from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import time, random
import face_parts
# --- OLED ---
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400000)
oled = SSD1306_I2C(128, 64, i2c, addr=0x3C)
# --- ボタン ---
button = Pin(15, Pin.IN, Pin.PULL_UP)
emotion_list = list(face_parts.EMOTION.keys())
emotion = random.choice(emotion_list)
eye_mode = "both"
last_press = 0
while True:
t = time.ticks_ms()
oled.fill(0)
# --- ボタン押下判定(チャタリング対策) ---
if not button.value() and time.ticks_diff(t, last_press) > 300:
emotion = random.choice(emotion_list)
eye_mode = random.choice(["left", "right", "both"])
last_press = t
face_parts.draw(oled, emotion, eye_mode, t)
oled.show()
time.sleep(1 / 30)