Shop OBEX P1 Docs P2 Docs Learn Events
Help with code for project — Parallax Forums

Help with code for project

WallydragWallydrag Posts: 16
edited 2010-01-01 14:31 in Learn with BlocklyProp
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

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-12-09 22:10
    "Motor" is not a command. It is a label. You need something like "GOTO Motor" instead. Note that it if you do it that way then the code will never execute both motor and the 60000 pause.

    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
  • RogerNRogerN Posts: 19
    edited 2010-01-01 14:31
    From your code-

    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.
Sign In or Register to comment.