From a hardware perspective, we need to take into account one more thing — the push-wheel switch behaves electrically like four normally-open push buttons. This means we need to use pull-down resistors in order to have a clear difference between high and low states.
So the schematic for one switch is as shown above. Now it is a simple matter to connect the outputs labelled 1, 2, 4, and 8 to for example digital pins 8, 9, 10 and Next, we need to have a sketch that can read the inputs and convert the BCD output to decimal. Consider the following sketch:. The function readSwitch is the key. It calculates the value of the switch by adding the numerical representation of each switch output and returns the total as its result. So there you have it.
Would you actually use these in a project? For one digit — yes. For four? Probably not — perhaps it would be easier to use a digit keypad. Now we will examine how to read four digits — and not waste all those digital pins in the process. Before moving forward, please note that some assumed knowledge is required for this article — the I2C bus parts one and two and the MCP We first will describe the hardware connections, and then the Arduino sketch.
Assuming I'll be using the internal pull-up resistors, does the common go to ground? Is there a better way to wire it? My working assumption is that the pusher will be powered down when switching pedals, and that selecting the "profile" will be done as part of the hardware setup, and will not change while the pusher is in use How do I read the switch and get it into a single decimal value I think it will be an "int" as the range will only be A simple and cheapest method to read a rotary BCD switch is to wire the common to ground and wire the 4 switch bits to 4 arduino input pins and then enable the optional internal pull-up resistors for those pins.
If speed is ever an issue you could utilize arduino pins belonging to the same port and then use direct port access to read all the bits in one read operation Vs using arduino digitalRead commands on each individual switch contact value. The main disadvantage of this technique is that the resulting code will not be portable between different chip types, like the Uno Vs Mega boards.
I now have the switch wired, and basic code written to read the switch state one time during the initialization stage of the program.
I also had it working with minor changes as a loop to read the value of the switch on each pass I used a 10 position three disk switch. It works the same way, if you use an 8 position switch. You can find this type of switch at many surplus electronics parts stores and on line at eBay, Jameco and other suppliers. Check with other club members or post your need on the OMARC website to let folks know you are looking for this type of switch.
Figure 2 - Poormans BCD. Figure 4 - Poormans BCD. The diagram below shows the wiring diagram for the switch. Cause that is the type of switch I ordered on ebay. Add a fourth deck and you can light up and LED per channel! You could use the fourth deck to activate a logic controlled 7 segment display per Chester I see you have negative and positive wires comming out from the switch black and red do the red wire get connected to the positive supplying 8 to 15 vdc and negative to ground?
Thanks chuck. After reviewing the Ritron schematic diagram
0コメント