STOP LIGHT USING 2 BUTTONS

Can you check my program i want to repeat the execution when i push the buttonA or the buttonB heres my code.

pls help me thank you.

FINAL_STOP_AND_GO_WITH_BUTTON.ino (3.37 KB)

So what happens when you run the code ?

    delay(15000);              // wait for a secon
    void lights1();

Why is there a function definition in the middle of the code ?

   delay(25000);              // wait for a second

It also helps to make code readable if comments match the code

Just because I can - and newbies might learn...

int buttonApin = 13;
int buttonBpin = 12;
int ledAPin = 2;
int ledBPin = 3;
int ledCPin = 4;

int ledDPin = 5;
int ledEPin = 6;
int ledFPin = 7;

void setup() {

 pinMode(buttonApin, INPUT_PULLUP);// define pin two as input for push button
 pinMode(buttonBpin, INPUT_PULLUP);// define pin two as input for push button

 pinMode(ledAPin, OUTPUT);// define pin two as input for push button
 pinMode(ledBPin, OUTPUT);// define pin two as input for push button
 pinMode(ledCPin,  OUTPUT);// define pin two as input for push button

 pinMode(ledDPin,  OUTPUT);// define pin two as input for push button
 pinMode(ledEPin,  OUTPUT);// define pin two as input for push button
 pinMode(ledFPin,  OUTPUT);// define pin two as input for push button
}

void loop() {
  lights1();
  lights2();
}

  void lights1() {
  if(digitalRead(buttonApin) == LOW){
  digitalWrite(ledAPin, LOW);   // set the LED on
  digitalWrite(ledBPin, HIGH);    // set the LED off
  digitalWrite(ledCPin, LOW);    // set the LED off
  digitalWrite(ledDPin, LOW);   // set the LED on
  digitalWrite(ledEPin, HIGH);    // set the LED off
  digitalWrite(ledFPin, LOW);    // set the LED off
  delay(5000);              // wait for a second


  digitalWrite(ledAPin, HIGH);   // set the LED on
  digitalWrite(ledBPin, LOW);    // set the LED off
  digitalWrite(ledCPin, LOW);    // set the LED off
 digitalWrite(ledDPin, LOW);   // set the LED on
  digitalWrite(ledEPin, LOW);    // set the LED off
  digitalWrite(ledFPin, HIGH);    // set the LED off
  delay(15000);              // wait for a second

    digitalWrite(ledBPin, HIGH);
    digitalWrite(ledEPin, HIGH);
    digitalWrite(ledCPin, LOW);
    delay(10000);


  digitalWrite(ledAPin, LOW);   // set the LED on
  digitalWrite(ledBPin, LOW);    // set the LED off
  digitalWrite(ledCPin, HIGH);    // set the LED off
  digitalWrite(ledDPin, HIGH);   // set the LED on
  digitalWrite(ledEPin, LOW);    // set the LED off
  digitalWrite(ledFPin, LOW);    // set the LED off
  delay(15000);              // wait for a secon


  void lights1();
}
  }

  void lights2() {
 if(digitalRead(buttonBpin) == LOW){
 digitalWrite(ledAPin, LOW);   // set the LED on
  digitalWrite(ledBPin, HIGH);    // set the LED off
  digitalWrite(ledCPin, LOW);    // set the LED off
  digitalWrite(ledDPin, LOW);   // set the LED on
  digitalWrite(ledEPin, HIGH);    // set the LED off
  digitalWrite(ledFPin, LOW);    // set the LED off
  delay(10000);              // wait for a second


  digitalWrite(ledAPin, HIGH);   // set the LED on
  digitalWrite(ledBPin, LOW);    // set the LED off
  digitalWrite(ledCPin, LOW);    // set the LED off
 digitalWrite(ledDPin, LOW);   // set the LED on
  digitalWrite(ledEPin, LOW);    // set the LED off
  digitalWrite(ledFPin, HIGH);    // set the LED off
  delay(25000);              // wait for a second

 digitalWrite(ledBPin, HIGH);
    digitalWrite(ledEPin, HIGH);
    digitalWrite(ledCPin, LOW);
    delay(10000);


  digitalWrite(ledAPin, LOW);   // set the LED on
  digitalWrite(ledBPin, LOW);    // set the LED off
  digitalWrite(ledCPin, HIGH);    // set the LED off
  digitalWrite(ledDPin, HIGH);   // set the LED on
  digitalWrite(ledEPin, LOW);    // set the LED off
  digitalWrite(ledFPin, LOW);    // set the LED off
  delay(25000);              // wait for a second


void lights2();
  }
}

.. and no, I'm not going to clean up the formatting.
You can do that with CTRL+T in the IDE

@lastchancename: There are multiple definitions of void lights1(); and void lights2(); in your code.
The second definition of each should be removed (sorry for my bad english :frowning: )

lastchancename:
Just because I can - and newbies might learn...

What is it that you can, and what is it that newbies might learn?

AWOL:
What is it that you can, and what is it that newbies might learn?

To post using code tags...
... and I didn't edit the code - simply put it in tags as an example.

Don't hold your breath :wink:

UKHeliBob:
So what happens when you run the code ?

    delay(15000);              // wait for a secon

void lights1();



Why is there a function definition in the middle of the code ?



delay(25000);              // wait for a second



It also helps to make code readable if comments match the code

if you press the button its stock to the last execution of the program. But i want to repeat the execution.

It's stuck because delay(25000) makes the Arduino wait for 25 seconds. It does literally nothing in this time. It can't read inputs, it can't change outputs, it just waits.

Read about how to make programs without using delay []here](Using millis() for timing. A beginners guide - Introductory Tutorials - Arduino Forum). The concepts introduced here should help you out with your problem if you understand and apply them correctly.

Metallor:
It's stuck because delay(25000) makes the Arduino wait for 25 seconds. It does literally nothing in this time. It can't read inputs, it can't change outputs, it just waits.

Read about how to make programs without using delay []here](Using millis() for timing. A beginners guide - Introductory Tutorials - Arduino Forum). The concepts introduced here should help you out with your problem if you understand and apply them correctly.

Thankyou