hai,i just want to add a start button ,restart button,stop button,can anybody explain me ,how can i add these three buttons for my whole programming,thank you for your help
I don't know exactly what you want to do, so I'll make some assumptions.
Start Button:
Hold your loop function until the start button is pushed.
Restart Button:
Cut the program's flow and go at the start of the loop function.
Stop Button:
- Pause the program's flow until the start button is pushed (stopFun1).
- Go to the start of the program and wait for the start button (stopFun2).
If with any button you want to wipe any changes to your variables and start over just use the reset pin on the microcontroller.
int startFlag = 0; //a flag to mark the start of the program.
int startBtn = 0; //pin of start button.
void setup() {
pinMode(startBtn, INPUT_PULLUP);
attachInterrupt(0, restartFun, RISING); //Interrupt on pin 2 of Arduino Uno. It triggers from LOW to HIGH.
attachInterrupt(1, stopFun1, RISING); //Interrupt on pin 3 of Arduino Uno. It triggers from LOW to HIGH.
//attachInterrupt(1, stopFun2, RISING);
//rest of setup.
}
void loop() {
restartPoint:
while(digitalRead(startBtn) == HIGH && startFlag == 0);
startFlag = 1;
//rest of loop.
}
void restartFun() {
goto restartPoint;
}
void stopFun1() {
while(digitalRead(startBtn) == HIGH);
}
/*
void stopFun2() {
startFlag = 0;
goto restartPoint;
}
*/