Help with code for project
Wallydrag
Posts: 16
Okay, I think I'm getting close but I need some help with the code:
What I'm trying to make happen is that when the PIR senses a motion it will send a signal to Pin 0. That signal should trigger "Motor:" to run. I've also tried to make it so that once the stamp recognizes that first signal, it won't recognize any more for 60 seconds. I guess I should make it that once it gets the first signal it reverses to output for 60 seconds the back to input until it gets another signal again, but I'm not sure how to write that.
My real trouble is that when I check the syntax it highlights the "THEN" and says Error: Expected an operator. Thanks for the help.
' {$STAMP BS1}
' {$PBASIC 1.0}
SYMBOL PIR = PIN0
LET DIRS = %00001110
Main:
IF PIR THEN Motor
PAUSE 60000
GOTO Main
Motor:
HIGH PIN1
LOW PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
PAUSE 5000
LOW PIN1
HIGH PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
NAP 30000
GOTO Main
What I'm trying to make happen is that when the PIR senses a motion it will send a signal to Pin 0. That signal should trigger "Motor:" to run. I've also tried to make it so that once the stamp recognizes that first signal, it won't recognize any more for 60 seconds. I guess I should make it that once it gets the first signal it reverses to output for 60 seconds the back to input until it gets another signal again, but I'm not sure how to write that.
My real trouble is that when I check the syntax it highlights the "THEN" and says Error: Expected an operator. Thanks for the help.
' {$STAMP BS1}
' {$PBASIC 1.0}
SYMBOL PIR = PIN0
LET DIRS = %00001110
Main:
IF PIR THEN Motor
PAUSE 60000
GOTO Main
Motor:
HIGH PIN1
LOW PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
PAUSE 5000
LOW PIN1
HIGH PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
NAP 30000
GOTO Main
Comments
Also, as a general development rule of thumb you should add one piece of functionality at a time, test it, and make sure that it works correctly before going on.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Powered by enthusiasm
Main:
IF PIR THEN Motor
PAUSE 60000
GOTO Main
It looks like it's going to check PIR input, if it's on go to motor, If PIR is not on, isn't it going to PAUSE 60000, ignoring the sensor? Maybe you want the PAUSE 60000 at the end of the Motor code, so it will monitor PIR at full speed and only ignore it for 60 seconds after the motor routine has ran. And as SRLM said, change THEN Motor to THEN GOTO Motor.