'''
01.10 - LED blink with loop
This sketch shows how to blink an LED connected to GPIO 21 using a loop.
Components
----------
- ESP32
- 330Ohm resistor for the LED
- 5mm LED
- Connect anode to GPIO 21
- Connect cathode to GND via the resistor
- Wires
- Breadboard
Documentation:
Pins and GPIO: https://micropython-docs-esp32.readthedocs.io/en/esp32_doc/esp32/quickref.html#pins-and-gpio
sleep_ms: http://docs.micropython.org/en/latest/library/utime.html?highlight=utime%20sleep#utime.sleep_ms
Course:
MicroPython with the ESP32
'''
import time
from machine import Pin
# Define the GPIO pins for the LEDs
led_pins = [21, 19, 18] # Assuming you have three LEDs connected to GPIO pins 2, 4, and 5
# Initialize the LED pins
leds = [Pin(pin, Pin.OUT) for pin in led_pins]
# Function to alternate the state of LEDs
def alternate_leds():
for i in range(len(leds)):
leds[i].on() # Turn on the current LED
time.sleep(0.5) # Wait for a short duration
leds[i].off() # Turn off the current LED
time.sleep(0.1) # Wait for a short duration
# Main loop
while True:
alternate_leds()