const int buttonPin1 = 15; // GPIO pin connected to the button
const int buttonPin2 = 2; // GPIO pin connected to the button
const int buttonPin3 = 0; // GPIO pin connected to the button
const int buttonPin4 = 22; // GPIO pin connected to the button
const int LEDPin1 = 27; // GPIO pin connected to LED1
const int LEDPin2 = 26; // GPIO pin connected to LED2
const int LEDPin3 = 25; // GPIO pin connected to LED3
const int LEDPin4 = 33; // GPIO pin connected to LED4
bool LEDState1 = false; // Variable to store the LED state
bool LEDState2 = false; // Variable to store the LED state
bool LEDState3 = false; // Variable to store the LED state
bool LEDState4 = false; // Variable to store the LED state
void setup() {
Serial.begin((115200));
pinMode(buttonPin1, INPUT_PULLUP); // initialize buttonPin1 as input
pinMode(buttonPin2, INPUT_PULLUP); // initialize buttonPin2 as input
pinMode(buttonPin3, INPUT_PULLUP); // initialize buttonPin3 as input
pinMode(buttonPin4, INPUT_PULLUP); // initialize buttonPin4 as input
pinMode(LEDPin1, OUTPUT); // initialize the LEDpin1 as output
pinMode(LEDPin2, OUTPUT); // initialize the LEDpin2 as output
pinMode(LEDPin3, OUTPUT); // initialize the LEDpin3 as output
pinMode(LEDPin4, OUTPUT); // initialize the LEDpin4 as output
}
void loop() {
int buttonState1 = digitalRead(buttonPin1); // read the state of buttonPin1
int buttonState2 = digitalRead(buttonPin2); // read the state of buttonPin2
int buttonState3 = digitalRead(buttonPin3); // read the state of buttonPin3
int buttonState4 = digitalRead(buttonPin4); // read the state of buttonPin4
// if the button is pressed, toggle the LED state
if (buttonState1 == LOW) {
LEDState1 = !LEDState1; // Toggle the LED state
digitalWrite(LEDPin1, LEDState1); // Update the LED
delay(100); // Add a small delay to debounce the button
}
if (buttonState2 == LOW) {
LEDState2 = !LEDState2; // Toggle the LED state
digitalWrite(LEDPin2, LEDState2); // Update the LED
delay(100); // Add a small delay to debounce the button
}
if (buttonState3 == LOW) {
LEDState3 = !LEDState3; // Toggle the LED state
digitalWrite(LEDPin3, LEDState3); // Update the LED
delay(100); // Add a small delay to debounce the button
}
if (buttonState4 == LOW) {
LEDState4 = !LEDState4; // Toggle the LED state
digitalWrite(LEDPin4, LEDState4); // Update the LED
delay(100); // Add a small delay to debounce the button
}
// Serial.print(LEDState1);
delay(50); // debounce delay for stability
}