Hi,
base on the example file of pushbotton and led
I need help on adding different led sequence base on push of botton
example 1 push 3 led blink
second push leds go off
third push second animation goes gon
4th push second animation off
5th push 3th animation on
6th push 3th animation off
any sugestion is very welcome
/// code here////
// this constant won't change:
const int buttonPin = 1; // the pin that the pushbutton is attached to
const int ledPin4 = 4;
const int ledPin5 = 5;
const int ledPin6 = 6;
const int ledPin7 = 7;
const int ledPin8 = 8; // the pin that the LED is attached to
const int ledPin9 = 9;
const int ledPin10 = 10;
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6 , OUTPUT);
pinMode(ledPin7 , OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10 , OUTPUT);
// initialize serial communication:
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
}
else {
// if the current state is LOW then the button
// wend from on to off:
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter == 1) {
digitalWrite(ledPin8, HIGH);
} else {
digitalWrite(ledPin8, LOW);
}
if (buttonPushCounter == 2) {
digitalWrite(ledPin8, HIGH);
delay(100);
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, HIGH);
delay(100);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, HIGH);
delay(100);
digitalWrite(ledPin10, LOW);
} else {
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, LOW);
}
if (buttonPushCounter == 3) {
digitalWrite(ledPin8, HIGH);
delay(100);
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, HIGH);
delay(100);
digitalWrite(ledPin9, LOW);
} else {
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, LOW);
}
/////END OF CODE/////
}