from machine import Pin, I2C
import time
import pcf8575
SCL = 17
SDA = 16
# I2C 設定 (依你的板子腳位調整)
i2c = I2C(0, scl=Pin(SCL), sda=Pin(SDA), freq=400000)
pcf = pcf8575.PCF8575(i2c, 0x20)
# turn LED on
pcf.port = 0x0000
time.sleep_ms(500)
# turn LED off
pcf.port = 0xFFFF
time.sleep_ms(500)
while True:
leds = 1
for i in range(1, 17):
# 將要控制的燈狀態寫入 PCF8575
pcf.port = 0x0000
time.sleep_ms(100)
pcf.port = leds
time.sleep_ms(100)
# 計算要打開的燈的位置
leds = leds << 1