Pomodoro timer ・ 番茄钟
集中作業用のポモドーロタイマー。ブザーとボタンで制御。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack Core2 | Controller | grove_i2c, grove_analog, grove_uart, mbus | official page — $46.9 |
| Unit Buzzer | Buzzer | grove_analog | official page — $4.5 |
| Unit Button | Button | grove_analog | official page — $2.25 |
M5Stack Core2とブザーユニット、ボタンユニットで作るポモドーロタイマーです。ボタンを押して作業開始、25分後にブザーが鳴り、休憩時間に切り替わります。集中力アップに役立ちます。
# M5Stack Core2 + Buzzer + Button (Pomodoro Timer)
# Wiring:
# Buzzer -> Core2 left Port.B (GPIO 36)
# Button -> Core2 right Port.B (GPIO 26)
import time
from machine import Pin, PWM
from m5stack import lcd, btnA
# Pin definitions
buzzer_pin = PWM(Pin(36), freq=4000, duty=512) # 4KHz, 50% duty
button_pin = Pin(26, Pin.IN, Pin.PULL_UP) # button pulls low when pressed
# Timer durations (in seconds)
WORK_TIME = 25 * 60 # 25 minutes
BREAK_TIME = 5 * 60 # 5 minutes
state = 'idle' # 'idle', 'work', 'break'
remaining = 0
def beep():
buzzer_pin.duty(512)
time.sleep(0.2)
buzzer_pin.duty(0)
def update_display():
lcd.clear()
lcd.font(lcd.FONT_DejaVu18)
lcd.print('Pomodoro Timer', 10, 10)
if state == 'idle':
lcd.print('Press button to start', 10, 50)
else:
mins = remaining // 60
secs = remaining % 60
lcd.print('{}: {:02d}:{:02d}'.format(state.upper(), mins, secs), 10, 50)
# Main loop
while True:
if state == 'idle':
update_display()
if button_pin.value() == 0: # button pressed
time.sleep(0.05) # debounce
while button_pin.value() == 0:
pass
state = 'work'
remaining = WORK_TIME
beep()
elif state == 'work':
update_display()
time.sleep(1)
remaining -= 1
if remaining <= 0:
beep()
state = 'break'
remaining = BREAK_TIME
elif state == 'break':
update_display()
if button_pin.value() == 0: # button pressed to skip break
time.sleep(0.05)
while button_pin.value() == 0:
pass
state = 'work'
remaining = WORK_TIME
beep()
else:
time.sleep(1)
remaining -= 1
if remaining <= 0:
beep()
state = 'idle'
time.sleep(0.1)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。