Go Down

Topic: Leds & Buttons (Read 62 times) previous topic - next topic

Llatzer

Hi! I show you part of a little project I'm doing, in which when you press a button, a Led lights up:

int Led = 1;
int But = 10;
int val = 0;

void setup() {
pinMode(But, INPUT);
pinMode(Led, OUTPUT);
}

void loop(){
 val = digitalRead(But);
  if (val == HIGH) {         
    digitalWrite(Led, HIGH);
  } else {
    digitalWrite(Led, LOW);
  }


I want to make when you push the button once, the led remain shining for a while, and I tried:


val = digitalRead(But);
  if (val == HIGH) {         
    digitalWrite(Led, HIGH);
    delay(500);
  } else {
    digitalWrite(Led, LOW);
  }


but it doesn't rules.... any suggestion?

Thanks!


terryking228

That delay is 1/2 second. Try delay(5000); 
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

Go Up