# 5 LED Ping-Pong Motion
# ESP32 + MicroPython
# Custom Structured Version
from machine import Pin
import time
# Konfigurasi pin
pin_numbers = [23, 22, 21, 19, 18]
leds = [Pin(p, Pin.OUT) for p in pin_numbers]
total_led = len(leds)
position = 0
direction = 1 # 1 = maju, -1 = mundur
delay_time = 0.30 # detik
def turn_off_all():
for led in leds:
led.value(0)
while True:
turn_off_all()
leds[position].value(1)
time.sleep(delay_time)
position += direction
# Jika sampai ujung, balik arah
if position == total_led - 1 or position == 0:
direction *= -1