Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Đặng Hữu Công Hiếu 20203417 #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions toggleLED.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <Arduino.h>
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() {

}
17 changes: 17 additions & 0 deletions toggleLED.ino
Original file line number Diff line number Diff line change
@@ -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);
}
}