johnWasser is right, an endless loop will "stop" it. [Stopping means preventing executing other code here] You could put of course that into a function.
void stop()
{
while(1);
}
And an some advanced version could make the stop conditional ..
volatile int stopFlag;
void stop()
{
stopFlag = 1;
while(stopFlag);
}
// and have some Hardware IRQ (attachInterrupt or timerinterrupts etc) to reset the stopFlag
void IRQ()
{
stopFlag = 0;
}
Another way to stop a sketch is to have a relay between your power supply and the Arduino. Then a digitalWrite(RELAYPIN, LOW) could shut of the system ...
Disclaimer: never tried
Hehe, you could setup a fancy little circuit so when you are done running your sketch, a transistor switch can put some dangerously high voltage into the arduino
It's worth noting, as mentioned by a few above, what does "stop" mean?
Does it mean - stop taking some prescribed action and wait until some signal occurs to resume activity, or does it mean that the sketch should perform a single activity, and then do nothing else until it has been power-cycled or reset, or, even more - does it mean the device should stop running entirely after performing some action?
For 3rd, you will need to control the state of the chip's sleep mode, as people have mentioned.
For the 2nd, as noted - simply put all of the logic in setup() and have a blank loop.
For the 1st, consider using a simple state machine:
Of course, your state machine will be arbitrarily complex based on your actual needs - but it is important to differentiate between the three possible outcomes as the solution to each is different.
on an esp8266 with Arduino IDE , and it did a
WDT reset dump the stack to the serial monitor
and hung .....
Go figure.
Yes the loop function needs to exit to kick the dog. You don't have to do this on real Arduinos.
Notice that winkie smiley in your code? Did you put it in there?
This is the forum mangling code and mistaking it for format information. This is why we are so hot on posting you code correctly.