Page 146 - Robots Androids and Animatrons : 12 Incredible Projects You Can Build
P. 146
‘ Set Up
start:
‘Read sensor on RB2
pot 2,255, b0
if b0 > 125 then l1 ‘If more than 100, light LED 1
if b0 <= 125 then l2 ‘If less than 100, light LED 2
l1: ‘Light LED 1 routine
high 0 ‘Light LED 1
low 1 ‘Turn off LED 2
goto start ‘Repeat
l2: ‘Light LED 2 routine
high 1 ‘Light LED 2
low 0 ‘Turn off LED 1
goto start ‘Repeat
The program for the PICBASIC Pro compiler is as follows:
‘ PICBASIC Pro Compiler ** reading resistance type sensors **
‘Photoresistor test program
‘ Set Up
output portb.0 ‘Set RB0 as output
output portb.1 ‘Set RB1 as output
b0 var byte
125
start:
pot portb.2,255, b0 ‘Read sensor on RB2
if b0 > 125 then l1 ‘If more than 100, light LED 1
if b0 <= 125 then l2 ‘If less than 100, light LED 2
l1: ‘Light LED 1 routine
high portb.0 ‘Light LED 1
low portb.1 ‘Turn off LED 2
goto start ‘Repeat
l2: ‘Light LED 2 Routine
high portb.1 ‘Light LED 2
low portb.0 ‘Turn off LED 1
goto start ‘Repeat
One can make the demonstration a little more interesting by sub-
stituting a CdS photoresistive cell in place of the potentiometer in
the circuit. If the proper CdS cell is chosen, for instance, one with
a dark resistance around 50K to 100K ohms and with a light satu-
ration resistance of 10K ohms or less, LED 1 will be lit when the
photoresistor is covered or in darkness. In bright light, LED 2 will
be lit.
It’s possible to read the numerical value of the pot variable by seri-
ally sending the variable to a serially interfaced LCD display or
Team LRN Intelligence