Hi guys,
This is my first time working with Aurduinos. I have an Arduino Uno and I have 10 led's turning on and off in a sequence from 1-10 and then repeat. I would like for the loop to stop when a push button is pressed and then continue when the push button is pressed again. i tried a few things I saw online but did not manage to make it stop. Any kind of help will be great full.
/*
Blinking LEDs - test program to run 3 LEDs in a pattern of blinks
*/
int buttonPin = 2;
int led1 = 3;
int led2 = 4;
int led3 = 5;
int led4 = 6;
int led5 = 7; // the number of the LED pin
int led6 = 8; // the number of the LED pin
int led7 = 9; // the number of the LED pin
int led8 = 10; // the number of the LED pin
int led9 = 11; // the number of the LED pin
int led10 = 12; // the number of the LED pin
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(buttonPin, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
//check button pressed, if so enter program condition (inside if statement)
if(digitalRead(buttonPin) == LOW) //functions based off of button pulling input pin LOW
{
digitalWrite(led1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(800); // wait for 1/2 a second
digitalWrite(led1, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(800); // wait for 1/2 a second
digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(800); // wait for 1/2 a second
digitalWrite(led3, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(800); // wait for 1/2 a second
digitalWrite(led4, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led5, HIGH); // turn the LED on (HIGH is the voltage level)
delay(800);
digitalWrite(led5, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led6, HIGH); // turn the LED on (HIGH is the voltage level)
delay(800); // wait for 1/2 a second
digitalWrite(led6, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led7, HIGH); // turn the LED on (HIGH is the voltage level)
delay(800); // wait for 1/2 a second
digitalWrite(led7, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(800); // wait for 1/2 a second
digitalWrite(led8, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led9, HIGH); // turn the LED on (HIGH is the voltage level)
delay(800);
digitalWrite(led9, LOW);
digitalWrite(led10, HIGH);
delay(800);
digitalWrite(led10, LOW);
delay(500); // wait for a second
}
}
sketch_jan14d.ino (3.06 KB)