SunFounder ESP32 Starter Kit
while True:
# Turn on the LED by setting its value to 1 (HIGH)
led.value(1)
# Wait for 1 second (1000 milliseconds) while the LED is on
time.sleep(1)
# Turn off the LED by setting its value to 0 (LOW)
led.value(0)
# Wait for 0.5 seconds (500 milliseconds) while the LED is off
time.sleep(0.5)
Learn More
In this project, we used MicroPython’s machine and time module, we can find more ways to use them here.
• machine.Pin
• time
3.8 2.2 Fading LED
In the previous project, we controlled the LED by turning it on and off using digital output. In this project, we will
create a breathing effect on the LED by utilizing Pulse Width Modulation (PWM). PWM is a technique that allows us
to control the brightness of an LED or the speed of a motor by varying the duty cycle of a square wave signal.
With PWM, instead of simply turning the LED on or off, we will be adjusting the amount of time the LED is on versus
the amount of time it is off within each cycle. By rapidly switching the LED on and off at varying intervals, we can
create the illusion of the LED gradually brightening and dimming, simulating a breathing effect.
By using the PWM capabilities of the ESP32 WROOM 32E, we can achieve smooth and precise control over the
LED’s brightness. This breathing effect adds a dynamic and visually appealing element to your projects, creating an
eye-catching display or ambiance.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
ESP32 Starter Kit 320+
You can also buy them separately from the links below.
3.8. 2.2 Fading LED 311