Files

26 lines
688 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pigpio
class Barrier:
def __init__(self, pin=12, min_pw=500, max_pw=2400):
self.pi = pigpio.pi()
if not self.pi.connected:
raise RuntimeError("Cannot connect to pigpiod – is it running?")
self.pin = pin
self.min = min_pw
self.max = max_pw
self.pi.set_mode(pin, pigpio.OUTPUT)
self.close()
def set_angle(self, deg):
pulse = self.min + (deg / 180.0) * (self.max - self.min)
self.pi.set_servo_pulsewidth(self.pin, pulse)
def open(self):
self.set_angle(0)
def close(self):
self.set_angle(90)
def stop(self):
self.pi.set_servo_pulsewidth(self.pin, 0)