That won’t work. You’ll have to program a timer in. The stamp cycles about once every 26 milliseconds.
Time var byte
Timeover var bit
If timeover = 1 then timeroff
Time = time + 1 + delta_t 'make sure to turn delta_t on,
’ otherwise this won’t work
relay1_fwd = 1
If time < 20 then dont_turn_off
relay1_fwd = 0
Timeover=1
dont_turn_off:
timeroff:
'PBasic takes inputs, and sends outputs accordingly once every
'cycle. That is why your code doesn’t work.
'I think the pause just pauses the cycle. I haven’t ever used it.
'Good luck on your programming! Feel free to ask other any other
'questions.
Jeff_Rice’s code should work for you. If you want some more info on why the original code wouldn’t work, read on. Otherwise, just ignore the rest of this.
Here goes:
None of the variable names actually mean anything. For example, you could rename relay1_fwd to relay7_rev and as long as you updated the aliases correctly, the Stamp wouldn’t know the difference.
Just setting a variable won’t change the motor itself. In fact, setting the variables are just a matter of convience and allow for more complex processing.
The motors are actually set by the values passed to the SEROUT command.
Since the original code never reaches a SEROUT between the relay1_fwd = 1 and the relay1_fwd = 0, the relay will never know the difference. Furthermore, if you don’t do a SEROUT at least once every 5 loops (that’s ~125ms), you’ll get a Basic Run Error. RoboEmu is a little more forgiving and will only complain after 1s which is probably why you didn’t get any actual errors.
I would also warn you to avoid doing anything that will tie up the robot in a loop – even one that includes a serout command. OR, let me say that all loops MUST include a test for autonomous mode bit. If you get in a pause or a loop and do not test for the end of autonomous mode, you will have a robot and a human, but no loving nurturing relationship…
Also something very important is having a SERIN command just before your autononomous code. This is very important because you need to get the mode every time it goes through the loop (you won’t get control from the robot if you don’t.)