From 5cada423345feb46efc9204d0c8af8954a134bdd Mon Sep 17 00:00:00 2001 From: PhanAnhNguyen08 Date: Tue, 26 Sep 2023 23:08:06 +0700 Subject: [PATCH] pushcode --- .vscode/c_cpp_properties.json | 20 ++++++++++++++++++++ exercise.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 exercise.cpp diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c1afae2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "windows-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/exercise.cpp b/exercise.cpp new file mode 100644 index 0000000..8749b10 --- /dev/null +++ b/exercise.cpp @@ -0,0 +1,31 @@ +#include +#define BUTTON_PIN 26 +#define LED_PIN 18 + + +int led_state = LOW; +int button_state; + +void setup() { + + Serial.begin(115200); + Serial.println("Hello, ESP32!"); + pinMode(LED_PIN, OUTPUT); + pinMode(BUTTON_PIN, INPUT_PULLUP); + button_state = digitalRead(BUTTON_PIN); +} + +void loop() { + button_state = digitalRead(BUTTON_PIN); + delay(100); + if (button_state == LOW) { + Serial.println("The button is pressed"); + // toggle state of LED + digitalWrite(LED_PIN, HIGH); + delay(5000); + digitalWrite(LED_PIN, LOW); + delay(1000); + }else{ + digitalWrite(LED_PIN, LOW); + delay(1000); + } \ No newline at end of file