lab3_led_Button
This commit is contained in:
3
part2_architecture/lab3-2_gpio_input/main/CMakeLists.txt
Normal file
3
part2_architecture/lab3-2_gpio_input/main/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "."
|
||||
INCLUDE_DIRS ".")
|
||||
2
part2_architecture/lab3-2_gpio_input/main/component.mk
Normal file
2
part2_architecture/lab3-2_gpio_input/main/component.mk
Normal file
@@ -0,0 +1,2 @@
|
||||
COMPONENT_SRCDIRS := .
|
||||
COMPONENT_ADD_INCLUDEDIRS := .
|
||||
50
part2_architecture/lab3-2_gpio_input/main/main.c
Normal file
50
part2_architecture/lab3-2_gpio_input/main/main.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2020 by Fabrice Muller *
|
||||
* *
|
||||
* This file is useful for ESP32 Design course. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file lab3-1_main.c
|
||||
* @author Fabrice Muller
|
||||
* @date 28 Sept. 2020
|
||||
* @brief File containing the lab3-1 of Part 2.
|
||||
*
|
||||
* @see https://github.com/fmuller-pns/esp32-vscode-project-template
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
static const gpio_num_t PIN_LED = 2;
|
||||
static const gpio_num_t PIN_PUSH_BUTTON = 15;
|
||||
|
||||
/**
|
||||
* @brief Starting point function
|
||||
*
|
||||
*/
|
||||
|
||||
void app_main(void) {
|
||||
gpio_pad_select_gpio(PIN_LED);
|
||||
gpio_set_direction(PIN_LED, GPIO_MODE_OUTPUT);
|
||||
gpio_pullup_en(PIN_PUSH_BUTTON);
|
||||
|
||||
uint32_t ledState = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
if(gpio_get_level(PIN_PUSH_BUTTON)==1){
|
||||
ledState = ~ledState;
|
||||
gpio_set_level(PIN_LED, ledState);
|
||||
|
||||
}
|
||||
|
||||
usleep(1000000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user