"stop" or "reset" button

Hello, I was wondering if anyone can help me with a simple matter. I have just bought a arduino duemilanoe atmega 328 board. I have loaded it with the simple "servo swep" from "exmples". How do I make it stop? I have pushed the stop button in the software and the reset button on the hardware it self. But it just continues running. Im sure I missed something in the "how to" section and at this moment I am not finding it.

Best

Ingi

Pressing reset button only stops the execution of the program for a couple of seconds. and stop button doesn't stop the execution of the program written in your Arduino board. Whatever you have written inside the loop continues its execution till u switch off the power to the Arduino board. :)

and Welcome to the world of Arduino.

1 Like

two main parts of any sketch are

void setup()
{

instruction inside this proceadure are executed only once

}

void loop()
{
instructions inside the loop() procedure will be executed for ever
or until you specify a while() condition
}

When I want a sketch to stop running, I will usually re-load the "Blink" example.

1 Like

reload blink? really... that is not your best solution.... I hope.

To create the effect of a HALT button, you can easily create a conditional loop in your code that will do NOTHING (as fast as possible) until you break out of that condition and return to the normal processing loop. You can control this behavior by using the "state machine" approach. Create MODES, like RUN = 1 STOP = 2.

So. You initially set your MODE to RUN... then, if you have the code sense that you pressed a button... you can SET the MODE to STOP and engage your "do-nothing" loop (well, except for checking to see if you pressed a button maybe so you don't have tp press RESET).

reload blink? really... that is not your best solution.... I hope.

My understanding of the original question was "how do I make a sketch stop running?"

It is possible he meant "how do I make a motor stop" which is what you were describing. That's not what I read.

Ah, It's one of those trick questions, theres an Englishman, Irishman & Scottsman joke here somewhere

Here my proposal:

Finally a use for the neglected EEPROM. Use any adress >3 to store a reset counter. The first instruction is to increment that counter. Then you check whether it's even or odd. If it is even (if you prefer: odd), then stay in an endless wait. Otherwise perform your program.

So: first reset stops the program, second reset lets it run, e.t.c.

Does anyone want to have the code??

Edit:

:'( But I post it even so..

byte byte4ofEEPROM =EEPROM.read(4);
EEPROM.write(4, byte4ofEEPROM+1);
while(byte4ofEEPROM&1);

Or, just disconnect the power to arduino to stop the program running

Finally a use for the neglected EEPROM.

Don't forget that the EEPROM has a limited number of writes in it's life cycle. For the 328p it's 100,000.

When you are really busy you will press the RESET button 10 times a minute for at moset 2 hours a day = 1200 uses, may be you work 200 days in a year on your Arduino, this indeed will come close to the defensive number in the datasheet.

If you then encounter problems you have to change to cell number 5 :-)

Note: I am fully aware that the simple code above will also be triggered after the code is flashed, and whenever you open or close the serial monitor. This is not easily distinguishable from the use of the buttom. This is truly awkward...

Sorry. I where undere the impression that the limit on write cycluses was on the whole EEPROM. Now that I've read some Wikipedia articles I see that it is limited to cells. Which is good news :)

deSilva, I like your solution, but why not just store it in a traditional variable in RAM? I don't see the advantage of putting it in EEPROM.

(1) It will not work reliably, as RESET dows influence the RAM. Is would be unavaoidable for DRAM, howeverthere is a chace for SRAM to survive. I have not tested... (2) The C-Compiler will generate initialization code; it is difficult to say which cells migth stay untouched... I have not tested.

Maybe a combination of RAM and EPROM will work...

But the main issue is, that starting and stopping the Serial Monitor will reset, and you will become quite confused about thw state your program is in....