From e36caf59975b9705aff4f15d6642043aec4f27c6 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Fri, 31 Jan 2020 19:24:33 +0000 Subject: [PATCH] wasp: Add a super-simple vibrator driver --- wasp/boards/pinetime/manifest.py | 1 + wasp/boards/pinetime/watch.py | 2 ++ wasp/drivers/vibrator.py | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 wasp/drivers/vibrator.py diff --git a/wasp/boards/pinetime/manifest.py b/wasp/boards/pinetime/manifest.py index 22fd135..5e525e3 100644 --- a/wasp/boards/pinetime/manifest.py +++ b/wasp/boards/pinetime/manifest.py @@ -5,6 +5,7 @@ freeze('../..', 'drivers/battery.py', 'drivers/signal.py', 'drivers/st7789.py', + 'drivers/vibrator.py', 'logo.py', ), opt=3 diff --git a/wasp/boards/pinetime/watch.py b/wasp/boards/pinetime/watch.py index 730eebc..0d0fa4b 100644 --- a/wasp/boards/pinetime/watch.py +++ b/wasp/boards/pinetime/watch.py @@ -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) diff --git a/wasp/drivers/vibrator.py b/wasp/drivers/vibrator.py new file mode 100644 index 0000000..eba6018 --- /dev/null +++ b/wasp/drivers/vibrator.py @@ -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) +