|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#23
|
||||
|
||||
|
Re: custom button panel
Quote:
Say you have a 6 position switch, you would wire it like: GND-> Position 0 - 2kOhm - Position 1 - 2kOhm - Position 3 - 2kOhm - Position 4 - 2kOhm - Position 5 <- +5V Then connect it to the joystick input. I guess it goes from -1 to 1, like shown below: Pos 0 -> ~-1 Pos 1 -> ~-0.6 Pos 2 -> ~-0.2 Pos 3 -> ~0.2 Pos 4 -> ~0.6 Pos 5 -> ~1 You'll want to factor in some tolerance. It won't be exactly -1, -0.6, etc. In this case, you have 0.4 units between each measurement. You can test between the cases. if ana < -0.8 pos = 0; else if ana >= -0.8 and ana < -0.4 pos = 1; else ifana >= -0.4 and ana < 0 pos = 2; else ifana >= 0 and ana < 0.4 pos = 3; else if ana >= 0.4 and ana < 0.8 pos = 4; else // in this case, this has to be true: ana >= 0.8 pos = 5; |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|