Canada
Asked — Edited
Resolved Resolved by Rich!

Trying To Get A Pir Working

I feel like a blind man wandering around in the bush at night hoping to find my way home!

So here's where I'm at with this project, I've put some comments in so you can see what I'm trying to accomplish. Any and all help will be appreciated.



:loop
#timer to power down
$x = 0
RepeatUntil($x = 30)
$x++
Sleep(1000)

EndRepeatUntil
repeatUntil(1=2)

#what to do when timer gets to 30

set(D2,OFF)
#$x = GetDigital(D2)
ControlCommand("Script Manager", ScriptStart, "power down")#do this once

sleep(5000) 
WaitForChange(GetDigital(D2))
sleep(5000)

#do this when the PIR is triggered after "power down"

$motion=getDigital(D2)
IF($motion=1) #pin went high
ControlCommand("Script Manager", ScriptStart, "Power up")#do this once
endif

#do this if PIR is triggered anytime after it has powered up

$motion=getdigital(D2)
if($motion=1)
#stay powered up - need something here - what?
sleep(10000)
EndIf

# if Pir is not triggered in 30 sec start the timer again

If($x = 30)
GoTo(loop)
endif
EndRepeatUntil


Thanks

PS. I would pay money to go to a course somewhere to learn EZ-Robot scripting!


ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

#25  

@ Rich - I got it working! I put in an If and a ElseIf and it's working! Here's what I ended up with;


# Enter your low power mode commands here

sayezb("i am powering down")
:start

# Once in low power mode wait for a change on the PIR ADC port
#WaitForChange(GetADC(ADC7))
$PIR = GetADC(ADC7)
If($PIR > 180)
$motion = 1
#print($PIR)

# Power up robot
Sleep(2000)
ControlCommand("Script Manager", ScriptStart, "Power Up")

EndIf
sleep(3000)
If($motion = 1)
ControlCommand("Script Manager", ScriptStart, "Monitor")
elseif($motion = 0)
Goto(start)
Endif


# And end this script
HALT()

Thanks again for everyone's help. Standby though, I'm working on another script, so you know I'll be calling on the community for help.