def begin(self): wiringpi.pinMode(self.dir, wiringpi.OUTPUT) wiringpi.pinMode(self.pwm, wiringpi.OUTPUT) wiringpi.pinMode(self.brake, wiringpi.OUTPUT) wiringpi.analogWrite(self.pwm, 0) wiringpi.digitalWrite(self.brake, wiringpi.LOW)
def run(self, direction, speed): if (direction == 1): wiringpi.digitalWrite(self.dir, wiringpi.HIGH) else: wiringpi.digitalWrite(self.dir, wiringpi.LOW) wiringpi.digitalWrite(self.brake, wiringpi.LOW) wiringpi.analogWrite(self.pwm, speed)
def _analog_write(self, pin, val): if self.board_type == '': if self._supports_analog(pin): wp.analogWrite(pin, val) else: self._digital_write(pin, val * 1023) elif self.board_type == 'troyka_cap_ext': self.exp.analogWrite(pin, val)
def __init__(self, pin_number, pin_mode, active_low_mode, pwm_max, piglow=False, led=None): self.pin_number = pin_number self.pwm = pin_mode self.pwm_max = pwm_max self.active_low_mode = active_low_mode self.pwm_on = pwm_max * int(not active_low_mode) self.pwm_off = pwm_max * int(active_low_mode) self.inout = 'Not set' self.always_on = False self.always_off = False self.inverted = False self.is_led = False self.led_m = led if pin_number > 999: self.is_led = True self.pin_number -= 1000 self.action = lambda b: self.led_m.write(self.pin_number, int(b * 255)) self.active_low_mode = False else: if self.pwm: self.action = lambda b: wiringpi.softPwmWrite( self.pin_number, int(b * self.pwm_max)) elif piglow: self.action = lambda b: wiringpi.analogWrite( self.pin_number + 577, int(b * 255)) else: self.action = lambda b: wiringpi.digitalWrite( self.pin_number, int(b > 0.5))
def release(self): wiringpi.digitalWrite(self.brake, wiringpi.LOW) wiringpi.analogWrite(self.pwm, 0)
def stop(self): wiringpi.digitalWrite(self.brake, wiringpi.HIGH) wiringpi.analogWrite(self.pwm, 255)
def _analog_write(self, pin, val): if self._supports_analog(pin): wp.analogWrite(pin, val) else: self._digital_write(pin, val * 1023)