summaryrefslogtreecommitdiff
path: root/wasp/drivers
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-01-31 19:24:33 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-01-31 19:34:04 (GMT)
commite36caf59975b9705aff4f15d6642043aec4f27c6 (patch)
treeeec6dcc49ac749ef8a9bd1fefbdc93703e939506 /wasp/drivers
parent735d8d094c81fe43688834151c5291e22f169099 (diff)
wasp: Add a super-simple vibrator driver
Diffstat (limited to 'wasp/drivers')
-rw-r--r--wasp/drivers/vibrator.py20
1 files changed, 20 insertions, 0 deletions
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)
+