1
0
Fork 0

wasp: Add a super-simple vibrator driver

This commit is contained in:
Daniel Thompson 2020-01-31 19:24:33 +00:00
parent 735d8d094c
commit e36caf5997
3 changed files with 23 additions and 0 deletions

View file

@ -5,6 +5,7 @@ freeze('../..',
'drivers/battery.py',
'drivers/signal.py',
'drivers/st7789.py',
'drivers/vibrator.py',
'logo.py',
),
opt=3

View file

@ -5,6 +5,7 @@ from machine import SPI
from drivers.battery import Battery
from drivers.signal import Signal
from drivers.st7789 import ST7789_SPI
from drivers.vibrator import Vibrator
class Display(ST7789_SPI):
def __init__(self):
@ -51,3 +52,4 @@ battery = Battery(
Pin('BATTERY', Pin.IN),
Signal(Pin('CHARGING', 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
View 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)