Go Down

Topic: Leds & Buttons (Read 26 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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy