From dcd3ec86ab084971db50f7c06c1fba2af45294ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hi=E1=BA=BFu=20=C4=90=E1=BA=B7ng?= <82595057+conghieutk1@users.noreply.github.com> Date: Wed, 27 Sep 2023 21:13:29 +0700 Subject: [PATCH 1/2] =?UTF-8?q?=C4=90=E1=BA=B7ng=20H=E1=BB=AFu=20C=C3=B4ng?= =?UTF-8?q?=20Hi=E1=BA=BFu=2020203417?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- toggleLED.ino | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 toggleLED.ino diff --git a/toggleLED.ino b/toggleLED.ino new file mode 100644 index 0000000..9cd3267 --- /dev/null +++ b/toggleLED.ino @@ -0,0 +1,17 @@ +const int ledPin = 2; +const int buttonPin = 4; +int stateLed = 0; + +void setup() { + Serial.begin(115200); + Serial.println("Hello, ESP32!"); + pinMode (ledPin, OUTPUT); + pinMode (buttonPin, INPUT); +} + +void loop() { + if (digitalRead(buttonPin) == HIGH) { + int stateLed = digitalRead(ledPin); + digitalWrite (ledPin, 1 - stateLed); + } +} From d6c98429936aa2538c9cdda122af6519831a39b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hi=E1=BA=BFu=20=C4=90=E1=BA=B7ng?= <82595057+conghieutk1@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:43:17 +0700 Subject: [PATCH 2/2] =?UTF-8?q?=C4=90=E1=BA=B7ng=20H=E1=BB=AFu=20C=C3=B4ng?= =?UTF-8?q?=20Hi=E1=BA=BFu=2020203417?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Toggle LED --- toggleLED.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 toggleLED.cpp diff --git a/toggleLED.cpp b/toggleLED.cpp new file mode 100644 index 0000000..b1f755e --- /dev/null +++ b/toggleLED.cpp @@ -0,0 +1,19 @@ +#include +const int ledPin = 2; +const int buttonPin = 4; +volatile int ledState = 0; + +void buttonInterrupt() { + ledState = 1 - ledState; + digitalWrite(ledPin, ledState); +} +void setup() { + Serial.begin(115200); + pinMode (ledPin, OUTPUT); + pinMode (buttonPin, INPUT); + attachInterrupt(digitalPinToInterrupt(buttonPin), buttonInterrupt, FALLING); +} + +void loop() { + +}