I'm a newb when it comes to arduino.
Looking for someone to help me out.
I have a 12 position rotary switch that I want to send a SINGLE keypress without repeating when toggled between positions.
Position 1 on rotary switch =
Send keyboard button number 1 only once without repeat
Position 2 on rotary switch =
Send keyboard button number 2 only once without repeat
Back to position 1 on rotary switch =
Send keyboard button number 1 only once etc. etc.
Each pin on the rotary switch will connect to a different pin on the arduino
Basically, I need them to act like a momentary rotary dial.
Is this possible?
Does anyone have an example code that I can test?
I appreciate all advice and discussion and thanks in advance!
I would not run 12 lines to the MCU. I would have the MCU drive a 1:n decoder with all the outputs connected to the contacts 1-12, and the common return to an input pin. That would be 5 pins in total. Or a shift register, total 3 pins.
The older CB radios had digital encoders built in to the switch - just a 4 pole N position switch with each pole wired to yield one bit. For example
pole 1 - 0,1,0,1
pole 2 - 1,1, 0, 0
...
For clues about how to detect and process key events, see the digital example sketches that ship with the IDE.
When the switch is moved from position to position, the space between positions means there is NO connection. Your coding must allow for that. Similar to "debounce" on a push button switch.
Paul
In my experience that brand/type are "make before break" unless specified, so when you switch two adjacent poles will be connected as the switch is rotated from one position to the next.
I think I might connect 11x 1K resistors to the switch and use an analog input to detect the position. Effectively you are turning the switch into a pot, but one with only 12 positions. You might be able to solder the resistors directly to the back of the switch, with only 5V (3.3V?), GND and a wire to the analog pin going back to the Arduino.