good morning,
I was just seeing if anyone could help with my code. The problem I am having is that once the water reaches a certain level < 30cm away from the sensor, I have a pump (B.2) which starts, the problem I am having is I don't know how to keep my ultrasonic range sensor calculating the distance whilst the pump is on.
Here is my code:
symbol SIG = C.2 ;Define pin for trigger and echo
symbol range = w1 ;16 bit word variable for range
main:
pulsout SIG,2 ;produce 20uS trigger pulse (must be minimum of 10uS)
pulsin SIG,1,range ;measure the range in 10uS steps
;now convert range to cm (devide by 5.8) or inches (devide by 14.8)
;as picaxe cannot use 5.8, multiply by 10 then devide by 58 instead
let range = range * 10 / 58 ;multiply by 10 then devide by 58
debug range ; display range via debug command
pause 50 ;short delay
if w1 > 30 then pump ;if the distance of the water is greater than 30 cm from the sensor then go to motor
goto main ;loop around forever
pump:
high B.2 ;Start B2
if w1 < 12 then main ;if the distance of the water is less than 12cm from the sensor then goto main
If anyone could help that would be great.
Thanks
I was just seeing if anyone could help with my code. The problem I am having is that once the water reaches a certain level < 30cm away from the sensor, I have a pump (B.2) which starts, the problem I am having is I don't know how to keep my ultrasonic range sensor calculating the distance whilst the pump is on.
Here is my code:
symbol SIG = C.2 ;Define pin for trigger and echo
symbol range = w1 ;16 bit word variable for range
main:
pulsout SIG,2 ;produce 20uS trigger pulse (must be minimum of 10uS)
pulsin SIG,1,range ;measure the range in 10uS steps
;now convert range to cm (devide by 5.8) or inches (devide by 14.8)
;as picaxe cannot use 5.8, multiply by 10 then devide by 58 instead
let range = range * 10 / 58 ;multiply by 10 then devide by 58
debug range ; display range via debug command
pause 50 ;short delay
if w1 > 30 then pump ;if the distance of the water is greater than 30 cm from the sensor then go to motor
goto main ;loop around forever
pump:
high B.2 ;Start B2
if w1 < 12 then main ;if the distance of the water is less than 12cm from the sensor then goto main
If anyone could help that would be great.
Thanks