Permalink
Browse files

Docstrings, api tweaks, examples tidied + more

  • Loading branch information...
Gadgetoid committed Feb 10, 2017
1 parent 5bcc4dc commit 931758410d50eb51571bd18c0715c1240863cf94
@@ -0,0 +1,66 @@
#!/usr/bin/env python
import time
import scrollphathd
print("""Advanced Scrolling
Advanced scrolling example which displays a message line-by-line
and then skips back to the beginning.
Press Ctrl+C to exit.
""")
scrollphathd.rotate(180)
rewind = True
delay = 0.03
line_height = scrollphathd.DISPLAY_HEIGHT + 2
lines = ["In the old #BILGETANK we'll keep you in the know",
"In the old #BILGETANK we'll fix your techie woes",
"And we'll make things",
"And we'll break things",
"'til we're altogether aching",
"Then we'll grab a cup of grog down in the old #BILGETANK"]
lengths = [0] * len(lines)
offset_left = 0
for line, text in enumerate(lines):
lengths[line] = scrollphathd.write_string(text, x=offset_left, y=line_height * line)
offset_left += lengths[line]
scrollphathd.set_pixel(0, (len(lines) * line_height) - 1, 0)
current_line = 0
scrollphathd.show()
while True:
pos_x = 0
pos_y = 0
for current_line in range(len(lines)):
time.sleep(delay*10)
for y in range(lengths[current_line]):
scrollphathd.scroll(1,0)
pos_x += 1
time.sleep(delay)
scrollphathd.show()
if current_line == len(lines) - 1 and rewind:
for y in range(pos_y):
scrollphathd.scroll(-int(pos_x/pos_y),-1)
scrollphathd.show()
time.sleep(delay)
scrollphathd.scroll_to(0,0)
scrollphathd.show()
time.sleep(delay)
else:
for x in range(line_height):
scrollphathd.scroll(0,1)
pos_y += 1
scrollphathd.show()
time.sleep(delay)
View
@@ -1,15 +1,17 @@
#!/usr/bin/env python
import time
import signal
import scrollphathd
from scrollphathd.fonts import font5x7 as font5x7
from scrollphathd.fonts import font5x7
scrollphathd.rotate(180)
scrollphathd.write_string("Hello World! ", x=0, y=0, font=font5x7, brightness=0.1)
scrollphathd.write_string("Hello World! ", x=0, y=0, font=font5x7, brightness=0.5)
while True:
scrollphathd.show()
scrollphathd.scroll(-1,0)
scrollphathd.scroll(1)
time.sleep(0.05)
File renamed without changes.
View
9 examples/plasma.py 100644 → 100755
@@ -1,18 +1,19 @@
#!/usr/bin/env python
import time
import math
import scrollphathd
speed_factor = 10
i = 0
while True:
i += 2
s = math.sin(i / 50.0) * 2.0 + 6.0
print(s)
for x in range(0, 17):
for y in range(0, 7):
v = 128.0 + (128.0 * math.sin((x * s) + i / 4.0) * math.cos((y * s) + i / 4.0))
v = 0.3 + (0.3 * math.sin((x * s) + i / 4.0) * math.cos((y * s) + i / 4.0))
scrollphathd.pixel(x, y, v)
View
34 examples/robot-mouth.py 100644 → 100755
@@ -1,20 +1,34 @@
#!/usr/bin/env python
import time
import math
from PIL import Image
import scrollphathd
img = Image.open("ahoy.bmp")
IMAGE_BRIGHTNESS = 0.5
img = Image.open("mouth.bmp")
def get_pixel(x, y):
p = img.getpixel((x,y))
if img.getpalette() is not None:
r, g, b = img.getpalette()[p:p+3]
p = max(r, g, b)
speed_factor = 10
return p / 255.0
try:
while True:
for x in range(0, 17):
for y in range(0, 7):
v = img.getpixel((x,y))
scrollphathd.pixel(x, 6-y, math.floor(v / 50) * 50)
for x in range(0, 17):
for y in range(0, 7):
brightness = get_pixel(x, y)
scrollphathd.pixel(x, 6-y, brightness * IMAGE_BRIGHTNESS)
scrollphathd.show()
while True:
scrollphathd.show()
time.sleep(0.03)
scrollphathd.scroll(-1)
except KeyboardInterrupt:
scrollphathd.fill(0)
scrollphathd.clear()
scrollphathd.show()
@@ -1,3 +1,5 @@
#!/usr/bin/env python
import time
import math
@@ -12,7 +14,7 @@
for x in range(scrollphathd.width):
for y in range(scrollphathd.height):
offset += 1
color = int(64 * scale) * (offset % 2)
color = 0.25 * scale * (offset % 2)
scrollphathd.pixel(x, y, color)
scrollphathd.show()
View
@@ -1,3 +1,5 @@
#!/usr/bin/env python
import time
import signal
@@ -7,13 +9,7 @@
scrollphathd.rotate(180)
for char in range(len(font5x7.data)):
scrollphathd.draw_char(char * (1 + font5x7.width), 0, char, font=font5x7)
#scrollphathd.pixel(0,0,255)
#scrollphathd.pixel(0,1,255)
#scrollphathd.pixel(2,1,255)
#scrollphathd.pixel(22,1,255)
scrollphathd.draw_char(char * (3 + font5x7.width), 0, char, font=font5x7)
while True:
scrollphathd.show()
@@ -1,8 +1,10 @@
#!/usr/bin/env python
import time
import scrollphathd
scrollphathd.pixel(8,4,64)
scrollphathd.pixel(8,4,1.0)
try:
while True:
@@ -1,12 +1,14 @@
#!/usr/bin/env python
import time
import scrollphathd
scrollphathd.pixel(0,0,64)
scrollphathd.pixel(0,0,0.5)
try:
while True:
scrollphathd.scroll(-1,-1)
scrollphathd.scroll(1,1)
scrollphathd.show()
time.sleep(0.1)
except KeyboardInterrupt:
@@ -8,7 +8,11 @@
i2c = smbus.SMBus(1)
display = is31fl3731.ScrollPhatHD(i2c)
pixel = display.pixel
DISPLAY_HEIGHT = 7
DISPLAY_WIDTH = 17
pixel = display.set_pixel
set_pixel = display.set_pixel
show = display.show
scroll = display.scroll
fill = display.fill
Oops, something went wrong.

0 comments on commit 9317584

Please sign in to comment.