wasp: Add a super-simple vibrator driver
This commit is contained in:
parent
735d8d094c
commit
e36caf5997
3 changed files with 23 additions and 0 deletions
|
@ -5,6 +5,7 @@ freeze('../..',
|
||||||
'drivers/battery.py',
|
'drivers/battery.py',
|
||||||
'drivers/signal.py',
|
'drivers/signal.py',
|
||||||
'drivers/st7789.py',
|
'drivers/st7789.py',
|
||||||
|
'drivers/vibrator.py',
|
||||||
'logo.py',
|
'logo.py',
|
||||||
),
|
),
|
||||||
opt=3
|
opt=3
|
||||||
|
|
|
@ -5,6 +5,7 @@ from machine import SPI
|
||||||
from drivers.battery import Battery
|
from drivers.battery import Battery
|
||||||
from drivers.signal import Signal
|
from drivers.signal import Signal
|
||||||
from drivers.st7789 import ST7789_SPI
|
from drivers.st7789 import ST7789_SPI
|
||||||
|
from drivers.vibrator import Vibrator
|
||||||
|
|
||||||
class Display(ST7789_SPI):
|
class Display(ST7789_SPI):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -51,3 +52,4 @@ battery = Battery(
|
||||||
Pin('BATTERY', Pin.IN),
|
Pin('BATTERY', Pin.IN),
|
||||||
Signal(Pin('CHARGING', Pin.IN), invert=True),
|
Signal(Pin('CHARGING', Pin.IN), invert=True),
|
||||||
Signal(Pin('USB_PWR', Pin.IN), invert=True))
|
Signal(Pin('USB_PWR', Pin.IN), invert=True))
|
||||||
|
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)
|
||||||
|
|
20
wasp/drivers/vibrator.py
Normal file
20
wasp/drivers/vibrator.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# Generic PWM capable vibrator
|
||||||
|
|
||||||
|
import time
|
||||||
|
from machine import PWM
|
||||||
|
|
||||||
|
class Vibrator(object):
|
||||||
|
def __init__(self, pin, active_low=False):
|
||||||
|
pin.value(active_low)
|
||||||
|
self.pin = pin
|
||||||
|
self.freq = PWM.FREQ_16MHZ
|
||||||
|
self.period = 16000
|
||||||
|
self.active_low = active_low
|
||||||
|
|
||||||
|
def pulse(self, duty=50, ms=100):
|
||||||
|
pwm = PWM(0, self.pin, freq=self.freq, duty=duty, period=self.period)
|
||||||
|
pwm.init()
|
||||||
|
time.sleep_ms(ms)
|
||||||
|
pwm.deinit()
|
||||||
|
self.pin.value(self.active_low)
|
||||||
|
|
Loading…
Reference in a new issue