buzzer.py
# この作品はMITライセンスの下で提供されています。
# Copyright (c) 2013-2025 OpenMV LLC. 全著作権所有。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Pure Thermalブザーサンプルスクリプト
#
# Pure Thermal OpenMVをお買い上げいただきありがとうございます!これは、内蔵ブザーの
# 制御方法を示すシンプルなサンプルスクリプトです。
from pyb import Timer, Pin
import time
# Timer2, Channel2
tim2 = Timer(2, freq=4000)
ch2 = tim2.channel(2, Timer.PWM, pin=Pin("BUZZER"), pulse_width_percent=50)
# 周波数とデューティ比のルックアップテーブルを使ってブザーの周波数とデューティ比を
# 制御し、キャッチーなジングルを再生します。
jingle = [
(1000, 50), (1200, 60), (1400, 70), (1600, 80),
(1800, 90), (2000, 100), (2200, 90), (2400, 80),
(2600, 70), (2800, 60), (3000, 50), (3200, 40),
]
while True:
for freq, duty in jingle:
tim2.freq(freq)
ch2.pulse_width_percent(duty)
time.sleep_ms(200)