tags:

views:

36

answers:

1

Hi,

I'd like to detect two buttons being pressed together with the Arduino LCD shield. Does anyone have example code of handling multiple button events? I need an event when both the Up and Down buttons are pressed together for 2 seconds.

Thanks,

Richard.

A: 

from what I've read about arduino, you need to set up a couple bool variables to detect when the button is pressed. Then if they are both true you can do the thing you want to do. Here's some pseudo code. Hopefully you already have what you need to fill in the rest.

I'm assuming you already know how to check if the button is pressed and already know how to do the thing you want to do when they are both pressed.

bool button1Pressed = CheckIfButtonPressed(1);
bool button2Pressed = CheckIfButtonPressed(2);

if (button1Pressed && button2Pressed)
  DoTheThingYouWantToDoWhenBothButtonsArePressed();

NOTE: You may also want to include some timing code to make sure you don't keep doing the thing you want to do when the buttons are held down. For that you would set a time stamp in body of the if statement and also include an else to un-set the time stamp.

gbogumil