Wait for button pressed before program runs?

 

 

I have just received my new Uno, and was wondering if there is a way to get the code that has been uploaded to it, to wait until the button is pressed before proceeding?

There is an option you could

There is an option you could try, but it involves a bit of advanced programming. There is documentation here:

http://www.nongnu.org/avr-libc/user-manual/group__avr__boot.html

on writing to Flash memory, where your program lives. On reboot, you could compare one static variable to another. If they don’t match (for various reasons, it makes sense to use non matching values first; you may also have to jump through some hoops of calling functions or whatever to keep it from optimizing your test of static data into an unconditional flow), then it means you just had new code uploaded. So you use the Flash memory function to change one to match the other. Then just set some major state variable so that you return immediately in loop(). 

When it is rebooted again, the test of the two “static” variables will find a match and you will know you have been rebooted a second time since the program was uploaded.

Thank you for taking the

Thank you for taking the time to advise me, arbanhart, I will check out your link.

I have managed to get over the problem by using a switch between the battery and the board, and a 5 second delay at the beginning of the program. This allows me to switch on and gives me time to grab the camcorder in good time :wink:

If that is the sort of delay

If that is the sort of delay you want, why not just read from Serial? Upload your program, then run the Serial Monitor, type in a character and don’t click Send until you are ready. In your setup function, do Serial.begin(9600) and then loop until there is a character available.