Using th Button command
NWCCTV
Posts: 3,629
Questin, Would a Button command be the appropriate approach to the following code to invoke a "reset" after each of the Servo commands? If so, how would I code it and if not, what should I use.
IF x = 1 THEN pulseleft = 850: pulseright = 650: pulsecount = 24: DO UNTIL (counter = pulsecount) PULSOUT 13, pulseleft PULSOUT 12, pulseright counter = counter+1000 LOOP ELSEIF x = 2 THEN pulseleft = 650: pulseright = 850: pulsecount = 24: DO UNTIL (counter = pulsecount) PULSOUT 13, pulseleft PULSOUT 12, pulseright counter=counter+1000 LOOP ELSEIF x = 3 THEN pulseleft = 850: pulseright = 750: pulsecount = 24: DO UNTIL (counter = pulsecount) PULSOUT 13, pulseleft PULSOUT 12, pulseright counter=counter+1000 PAUSE 20 LOOP ELSEIF x = 4 THEN pulseleft = 750: pulseright = 650: pulsecount = 24: DO UNTIL x = 6 PULSOUT 13, pulseleft PULSOUT 12, pulseright counter=counter+1000 PAUSE 20 LOOP ENDIF counter = 0 LOOP
Comments
This will loop forever as counter will never equal pulsecount.
Maybe this is what you are trying to do?
*** NOT TESTED ***
The BUTTON command is usually overkill, unless you need the auto-repeat feature. It is easier to read the button-switch with a simple IN command. Are you using an original BS2?
Are you trying to detect a reset command on the serial line issued by software running on a PC? If so, you must poll the serial line within your looping construct in PBASIC. The Stamp does not have a serial port buffer and the Stamp can only do one thing at a time. So, the only time the Stamp can detect a reset command on the serial line is when the Stamp is looking for a command on the serial line. The PC software should resend the reset command until the Stamp acknowledges receiving the reset command. After the acknowledgment, the stamp will reset something...
Connect a resistor (10k) to the Stamp's reset line, and the other end of the resistor to +5V (make sure it's really 5V).
Dedicate a Stamp pin to use for the operation/purpose.
Connect the dedicated pin to the Stamp reset pin (maybe through a 220 resistor).
In the Stamp code, set the dedicated pin to output, default "high".
Then, when a Stamp reset is desired, programatically pull the dedicated pin low, which will in turn reset the Stamp.
Lemme know?
***edit post...guess I should have read RDL2004's post a bit more carefully!
I should also point out that just using a label with GOTO commands isn't going to clear anything already in memory (variables and such), so you would need to deal with that.