I have a memory game project and for that I need to use buttons and leds. The thing I want is if the user pushes the first button, the first led starts to light. If the second button is pressed the second led should light. But maybe I missed somethink when learnt how the buttons should be programmed because when I check if the first button is pressed the first led is starts lighting, but when I press the second button the first led starts lighting again (the second led won't because I didn't write the code for that, but it shouldn't light the first led either). Its not finished I know. I didn't wrote the code for all the buttons and leds because I just tested. I don't ask you guys to solve the whole thing, just to help me why is this bug appears.
When I run the simulation you link, and hit the Pause button, the places where the switches are wired to all read "input floating".
This means the value returned by digitalRead() for the buttons will be HIGH or LOW, but not necessarily because you are, or are not, pressing the buttons.
The buttons connect the diagonally opposite corners.
In the wokwi, wire the switch between ground and the pin, and use INPUT_PULLUP mode. One side to ground, a diagonally opposite corner to the corresponding input pin.
Expect digitalRead() to return LOW when the button is being held down (pressed). I haven't looked at your code to even guess what does what yet.
I already did what you said. I did the wireing the same and I use INPUT_PULLUP as pinmode for those pins where I actually check if the button pressed or not
Now the main problem is solved, thanks a lot. But there is like a bug, cause sometimes I press any button its like it stuck and the led lights permanently. I mean hardly ever but sometimes they do. Is it only a bug or this is the "bouncing problem"?
The button places a value on the input pin, digitslRead() is for checking the value.
Read more code. Read more about coding. You never saw such a circuit for a button ever, anywhere.
Now you code has some problems, at the very least it does not appear the you ever change pastTime.
Even when you do, put your finger on the code and see what happens, I think you've not got the pattern correct if you are working with millis() to only do something if it is time.
And your else clause is always going to turn off alla LEDs soon enough you won't see the, I think.
Can't read it too well as I am in transit looking through the tiny window.
I wrote its not finished. I know about the "pastTime" I should update it at the end of the if statement and so on. I know there is a lot to do on this code but I tried to test if the main things works
@botond500 in the wokwi, you can actually get perfect buttons… it's a crutch and you will need to overcome it one day, but
click on a button, and you get a pop up where you can turn off simukated debouncing.
This is handy if you just want to see the effect of bouncing, or if you are using the simulator for another issue and just don't want to bother with doing the proper treatment necessary IRL.
Thank you guys! I know I have a lot to learn about arduino, electronics and coding as well. I try and now I understand more. Now its up to me so I will do the rest and learn learn learn....