ButtonLED Dev
This commit is contained in:
6
ButtonLED/main/CMakeLists.txt
Normal file
6
ButtonLED/main/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
idf_component_register(
|
||||
SRCS "Main.c"
|
||||
PRIV_REQUIRES spi_flash
|
||||
INCLUDE_DIRS ""
|
||||
PRIV_REQUIRES esp_driver_gpio
|
||||
)
|
27
ButtonLED/main/Main.c
Normal file
27
ButtonLED/main/Main.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#define LED_GPIO 7
|
||||
#define BUTTON_GPIO 1
|
||||
|
||||
void app_main(void) {
|
||||
// Set led pin to output
|
||||
gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT);
|
||||
|
||||
// Set button to input
|
||||
gpio_set_direction(BUTTON_GPIO, GPIO_MODE_INPUT);
|
||||
|
||||
while(1) {
|
||||
if (gpio_get_level(BUTTON_GPIO) == 1) {
|
||||
printf("Trunning LED On/n");
|
||||
gpio_set_level(LED_GPIO, 0);
|
||||
} else {
|
||||
printf("LED is off/n");
|
||||
gpio_set_level(LED_GPIO, 1);
|
||||
}
|
||||
vTaskDelay(100);
|
||||
return;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user