Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
FUNCTION Get_ADC_Sample() AS WORD // Function to grab the ADC sample for player position
result = (ADC.Read(0)+1)*500/1024 // Grab an ADC sample from channel 0
END FUNCTION
I think most of the examples everyone is showing are using all 1K resistors, so get rid of the "2K" resistor and just use a single 1K in its place.I have 12 resistors in series (2-1K to equal the 2K resistor)
Select ADC.Read(0)
Case <25
'no button pressed
Case <100 ' ideal=92
'button 1 pressed
Case <200 ' ideal=185
'button 2 pressed
Case <300 'ideal=278
'button 3 pressed
Case <400 'ideal=371
'button 4 pressed
Case <500 'ideal=464
'button 5 pressed
Case <600 'ideal=557
'button 6 pressed
Case <700 'ideal=650
'button 7 pressed
Case <800 'ideal=743
'button 8 pressed
Case <900 'ideal=836
'button 9 pressed
Case <1000 'ideal=929
'button 10 pressed
else
'something is wrong
End Select
Just to add a little 'story' to this method of using switched resistors and an A2D for reading multiple switches.
This technique was used a LONG, LONG time ago on early JVC VCR's - back before IR remote controls they used to use a corded remote, which used a 3.5mm jack plug, and a number of switched resistors inside the remote.
Nice idea, but poorly implemented - for two reasons:
1) One of the buttons switched directly across the cable, giving 'zero' ohms (I think it was the Play button - in any case, it was one commonly used).
2) The next button up from that (the next lowest resistor value) was the record button.
So this gave an unfortunate result, the cable for the remote tended to get bent and twisted, and started to give significant resistance in the cable. So when you pressed 'Play' it could inadvertently go to Record instead, erasing what you were trying to watch - which could be quite disastrous. I repaired countless remotes for this fault, replacing the existing wire with thin microphone cable, and a new 3.5mm jack plug.
I see that you aren't using 'zero ohms', but it still might be a good idea to consider which button you use for each option, just in case something strange happens (like a poor contact in a switch, giving a higher resistance reading).