Skip to content

Commit

Permalink
Added brightness to string, fixed clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Feb 3, 2017
1 parent 42a5728 commit 5bcc4dc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
8 changes: 1 addition & 7 deletions examples/stringtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@

scrollphathd.rotate(180)

scrollphathd.write_string("Hello World! ", x=0, y=0, font=font5x7)

#scrollphathd.pixel(0,0,255)
#scrollphathd.pixel(0,1,255)
#scrollphathd.pixel(2,1,255)

#scrollphathd.pixel(22,1,255)
scrollphathd.write_string("Hello World! ", x=0, y=0, font=font5x7, brightness=0.1)

while True:
scrollphathd.show()
Expand Down
7 changes: 4 additions & 3 deletions library/scrollphathd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
flip = display.flip
draw_char = display.draw_char
write_string = display.write_string
clear = display.clear

def clear():
display.fill(0)
def _exit():
display.clear()
display.show()

atexit.register(clear)
atexit.register(_exit)
12 changes: 8 additions & 4 deletions library/scrollphathd/is31fl3731.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def flip(self, x=False, y=False):
self._flipx = x
self._flipy = y

def clear(self):
del self.buf
self.buf = numpy.zeros((self.width, self.height))

def _bank(self, bank=None):
#print "bank", bank

Expand All @@ -75,7 +79,7 @@ def _register(self, bank, register, value=None):

self.i2c.write_i2c_block_data(self.address, register, [value])

def draw_char(self, o_x, o_y, char, font=None):
def draw_char(self, o_x, o_y, char, font=None, brightness=1.0):
if font is None:
if self._font is not None:
font = self._font
Expand All @@ -92,13 +96,13 @@ def draw_char(self, o_x, o_y, char, font=None):

for x in range(len(char[0])):
for y in range(len(char)):
self.pixel(o_x + x, o_y + y, char[y][x])
self.pixel(o_x + x, o_y + y, int(char[y][x] * brightness))

return (o_x + x, o_y + font.height)

def write_string(self, string, x=0, y=0, font=None, letter_spacing=1):
def write_string(self, string, x=0, y=0, font=None, letter_spacing=1, brightness=1.0):
for char in string:
x, n = self.draw_char(x, y, char, font)
x, n = self.draw_char(x, y, char, font=font, brightness=brightness)
x += 1 + letter_spacing

def init(self):
Expand Down

0 comments on commit 5bcc4dc

Please sign in to comment.