# Esp32 - kit FKS0001 generating sound by PWM
# provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2026-01-14  initial release

from 	machine 	import 	Pin, PWM
import	time

# ======================= 1000 Hz ============================

# generate 1000 Hz PWM sound. connect IO25 with SPEAKER
def test1000():
    pwm = PWM(Pin(25), freq=1000, duty_u16=0x8000)
    try:
        while True: pass
    finally: pwm.deinit()
    
    
# test1000()

# ======================= 1000 Hz ============================

# generate an alarm PWM sound. connect IO25 with SPEAKER
def testAlarm():
    
    def alarm_single():
        pwm = PWM(Pin(25), freq=1000, duty_u16=0x8000)
        time.sleep_ms(700); pwm.freq(1500)
        time.sleep_ms(700); pwm.freq(1000)
        time.sleep_ms(700); pwm.freq(1500)
        time.sleep_ms(700); pwm.deinit()


    for _ in range(2):
        alarm_single()
        time.sleep(2)


testAlarm()

# ========================== end =============================
