'In class example: uses the BX24 and a sharp proximity sensor on pin 13.
(Click here for sharp proximity sensor schematic).
If the proximity is less then 300 then the servo slowly rotates to open,
'if the prox is less then 300, the servo quickly closes.
dim minPulse as single ' the minimum pulseWidth
dim maxPulse as single ' the maximum pulseWidth
dim pulseWidth as single ' the servo's pulsewidth
dim refreshPeriod as single ' the time between pulses
dim prox as integer
Sub Main()
''''''SET MY VARIABLES
minPulse = 0.0008
maxPulse = 0.0025
refreshPeriod = 0.02
pulsewidth = minpulse
'''''MAIN DO LOOP
Do
prox = getADC(13)
debug.print; cstr(prox)
call pulseOut(12, pulsewidth, 1)
call sleep(refreshPeriod)
if prox < 300 then
pulsewidth = minpulse
end if
if prox > 300 then
if pulsewidth < maxpulse then
pulsewidth = pulsewidth + 0.00001
pulsewidth = maxpulse
end if
end if
loop
End Sub
|