def noTone(pin): GPIO.PWM(pin).stop()
def tone(pin, frequency, duration=None): p = GPIO.PWM(pin, frequency) p.start(50) if duration is not None and duration > 0: threading.Timer(duration, lambda *args, **kwargs: p.stop()).start()