week5
Analog-to-Digital Conversion (ADC) Input
Jeff's in-class example with a potentiometer and a force sensor.
code 1
-----get ADC value code----------------- dim potVar as integer Sub main() do potVar = getADC(13) loop
|
dim potVar as integer Sub main() do if (potVar
>= 600) And (potVar < 900) then if (potVar
>= 900) then loop
|
Look at the deffrence between the photo cell range itself and the range when it is connected with a potentiometer.
Then I wanted to make several LEDs lit followed as the Potentiometer's value. Because the languages and syntaxes are different from Lingo, sometimes I get confused. The most tricky thing was the syntax which uses 'if-then' statement. So I just repeated 'if', 'then' and 'end if'. It doesn't look elegant now. So I felt have to study more about the language of Basic X. After writing the code, I learned about how to use 'if' and 'else if' statement. In Basic X, if-then statement composed like this. the difference between Lingo and BasicX is in else-if statement. Lingo uses 'else if'(there is a space beween 'else' and 'if' ) , but BasicX uses 'elseif' (there is no space).
|
code 3
dim
potVar as integer Sub main() do
if (potVar >= 150) And (potVar < 300) then '
to lit on LED 5,6
if (potVar >= 300) And (potVar < 450) then '
to lit on LED 5,6,7
if (potVar >= 450) And (potVar < 600) then
' to lit on LED 5,6,7,8
if (potVar >= 600) And (potVar < 750) then
' to lit on LED 5,6,7,8,9
if (potVar >= 750) And (potVar < 900) then '
to lit on LED 5,6,7,8,9,10
if (potVar >= 900) And (potVar < 1000) then ' to
lit on LED 5,6,7,8,9,10,11
if (potVar >= 1000) then ' to lit on LED 5,6,7,8,9,10,11,12 loop end sub |