1
0
Fork 0
wasp-os/wasp/drivers/vibrator.py

21 lines
517 B
Python
Raw Normal View History

# 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)