Question
Asked October 24 2014

Community Question

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.

Code:



: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!

October 28 2014
Thanks Rich,
I applied your new script and it senses the change as does the "Monitoring script" but nothing happens. I must have something out of place in the "monitoring script" below;

Code:


# Monitor for movement for 30 seconds

# Set a lable for the start
:start

# Reset the counter
$Monitor_Counter = 0

# Repeat
RepeatUntil($Monitor_Counter = 30)

# Increase the counter by 1
$Monitor_Counter++

# Check for detection on PIR - since we need to check 5 times per second use repeat

# checking counter needed
$Monitor_Check_Counter = 0

RepeatUntil($Monitor_Check_Counter = 5)
# Add 1 to the check counter
$Monitor_Check_Counter++

# Check the status of the digital port
# Check the status of the ADC port
#$PIR = GetDigital(D2)
$PIR = GetADC(ADC7)

# Check if it is high or low and take action
IF($PIR > 195)

$motion = 1
Else
$motion = 0
#EndIF
# Motion detected, return to start
Goto(start)
Endif
# Note - no else or elseif required since nothing happens if motion isnt detected
print($PIR)
# Wait a while to save system resources
Sleep(200)
EndRepeatUntil

# 1 second has passed by this point
# repeat 30 times
EndRepeatUntil



# 30 seconds passed - Enter low power plus monitoring mode
ControlCommand("Script Manager", ScriptStart, "LowPowerMonitoring")

# End the script
HALT()

October 28 2014
Hi Rich, when you get a chance, could you have a look at this for me.
Thanks
October 29 2014
Yeah, sorry run out of time yesterday.

Code:


# Monitor for movement for 30 seconds

# Set a lable for the start
:start

# Reset the counter
$Monitor_Counter = 0

# Repeat
RepeatUntil($Monitor_Counter = 30)

# Increase the counter by 1
$Monitor_Counter++

# Check for detection on PIR - since we need to check 5 times per second use repeat

# checking counter needed
$Monitor_Check_Counter = 0

RepeatUntil($Monitor_Check_Counter = 5)
# Add 1 to the check counter
$Monitor_Check_Counter++

# Check the status of the ADC port
$PIR = GetADC(ADC7)

# Check if it is high or low and take action
# Convert ADC to simple high/low
IF($PIR > 195)
$motion = 1
Else
$motion = 0
EndIF

IF($motion = 1)
# Motion detected, return to start
Goto(start)
Endif
# Note - no else or elseif required since nothing happens if motion isnt detected
print($PIR)
# Wait a while to save system resources
Sleep(200)
EndRepeatUntil

# 1 second has passed by this point
# repeat 30 times
EndRepeatUntil



# 30 seconds passed - Enter low power plus monitoring mode
ControlCommand("Script Manager", ScriptStart, "LowPowerMonitoring")

# End the script
HALT()



This is all from memory and without EZ-Builder. It looked like you had it detecting motion when there was none and vice versa. This was causing it to reset the timer and start again.

You could remove the whole converting it to 0 or 1 though, it's pretty redundant.

Code:

# Monitor for movement for 30 seconds

# Set a lable for the start
:start

# Reset the counter
$Monitor_Counter = 0

# Repeat
RepeatUntil($Monitor_Counter = 30)

# Increase the counter by 1
$Monitor_Counter++

# Check for detection on PIR - since we need to check 5 times per second use repeat

# checking counter needed
$Monitor_Check_Counter = 0

RepeatUntil($Monitor_Check_Counter = 5)
# Add 1 to the check counter
$Monitor_Check_Counter++

# Check the status of the ADC port
$PIR = GetADC(ADC7)


IF($PIR > 195)
# Motion detected, return to start
Goto(start)
Endif
# Note - no else or elseif required since nothing happens if motion isnt detected
print($PIR)
# Wait a while to save system resources
Sleep(200)
EndRepeatUntil

# 1 second has passed by this point
# repeat 30 times
EndRepeatUntil



# 30 seconds passed - Enter low power plus monitoring mode
ControlCommand("Script Manager", ScriptStart, "LowPowerMonitoring")

# End the script
HALT()

October 29 2014
Thanks Rich, I made those changes, however, it did not work as expected. I noticed that the "LowPowerMonitor" script ran thru to the end and stopped, so I added in a "GoTo" command and I worked, BUT now everytime the PIR is triggered it runs thru the "PowerUp" command. After Power Up it returns to the "monitor" script though.

Code:


# 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
Goto(start)
# And end this script
#HALT()


Thanks, we are getting closer. Thanks for the nice comments you said about my project.

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

Code:


# 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.