About Lesson
A. The Blink LED Example
The classic “Blink” program is a simple way to verify that everything is working correctly.
**1. Understanding the Code
Here’s a simple example code that blinks an LED connected to GPIO 2 on the ESP32:
cpp
void setup() {
pinMode(2, OUTPUT); // Initialize digital pin 2 as an output.
}
void loop() {
digitalWrite(2, HIGH); // Turn the LED on.
delay(1000); // Wait for a second.
digitalWrite(2, LOW); // Turn the LED off.
delay(1000); // Wait for a second.
}
- setup(): Initializes the pin as an output.
- loop(): Repeats the process of turning the LED on and off with a delay.
**2. Uploading the Code
- Select the ESP32 board from Tools → Board.
- Choose the correct COM port from Tools → Port.
- Click the upload button and wait for the code to compile and upload.
B. Observing the Results
The LED on the ESP32 board should blink on and off, indicating that your program is running correctly.
C. Troubleshooting
- Common issues (e.g., COM port not found, driver issues).
Interactive Element:
- Code Editor: Try modifying the delay time in the provided code snippet and see how it affects the LED blink rate.