Add buzzer and led support
This commit is contained in:
0
rpi/hardware/buzzer/__init__.py
Normal file
0
rpi/hardware/buzzer/__init__.py
Normal file
20
rpi/hardware/buzzer/buzzer.py
Normal file
20
rpi/hardware/buzzer/buzzer.py
Normal file
@@ -0,0 +1,20 @@
|
||||
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)
|
||||
0
rpi/hardware/led/__init__.py
Normal file
0
rpi/hardware/led/__init__.py
Normal file
15
rpi/hardware/led/led.py
Normal file
15
rpi/hardware/led/led.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import grovepi
|
||||
|
||||
class Led:
|
||||
|
||||
_pin : int
|
||||
|
||||
def __init__(self, pin : int):
|
||||
self._pin = pin
|
||||
grovepi.pinMode(self._pin, "OUTPUT")
|
||||
|
||||
def on(self):
|
||||
grovepi.digitalWrite(self._pin, 1)
|
||||
|
||||
def off(self):
|
||||
grovepi.digitalWrite(self._pin, 0)
|
||||
Reference in New Issue
Block a user