Need help with button box code.

So im currently using an arduino mega to test somethings while my micro isn’t here. Im a eletronic and programming student and i can’t seem to figure out how to get 13 buttons to work. Could someone help me with some code? Im familiarized with pull down and pull up resistors.

Connect the buttons between input and ground and enable the internal pull ups, in the pin mode statement in the setup function.

CreepyShot: So im currently using an arduino mega to test somethings while my micro isn't here. Im a eletronic and programming student and i can't seem to figure out how to get 13 buttons to work. Could someone help me with some code? Im familiarized with pull down and pull up resistors.

I'm not quite sure what you mean by "arduino mega to test somethings while my micro isn't here." To me it sounds like you pulled the micro off the Arduino board but I'm sure that can't be what you meant :)

Do you have a schematic yet of your buttons attached to your mega? If so please post it.

The code would be fairly simple. You would copy an example that reads one button (like this one), then copy it with 13 buttons connected to 13 GPIO on your Mega.

While my arduino micro im going to use to simulate button presses isn't here ahah

Grumpy_Mike:
Connect the buttons between input and ground and enable the internal pull ups, in the pin mode statement in the setup function.

Going to try that, but how do i check if button is pressed in a “If” statement?

If the button is connected between the input pin and ground:-
(We’ll assume it’s connected to digital pin 2.)

const byte button1 = 2;    // Button 1 on pin 2 (Declared globally at the top of the sketch.)
.
.
pinMode(button1, INPUT_PULLUP);    // Enable internal pullup on Button 1 (In the 'setup()' function)
.
.
if(digitalRead(button1) == LOW)    // If button1 is pressed. (In 'loop()' or another function.)
{
    // do something here
}

Hi, Look at the example sketches in the programming IDE, it will give to examples of how to read and write to input and output arduinio I/O.

Hope this helps... Tom.. :)