Created
March 25, 2019 10:32
-
-
Save thomasw-mitutoyo-ctl/89d1da16161325a8b1282d519ca95a4d to your computer and use it in GitHub Desktop.
luma test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
from luma.core.render import canvas | |
from luma.led_matrix.device import ws2812 | |
''' | |
Pin connections: | |
VCC (red): 5 Volt, don't use Raspberry's power, because it may draw a lot of current | |
DIN (green): Pin 12, GPIO18 | |
GND (white): Common ground | |
''' | |
def mapping(): | |
result = [] | |
for block in range(8): # 0 ... 8 | |
for y in range(0,56+1,8): | |
result.append(block+y) | |
for y in range(128-8,128-64-1,-8): | |
result.append(block + y) | |
for y in range(128,128+56+1,8): | |
result.append(block + y) | |
for y in range(256-8,256-64-1,-8): | |
result.append(block + y) | |
return result | |
def ws2812draw(): | |
device = ws2812(width=32, height=8, rotate=0, mapping=mapping()) | |
device.contrast(255) | |
with canvas(device) as draw: | |
draw.rectangle(device.bounding_box, outline="green", fill="blue") | |
draw.line((0, 0, 8, device.height), fill="red") | |
draw.line((1, 0, 1, device.height), fill="orange") | |
draw.line((0, 0, 0, 0), fill="white") | |
draw.line((0, 7, 0, 7), fill="white") | |
sleep(3) | |
for c in range(0, 255, 8): | |
device.contrast(c) | |
sleep(0.2) | |
sleep(3) | |
device.cleanup() | |
del device | |
def ws2812linear(width: int, height: int, mapping=None): | |
device = ws2812(width=width, height=height, rotate=0, mapping=mapping) | |
device.contrast(32) | |
for w in range(width): | |
for h in range(height): | |
with canvas(device) as draw: | |
draw.point((w, h), fill="white") | |
sleep(0.05) | |
sleep(3) | |
device.cleanup() | |
del device | |
print(mapping()) | |
print("32x8 ...") | |
#ws2812draw() | |
print("256x1 ...") | |
#ws2812linear(256, 1) | |
#ws2812linear(32, 8) | |
ws2812linear(32, 8, mapping()) | |
print("end.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment