20 lines
422 B
Python
20 lines
422 B
Python
import _thread
|
|
import time
|
|
|
|
import grovepi
|
|
|
|
class Buzzer:
|
|
|
|
_pin : int
|
|
|
|
def __init__(self, pin : int):
|
|
self._pin = pin
|
|
grovepi.pinMode(self._pin, "OUTPUT")
|
|
|
|
def beep(self, duration = 1):
|
|
_thread.start_new_thread(self._beep, (duration,))
|
|
|
|
def _beep(self, duration = 1):
|
|
grovepi.digitalWrite(self._pin, 1)
|
|
time.sleep(duration)
|
|
grovepi.digitalWrite(self._pin, 0) |