[esp] Add ESP examples.

This commit is contained in:
2025-02-01 10:30:18 -05:00
parent 5f9f508581
commit 8bf174d256
17 changed files with 278 additions and 17 deletions

View File

@@ -0,0 +1,38 @@
// set pin numbers
const int buttonPin = 4; // the number of the pushbutton pin
const int ledPin = 5; // the number of the LED pin
// variable for storing the pushbutton status
int buttonState = 0;
bool light_on = false;
bool handled = false;
void setup() {
Serial.begin(115200);
// initialize the pushbutton pin as an input
pinMode(buttonPin, INPUT);
// initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the state of the pushbutton value
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
if (buttonState == HIGH) {
if (!handled) {
Serial.println("Handling button pressed.");
light_on = !light_on;
handled = true;
digitalWrite(ledPin, light_on ? HIGH : LOW);
}
// turn LED on
} else {
if (handled) {
Serial.println("Reset button handled state.");
handled = false;
}
}
}

View File

@@ -0,0 +1,5 @@
# 01_led-button
![schematic](./schematic.png)
Simple LED controlled by an on-board button.

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB