Below are the codes of 2 buttons on/off
// constants won't change. They're used here to set pin numbers:
const int buttonPin2 = 6; // the number of the pushbutton pin
const int buttonPin3 = 7;
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState2 = 0; // variables for reading the pushbutton status
int buttonState3 = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
}
void loop() {
// read the state of the pushbutton values:
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
// check if the pushbutton 2 is pressed. If it is, the buttonState is LOW:
if (buttonState2 == LOW) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
// check if the pushbutton 3 is pressed. If it is, the buttonState is LOW:
if (buttonState3 == LOW) {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}