Hello everyone. I'm super new at arduino and electronics. This is my first post, but I'm at my wits end and feel like a tool trying to get something so basic to work.
I have a very simple 3 button setup. Eventually I want to build a button box, but I'm just trying to get 3 buttons to work first. I am not using a matrix for simplicity. I've tried lots of code examples of reading when the buttons are pressed and all seem to fare the same. It seems to be recording multiple button presses for some reason. (seen in the serial monitor) Also when looking at the "game controller" in windows, as soon as I push a button all of them light up and stay lit up. Following that when I push a button it will deactivate and then light back up which seems opposite to me. I have got to be doing something very stupid since I can't find anyone else having this issue. Can anyone help point me in the right direction? I've already watched Dan's tutorials on youtube plus others. I uploaded a snapshot of the code and serial monitor. Also a diagram of the wiring. I'm using a Leonardo even though the diagram shows an Uno.
Also, in case it's pertinent. I've also noticed that if I push several buttons in succession, the Leonardo will reboot... or crash. I don't know what it's doing, but I lose connection with it and windows then has to detect it again.
Thank you Paul & Tom, I've corrected the wiring mistakes which has stabilized it and fixed the "staying pressed" issues, however I'm still noticing that the code seems to be running twice because I'm seeing "Button X was pressed" twice in the serial monitor for each push. I'm not even sure it's a problem, but since my intent is to build a button box, I don't want to record 2 button presses if it was only pressed once. Also, I'm trying to take advantage of the internal pullup resistor, so I rewired as such. Any ideas?
I tried your code and it works perfectly for me. Even letting me change the pins to whatever I wanted to use which was my problem How do use the pins I want
I too am doing a button box, well it's a truck shift knob to use in ETS2 and ATS, but close enough.
So thank you for your code. I did drop the Serial.printIn lines because they weren't needed.
Admittedly I do wonder if it can be cleaned up, but I'm at point now where I'm not sure I care enough.
Now I get the headache of working on the next thing; a truck driver button box with an ignition switch, buttons, switches and rotaries.