Pages: [1]   Go Down
Author Topic: Running more than one event listeners  (Read 496 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been snoozing the past year when I should have been learning more, thus newbie program. I've seen it before but can't remember a single thing about how to accomplish it. Here I have a LED blink on else if no button is pressed. I'm puzzled on how to make it do this without the delay to read the instruction to write to LED when the push button I have is triggered.

If I failed to explain, I wish to have the LED blink but respond to the push button listener that tells the program to turn the LED on. My program however, will only listen at one moment in the instructions as it runs the loop. How can I solve this?


Code:
const int ledPin = 13;
const int buttonPin = 53;
int buttonState = 0;

void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop(){  //
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)  {
  digitalWrite(ledPin, HIGH);
  }
 else  {
   digitalWrite(ledPin, HIGH);
   delay(500);
   digitalWrite(ledPin, LOW);
   delay(500);
  }
    Serial.println(buttonState);
}
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Open the Arduino IDE, go to File => Examples => Digital => Blink without delay.
Logged

Pages: [1]   Go Up
Jump to: