0

I am creating a memory game with the Arduino. It has four buttons, each for a different colored led. The leds will blink in a random sequence and either fail or add another light in the next sequence if the user presses the correct buttons. I have also attached an lcd screen to late implement a score tally.

Right now, the welcome lights display and the sound is working fine, but when the sequence starts, it will act as though I am pressing a button and proceed through the fail light method. I think the last method is causing this issue where I am comparing the button pressed to the sequence.

I would appreciate any help!

This is essentially my wiring just with different pins chosen: enter image description here

4
  • What have you done to try to understand the problem? Put some debug prints in, see where it's going wrong.
    – Mark Smith
    Apr 19, 2018 at 14:03
  • I have outputted the button states as well as the button state right before it checks the sequence along with the seq. In the serial monitor it will say button3 = 1 when I have not pressed any buttons since the start of the program.
    – Katie
    Apr 19, 2018 at 14:25
  • the buttons in schema have pull-down resistors
    – Juraj
    Apr 19, 2018 at 18:49
  • That was one of the things I was thinking could be wrong since I declare the pinModes with INPUT_PULLUP. Should I instead just use INPUT? Or would it be more efficient to not have the pull down resistors?
    – Katie
    Apr 19, 2018 at 18:55

2 Answers 2

1

I found that I did not need the pull down resistors for each button since I had declared the pinMode for each button to be INPUT_PULLUP. So instead of the schematic above, I took out the resistors for the buttons and instead wired one side of the buttons to ground.

0

The problem might be that you do not debounce the buttons. When you press a button, there is somehwere between fully pressed and not pressed (or backwards) a state there it 'bounces', e.g. you get lots of state transitions, resulting in seeing a button pressed twice or many times instead of once.

Check the debounce example in the default Arduino Tutorial

7
  • Thank you. I don't even press any buttons though, and it does this.
    – Katie
    Apr 19, 2018 at 13:58
  • Check the variable button just before FailLight, is it -1 (expected) or has it a button (press) value? Apr 19, 2018 at 14:03
  • the button value is 0 before the fail light
    – Katie
    Apr 19, 2018 at 14:11
  • Are you sure that if(button0 == LOW){ should be LOW and not HIGH? Apr 19, 2018 at 14:16
  • well for the pinMode of the buttons, i set them to INPUT_PULLUP so doesn't that make the states opposite? (HIGH when not pressed and LOW when pressed)
    – Katie
    Apr 19, 2018 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.