Hi
I've used the example and am trying to get 1 button to control 2 leds.
What i want to happen is to have ledPin turn on and off instantly as the button is pressed. HOWEVER i want a_ledpin to light up 2 seconds later, and turn off 2 seconds later (after the button is pressed).
forgive my extreme nubeness
What i'd really like is to know how to make the delay function work ONLY for the next part and not to affect the entire loop , its hard for me to explain right now
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int a_ledpin = 12;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(a_ledpin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
delay(2000);
digitalWrite(a_ledpin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
delay(2000);
digitalWrite(a_ledpin, LOW);
}
}