I have been using https://wokwi.com/ to learn Arduino and I am having a problem that seems to be happening no matter what I do. I am trying to set up a push button and an LED. The end goal here is to set it up so that when I tap the push button down and release it that the LED blinks like a turn signal in a car. When I push it down and release it again, the LED should stop blinking. I have tried tons of different code, even using code copied and pasted directly from Arduino's website. What ends up happening is that the button is unreliable. Sometimes the button will click, other times it won't register. It is very bizarre behavior. I read about the bouncing effect but any code I put in to ignore bouncing doesn't seem to have any effect on the system. Why are push buttons so unreliable? I know in real life they aren't because I am able to type this using presumably push buttons on my keyboard. What am I doing wrong??
Here is an example. The push button is totally unpredictable. Why is it behaving like this?
int state = 0;
void setup()
{
pinMode(9, OUTPUT);
pinMode(6, INPUT);
}
void loop()
{
if (digitalRead(6)) {
state = !state;
}
digitalWrite(9, state);
}
if it's dark outside, then flip the light switch
... you'd be turning the lights on and off all night long, and the light stands a chance to be left on all dayif (!digitalRead(6)) { state = !state; }
Is that correct?