
Our if statement checks the state of the button using the built-in digitalRead function. This function can only check on button at a time, using the variable it gets from the main loop function so that it knows which button the check. void checkPush ( int pinNumber)įollowing this, we need to assign the variable we are using and create an if statement to detect when each button is pressed.
GETTING INPUT FROM WIRE ARDUINO CODE
To start, we need to declare our function with an integer variable like the code below. This next stage is more complex than the others, as we will be creating our own function that will be dealing with a variable from the main loop function.

PinMode(input1Pin, INPUT) // these lines declare each of the buttons as an input
GETTING INPUT FROM WIRE ARDUINO SERIAL
Serial.begin( 57600) // this begins the serial connection with a baud rate of 57600 This is all we need in our void setup() function.

First, we will start our serial connection with a baud rate of 57600, followed by the initialization of our buttons. Int input1Pin = 2 Setting Up the ButtonsĪs with most Arduino projects, we will be using a function that will run once at the beginning of the program, called void setup(). This should be placed at the top of your Arduino project, before any of the functions. Seeing as we used Digital Pins 2, 3, 4, and 5, these are the pins we will declare with our code. Assigning Buttons to Pinsįor the first step, we need to assign our buttons to the different pins on our Arduino board. The code for the project is nice and simple, without the need for any class libraries or other complicated programming.

Programming Multiple Push-Buttons With an Arduino
