12 inputs on a single ADC

Michael 2727

Senior Member
This is part of the code I used to make a
crude 08M Music keyboard.
<A href='http://porepunkahps.vic.edu.au/home/jef01/files/display/08M-Music-Organ.txt' Target=_Blank>External Web Link</a>

<code><pre><font size=2 face='Courier'>
Using these values you should be able to
make a 12 key Keyboard or 12 Switches/Buttons
on a single ADC input.
Code:
readadc 4,b0
pause 100                              ' Actual ADC measured @ 4.05 Volts.
if b0 &gt;= 0 and b0 &lt;=117then No Change     ' is 115 = 120k = Silence.
if b0 &gt;= 118 and b0 &lt;=123 then One     ' is 120 = 110k
if b0 &gt;= 124 and b0 &lt;=130 then Two     ' is 126 = 100k
if b0 &gt;= 131 and b0 &lt;=136 then Three   ' is 133 = 90k
if b0 &gt;= 137 and b0 &lt;=145 then Four    ' is 140 = 80k
if b0 &gt;= 146 and b0 &lt;=153 then Five    ' is 149 = 70k
if b0 &gt;= 154 and b0 &lt;=164 then Six     ' is 158 = 60k
if b0 &gt;= 165 and b0 &lt;=175 then Seven   ' is 169 = 50k
if b0 &gt;= 176 and b0 &lt;=189 then Eight   ' is 181 = 40k
if b0 &gt;= 190 and b0 &lt;=202 then Nine    ' is 195 = 30k
if b0 &gt;= 203 and b0 &lt;=220 then Ten     ' is 211 = 20k
if b0 &gt;= 221 and b0 &lt;=240 then Eleven  ' is 231 = 10k
if b0 &gt;= 241 and b0 &lt;=255 then Twelve  ' is 254 = shorted out Zero Ohms. 

' Using a 10K resistor to Neg and the above resistors to the ADC 
' input and Pos, the obtained ADC value was made the centre 
' value for each &quot;then&quot;. ADC value below 115 produces No Change.  </font></pre></code>  

May come in handy if you are short of input
pins one day,,~ ;o)

An open ended String of 12 equal 10K Ohm resistors were used.
The resistor junctions used to pick each value.

Edited by - Michael 2727 on 25/05/2006 08:29:26
 

womai

Senior Member
Your if-then code section can be made much shorter and faster - variables can't be negative anyway, and you already checked for all previous smaller cases:

if b0 &lt;=117then No Change ' is 115 = 120k = Silence.
if b0 &lt;=123 then One ' is 120 = 110k
if b0 &lt;=130 then Two ' is 126 = 100k
if b0 &lt;=136 then Three ' is 133 = 90k
if b0 &gt;= 137 and b0 &lt;=145 then Four ' is 140 = 80k
if b0 &lt;=153 then Five ' is 149 = 70k
if b0 &lt;=164 then Six ' is 158 = 60k
if b0 &lt;=175 then Seven ' is 169 = 50k
if b0 &lt;=189 then Eight ' is 181 = 40k
if b0 &lt;=202 then Nine ' is 195 = 30k
if b0 &lt;=220 then Ten ' is 211 = 20k
if b0 &lt;=240 then Eleven ' is 231 = 10k
goto Twelve ' is 254 = shorted out Zero Ohms.
 

Michael 2727

Senior Member
Yes Womai, you will save 40 bytes.
And the No change needs an Underscore
e.g. No_Change, or you will get an error.
The pitfalls of being lazy and Copy/Paste,,~ ;o)
 
Top