Go Down

Topic: Blink led with a button (Read 369 times) previous topic - next topic


I want to put the led on when the button is pushed...But I have some problem with the language on the software...

If I write in void loop

val= digitalread (inpin); // read input value
if (val== HIGH) // check if the input is HIGH (Button released)
digitalwrite (ledpin, LOW); // Turn LED off
digitalwrite (ledpin, HIGH); // turn LED on

I have the opposite that I want... The led Turns on always and it turns off when I push the button...
Where do I change the value HIGH and LOW??
Please somebody answer me........ :P


It depends on what your circuit looks like, but usually pushbuttons are inverted logic, because they are pulled up to VCC using a resistor and shorted temporarily to ground when the button is pressed.  In such a configuration, the switch is "active low", e.g. it's 0V when pressed and 5V otherwise.


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!

via Egeo 16
Torino, 10131