#include "driver/gpio.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
// Define the pin numbers for the buttons and LED
#define BUTTON_1_PIN 18
#define BUTTON_2_PIN 19
#define LED_PIN 2
void app_main(void)
{
//changing the LED pins to output
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
//changing the LED pins to output
gpio_set_direction(BUTTON_1_PIN, GPIO_MODE_INPUT);
//changing the LED pins to output
gpio_set_direction(BUTTON_2_PIN, GPIO_MODE_INPUT);
//while condition to state that when one button is pressed turn LED on and if two or none are touched LED will be off
while (1) {
// if the button state matches the get level turn on
int button1_state = gpio_get_level(BUTTON_1_PIN);
int button2_state = gpio_get_level(BUTTON_2_PIN);
// Turn LED on if button is presses
if ((button1_state == 0 && button2_state == 1) || (button1_state == 1 && button2_state == 0)) {
gpio_set_level(LED_PIN, 1); // Turn LED ON
}
// Turn LED OFF if both buttons are pressed or neither is pressed
else {
gpio_set_level(LED_PIN, 0); // Turn LED OFF
}
// Delay
vTaskDelay(50 / portTICK_PERIOD_MS);
}
}Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1