Go Down

Topic: Terminating other functions to start another function (Read 675 times) previous topic - next topic


When I press a button I want the other functions that are happening to stop. How do you do so.
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int buttonPin4 = 5;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

void setup() {
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);

void loop() {
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);

  //4 functions
  if (buttonState1 == HIGH) {
    //function here
    if (buttonState2 == HIGH) {
    //function here
    if (buttonState3 == HIGH) {
    //function here
  if (buttonState4 == HIGH) {
    //function here


Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!


You write the missing functions so that they do not block. That is no delay() calls, no for loops, no while loops, etc.
The art of getting good answers lies in asking good questions.

Go Up