Skip to content

Commit

Permalink
Added wrap_around option for pixel.increment()
Browse files Browse the repository at this point in the history
  • Loading branch information
speratus committed Oct 31, 2019
1 parent 8f3f4e9 commit 0bfa94d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions blinkter/pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ def draw(self):
blinkt.show()
self.board.lock.release()
## print('drew the pixel. If nothing shows, then there is an error somewhere.')


def increment(self, led: LED, amount=0):

def increment(self, led: LED, amount=0, wrap_around=False):
"""
Increments the selected LED's brightness by the specified amount.
Expand All @@ -144,15 +143,17 @@ def increment(self, led: LED, amount=0):
The amount to increase the brightness of the specified LED.
"""
self._keep_color()
too_hi = 0 if wrap_around is True else 255
too_lo = 255 if wrap_around is True else 0

a = amount if amount is not 0 else self.increment_amount
#print(f'using value {a}')
c = self.rgb[led.value]
if c+a > 255:
c = 255
c = too_hi
self.rgb[led.value] = c
elif c+a < 0:
c = 0
c = too_lo
self.rgb[led.value] = c
else:
c += a
Expand Down

0 comments on commit 0bfa94d

Please sign in to comment.