rotary switch wiring and code

With a rotary switch you will need to add series resistors to build a resistor ladder which adds/subtracts for each click. The Leo Bodnar £5 3 wire ones are a good base point if you don’t want to do this yourself (1k resistors linked between each pole is fine)

apply your 5v and ground lines and read the output voltage from the voltage divider you have just created.

write the step voltages down (they should be more or less the same but will differ within the resistor tolerance bands)

in your arduino sketch you can then either use a linear equation with nearest integer rounding, an array or a lookup table to output your switch position from the analogue voltage reading.

If you get stuck there is plenty of walk throughs on the likes of instrucables by searching “Arduino Rotary Switch”
 
Upvote 0
The best way is to use the stm32 card. You don't need a resistor and it accepts a great combination of buttons. Just look at the link below.

 
Upvote 0
With a rotary switch you will need to add series resistors to build a resistor ladder which adds/subtracts for each click. The Leo Bodnar £5 3 wire ones are a good base point if you don’t want to do this yourself (1k resistors linked between each pole is fine)

apply your 5v and ground lines and read the output voltage from the voltage divider you have just created.

write the step voltages down (they should be more or less the same but will differ within the resistor tolerance bands)

in your arduino sketch you can then either use a linear equation with nearest integer rounding, an array or a lookup table to output your switch position from the analogue voltage reading.

If you get stuck there is plenty of walk throughs on the likes of instrucables by searching “Arduino Rotary Switch”
i dont understand?
 
Upvote 0

Have a look at this, it gives you the basics of what you are trying to do.
 
Upvote 0
has anyone found a sketch yet? i understand what i need to do with wiring, and i understand the endgoal of the software. but i cant write the code.
i would liketo merge it with the buttonbox and rotary encoders like seen in this video.


I want to bind each position of the rotary switch to a black box menu in iracing

Thanks
 
Upvote 0
Be aware that there are different components, that can look very similar:

- Rotary encoders (incremental): those are used in the video you embedded. Their output is simply one/two/three clicks clockwise/counterclockwise. You can see towards the end of the video that when an encoder is turned clockwise each click is one button push in the controller properties, when it is turned counterclockwise, each click is a push of a different button. To read it with an Arduino you can use this library.

- Rotary encoders (absolute): these give you an exact information about the current position of the encoder. They come in different accuracy, 3 bits can give you a maximum of 2³ = 8 positions over a full turn, 4 bits can give you 2⁴ = 16 positions and so on. You can check this video for an example of an absolute rotary encoder with 128 positions.

- Rotary switches have a different working principle. They basically just connect a center terminal to one of their other terminals depending on the position. Check the post above yours for an example how to read it using only one analog pin.
 
Upvote 0

Latest News

Are you buying car setups?

  • Yes

  • No


Results are only viewable after voting.
Back
Top