Compare commits
5 Commits
master
...
vp_develop
Author | SHA1 | Date |
---|---|---|
Vincent Presciutti | 421c4acf32 | 4 years ago |
Vincent Presciutti | 4591f47b23 | 4 years ago |
Vincent Presciutti | 4cee63ed87 | 4 years ago |
Vincent Presciutti | a431695386 | 4 years ago |
Vincent Presciutti | 1cbd7db3ed | 4 years ago |
@ -0,0 +1,67 @@
|
|||||||
|
# Library containing the class interface to create a new LED light display.
|
||||||
|
|
||||||
|
import board
|
||||||
|
import neopixel
|
||||||
|
from PIL import Image
|
||||||
|
from adafruit_pixel_framebuf import PixelFramebuffer
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
class LightDisplay:
|
||||||
|
def __init__(self, x=8, y=8, orientation="vertical", color="red", speed=1):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.orientation = orientation
|
||||||
|
self.color = color
|
||||||
|
self.speed = speed
|
||||||
|
|
||||||
|
def display(self, message="Hello World"):
|
||||||
|
# Init variables
|
||||||
|
gpio_pin = board.D18
|
||||||
|
pixel_width = self.x
|
||||||
|
scroll_width = pixel_width + 1
|
||||||
|
pixel_height = self.y
|
||||||
|
scroll_height = pixel_height + 1
|
||||||
|
pixel_max = pixel_width * pixel_height - 1
|
||||||
|
led_message = self.message
|
||||||
|
|
||||||
|
# Process arguments
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Create NeoPixel object with appropriate configuration.
|
||||||
|
neo_pixel = neopixel.NeoPixel(gpio_pin, pixel_width * pixel_height, brightness=0.1, auto_write=False)
|
||||||
|
|
||||||
|
#Create PixelFramebuffer object with appropriate configuration.
|
||||||
|
pixel_framebuf = PixelFramebuffer(neo_pixel, pixel_width, pixel_height, reverse_x=True,alternating=True)
|
||||||
|
|
||||||
|
print ('Press Ctrl-C to quit.')
|
||||||
|
|
||||||
|
if not args.clear:
|
||||||
|
print('Use "-c" argument to clear LEDs on exit')
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
led_message_len = len(led_message)
|
||||||
|
led_message_scroll_height = led_message_len * 16
|
||||||
|
|
||||||
|
for led_scroll in range(0, led_message_scroll_height , 1):
|
||||||
|
led_char_counter = 1
|
||||||
|
pixel_framebuf.fill(0x000000)
|
||||||
|
# pixel_framebuf.display()
|
||||||
|
|
||||||
|
for led_char in led_message:
|
||||||
|
led_char_spacing = 8 * led_char_counter
|
||||||
|
led_char_pos = pixel_height - led_scroll + led_char_spacing
|
||||||
|
pixel_framebuf.text(led_char, 0, led_char_pos , 0x00FF00)
|
||||||
|
led_char_counter += 1
|
||||||
|
|
||||||
|
pixel_framebuf.display()
|
||||||
|
time.sleep(25/500)
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
if args.clear:
|
||||||
|
neo_pixel.deinit()
|
||||||
|
|
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from led_display import LightDisplay
|
||||||
|
|
||||||
|
def main():
|
||||||
|
led_test = LightDisplay(8, 16, "blue", 2)
|
||||||
|
print(led_test.color)
|
||||||
|
print(led_test.x)
|
||||||
|
print(led_test.y)
|
||||||
|
print(led_test.speed + '\n\n\n')
|
||||||
|
led_test.display("Print this message")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in new issue