def set(self, value): value = constrain(value, 0, DIGIPOT_MAX_AMOUNT) if self._currentValue is None: self.reset() if self._currentValue > value: self.change(-1, self._currentValue - value) elif self._currentValue < value: self.change(1, value - self._currentValue)
def change(self, direction, amount): if direction == 1: ud = HIGH elif direction == -1: ud = LOW else: raise ValueError('invalid direction: %s', direction) amount = constrain(amount, 0, DIGIPOT_MAX_AMOUNT) if amount == 0: return if self._udLastValue != ud: self._udPin.write_digital_value(ud) for _ in range(amount): self._incPin.write_digital_value(LOW) self._incPin.write_digital_value(HIGH) if self._currentValue is not None: self._currentValue += direction self._currentValue = constrain(self._currentValue, 0, DIGIPOT_MAX_AMOUNT)
def change(self, direction, amount): if direction == 1: ud = HIGH elif direction == -1: ud = LOW else: raise ValueError('invalid direction: %s', direction) amount = constrain(amount, 0, DIGIPOT_MAX_AMOUNT) if amount == 0: return if self._udLastValue != ud: self._udPin.write_digital_value(ud) for _ in range(amount): self._incPin.write_digital_value(LOW) self._incPin.write_digital_value(HIGH) if self._currentValue is not None: self._currentValue += direction self._currentValue = constrain( self._currentValue, 0, DIGIPOT_MAX_AMOUNT)
def decrease(self, amount): amount = constrain(amount, 0, DIGIPOT_MAX_AMOUNT) self.change(-1, amount)