diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-01-31 19:24:33 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-01-31 19:34:04 (GMT) |
| commit | e36caf59975b9705aff4f15d6642043aec4f27c6 (patch) | |
| tree | eec6dcc49ac749ef8a9bd1fefbdc93703e939506 /wasp/drivers | |
| parent | 735d8d094c81fe43688834151c5291e22f169099 (diff) | |
wasp: Add a super-simple vibrator driver
Diffstat (limited to 'wasp/drivers')
| -rw-r--r-- | wasp/drivers/vibrator.py | 20 |
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) + |
