by Diane Thomas

PicBasic Pro code for serial-read though-beam sensor.

'set photocell pin for input
'if photocell goes low, trigger the relays
' make test LED HIGH if resistance drops (trigger event -- make array calculations)

'This is the initial test code for the Though-beam sensor.
' 3 issues:
'1) photocell seems to acclimate to the intensity of the laser, electron activity falls off some.*see light history 'note above.  intitial evaluation of "700 in DEC" would have to be lowered.
'2) lasers bout in ChinaTown have a very short life span--10 minutes. (tried two types)
'3) evaluating laser consistency burns out eye balls.


define ADC_CLOCK 3
define ADC_BITS 10
Define ADC_SAMPLEUS 20
define osc 4

ADCvar var word
PCell var porta.0
TestBlink var portc.4
output testblink
ADCON1 = %10000010
TRISA = %11111111
Tx var portc.6


high testblink 'testblink 2 times --stop
pause 200
low testblink
pause 200
high testblink
pause 200
low testblink
pause 200

main:
pcell = adcvar
adcin 0, adcvar
serout2 tx, 16468,["adcvar = ", dec adcvar, 10,13]
pause 200
if adcvar > 700 then    'if photocell light is blocked and voltage drops-
high testblink                'test light goes HIGH if beam is broken
else 
low testblink
endif
goto main                     'keep reading Pcell pin