Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
    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)
Exemple #4
0
    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)
Exemple #5
0
 def decrease(self, amount):
     amount = constrain(amount, 0, DIGIPOT_MAX_AMOUNT)
     self.change(-1, amount)
Exemple #6
0
 def decrease(self, amount):
     amount = constrain(amount, 0, DIGIPOT_MAX_AMOUNT)
     self.change(-1, amount)