imrishabh18/rp2040-motor-controller

The circuit implements a powered USB interface with a W25Q16 flash memory chip, a RP2040 microcontroller, and AO3400A MOSFETs for switch control, enabling USB communication, memory storage, and device power management.

Version
1.0.19
License
unset
Stars
0

firmware/audible_alarm.py

"""Passive buzzer driven through Q_BUZZER. No GPIO load current."""
from tmp102 import WARN_C, TRIP_C


def alarm_duty(temperature_c, hardware_alert_ok, now_ms):
    if not hardware_alert_ok or temperature_c is None or temperature_c >= TRIP_C:
        return 32768
    if temperature_c >= WARN_C:
        # Short chirp each second before shutdown temperature is reached.
        return 32768 if now_ms % 1000 < 200 else 0
    return 0


class AudibleAlarm:
    def __init__(self, pwm):
        self.pwm = pwm
        self.pwm.freq(2731)
        self.pwm.duty_u16(0)

    def update(self, temperature_c, hardware_alert_ok, now_ms):
        self.pwm.duty_u16(alarm_duty(temperature_c, hardware_alert_ok, now_ms))

    def close(self):
        self.pwm.duty_u16(0)
        self.pwm.deinit()