I ran my program and it runs continously in a loop. It doesn't stop.
How can I stop the program manually if I want to edit the code or just want to pause/stop it then run it again later on? Apparently there's no stop/pause button in sight?
Thanks for your help. Sorry for the silly question! Basically, I do want to run my program continuously but if I want to do something else, so I want to stop the program without disconnecting the wire and run it again at a later time, how do I do that?
"How can I stop the program manually if I want to edit the code or just want to pause/stop it then run it again later on?"
Add a button to your arduino.
At the top of loop, read the button - if pressed and the program is not running, start the program.
If pressed and the program is running, stop the program.
button = 2;
running = 0;
void setup(){
pinMode (button, INPUT);
digitalWrite (button, HIGH); // ground the pin to make the button signal active
}
void loop(){
if ( (digitalRead(button) == 0) && (running == 1) ){ // program is running
running = 0; // so stop it
delay (100); // debounce swithch; crude
}
if ( (digitalRead(button) == 0) && (running == 0) )
{ // program is not running
running = 1; // so start it
delay (100); // debounce switch; crude
}
if ( running == 1)
{
motor.step(100, FORWARD, SINGLE);
}