View Full Version : Delay or Stop program when uploaded to PBASIC

01-24-2010, 02:32 PM
Hello, I tend to make things complex and go into too much detail, so throw something at me if I do or you become lost or don't understand my jib-jib, but here's my problem.

Every time I turn the power on to my Boe-Bot my program I wrote starts to run, so is there a way to prevent this? Such as a way for the Boe-Bot to count the number of resets. One reset would return a 0 or a number of resets and I could use this number to determine if the Boe-Bot was just turned on or not. Also I don't know if this would work for when I am testing the Boe-Bot while its on and I am updating/uploading my new code as this would throw off the reset counter. Am I right?

So I guess what I'm asking is...is there a way to delay my code from running until I myself press the reset button on the Boe-Bot. There simply said.

Told you I'd make it complex/confusing http://forums.parallax.com/images/smilies/yeah.gif

Kevin Wood
01-24-2010, 03:33 PM
I don't think you can do this directly from the reset button, since it basically hard-cycles the power.

However, you could add another pushbutton switch to your Boe-Bot and monitor it for a button press. The button-handling subroutine could be written to start & stop your Boe-Bot. You would need to periodically check for a button press to keep it responsive.

Mike Green
01-24-2010, 10:45 PM
You can write your program to do this using an EEPROM location for a counter and the READ / WRITE statements to change it. Essentially, your program, when started, checks a location in EEPROM and increments it, waits for a period of time, then resets the location to zero. If the reset button is pressed again during that wait, the location will be greater than zero when it's checked.

flag DATA 0 ' initialize EEPROM location zero to zero
temp VAR byte ' temporary

read flag,temp ' read contents of EEPROM flag
temp = temp + 1
write flag,temp ' increment and write it back
if temp > 1 then goto continue ' if it was > 0
pause 500 ' time window for another reset
write flag,0 ' if not, re-initialize the counter

01-25-2010, 02:09 AM
If all you want is for the actions in the program to wait for you to start them you could put a loop in the first part of the program that waits for a button on a pin to be pressed (not the reset button) before continuing with the rest of the code.

- Stephen

01-25-2010, 11:59 AM
Mike, after reviewing my notes and freshening up on how to use the write/read data from EEPROM I analyzed your code and it works great. After the second reset it follows through and executes my code. However, there isn't a way to recognize that only the reset button has been pushed or not? If not this works great! Also I haven't seen the use/syntax of a colon ':' yet, but I'm only halfway done with the book. Where did you learn about that syntax and is there another book out there that can help you do more with the Boe-Bot?

And finally how do you know so much about the Boe-Bot and its programing language as I see your postings everywhere. Are you fluent with programming languages or is the Boe-Bot a hobby? I'm just curious.

Thanks again guys!!! http://forums.parallax.com/images/smilies/burger.gif

Mike Green
01-25-2010, 12:51 PM
There is no way to distinguish between pushing the reset button and turning the Stamp off and on again if that's what you're asking.

Normally you put one PBasic statement per line of a program. The colon (":") simply substitutes for the end of one line and the beginning of the next so you can put more than one statement on a line. That's all. The only exception that I recall is that a comment extends to the end of the line. Any colon found after a comment starts is treated as part of the comment.

I've been using Stamps (and Propellers) for a number of years. I've been programming for over 45 years.

Have a look at all the tutorials that Parallax has available. Good introductory tutorials include:

What's a Microcontroller?
Robotics with the BoeBot.
BASIC Stamp Syntax and Reference Manual

Look here: www.parallax.com/tabid/440/Default.aspx (http://www.parallax.com/tabid/440/Default.aspx)
and here: www.parallax.com/tabid/535/Default.aspx (http://www.parallax.com/tabid/535/Default.aspx)
There's also lots of good information here:
www.parallax.com/tabid/272/Default.aspx (http://www.parallax.com/tabid/272/Default.aspx)

Post Edited (Mike Green) : 1/25/2010 5:56:46 AM GMT

01-25-2010, 01:41 PM
Thank you very much again Mike. Very much appreciated.