I wrote a simple script to check if there are buttons pressed. I added a pull down resistor between output of my tactile button and ground. The output of the buttons go to A0, A1, A2, ..., A6. At the input pin of the buttons I put 5V. My script does something very weird. When I press the button it keeps spamming the message "Button pressed". But when I uncomment the third line in this piece of code it suddenly works (which means it only prints "Button pressed" once for every time I press the button).
Nowhere other than in this piece of the code are buttonsPressed[] and buttonsHeld[] changed, printed or whatever. Except for the setup which sets all the values to false.
Anteino:
Alright here it is. But it doesn't really add anything.
It adds a very important extra - now I know there is nothing else important. You would be surprised what gets left out.
I added a pull down resistor between output of my tactile button and ground.
That does not sound correct. I suspect the input is floating.
Either put a pull-up resistor on the pin (or better still use pinMode(pin, INPUT_PULLUP) ) and use the switch to pull it to GND. Or use a pull-down resistor on the pin and use the switch to pull it to 5v. The former is better as it is less likely to give rise to a short circuit is something comes adrift.