def cleanup(): import sys from luma.led_matrix.device import max7219 from luma.core.legacy import text, show_message device = set_long_device() show_message(device, 'Shutting down', fill='white', scroll_delay=0.05) sys.exit(0)
def activate(num): device = set_long_device() global cntr from luma.core.render import canvas from luma.core.legacy import text, show_message from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT player.load(numbers[num]) player.play() if cntr == 10: show_message(device, '10', fill="white", font=proportional(CP437_FONT), scroll_delay=0.08) else: with canvas(device) as draw: text(draw, (0, 0), str(num), fill="white", font=proportional(CP437_FONT)) cntr = (cntr + 1) % 11 import time while player.get_busy(): time.sleep(0.1)
def main(): msg = "Neopixel WS2812 LED Matrix Demo" show_message(device, msg, y_offset=-1, fill="green", font=proportional(TINY_FONT)) time.sleep(1) with canvas(device) as draw: text(draw, (0, -1), txt="A", fill="red", font=TINY_FONT) text(draw, (4, -1), txt="T", fill="green", font=TINY_FONT) time.sleep(1) with canvas(device) as draw: draw.line((0, 0, 0, device.height), fill="red") draw.line((1, 0, 1, device.height), fill="orange") draw.line((2, 0, 2, device.height), fill="yellow") draw.line((3, 0, 3, device.height), fill="green") draw.line((4, 0, 4, device.height), fill="blue") draw.line((5, 0, 5, device.height), fill="indigo") draw.line((6, 0, 6, device.height), fill="violet") draw.line((7, 0, 7, device.height), fill="white") time.sleep(4) for _ in range(5): for intensity in range(16): device.contrast(intensity * 16) time.sleep(0.1) device.contrast(0x80) time.sleep(1) gfx(device)
def demo(msg, n, block_orientation, rotate, provided_font): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0) print("***Created device***") # start demo print(msg) show_message(device, msg, fill="white", font=proportional(SINCLAIR_FONT), scroll_delay=0.07) with canvas(device) as draw: text(draw, (0, 1), chr(3), fill="white") #time.sleep(5) time.sleep(0.2) for _ in range(100): for intensity in range(16): device.contrast(intensity * 16) time.sleep(0.01) device.contrast(0x80) time.sleep(1)
def showMessage(lexStatus): n = 4 cascaded = 1 block_orientation = -90 rotate = 0 inreverse = 0 # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse) print("Created device") msg = lexStatus msg = re.sub(" +", " ", msg) print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.02)
def demo(): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=32, height=8, block_orientation=-90, rotate=2) # Create The Message msg = "Devscover Subscribers: " try: url = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UC7jBsNZf-wRyJkEmDKBrg2A&key=XXXX" res = urllib.request.urlopen(url) data = json.load(res) subs = data['items'][0]['statistics']['subscriberCount'] except: subs = 'cant load' msg_to_show = msg + subs # Start The Display print(msg_to_show) show_message(device, msg_to_show, fill="white", font=proportional(CP437_FONT)) time.sleep(1)
def main(cascaded, block_orientation, rotate): # create matrix device serial = spi(port=0, device=1, gpio=noop()) device = max7219(serial, cascaded=cascaded or 1, block_orientation=block_orientation, rotate=rotate or 0) # debugging purpose print("[-] Matrix initialized") # print Balrog Brewery on the matrix display msg = "Balrog Brewery" time.sleep(3) # print Brewing process initializing... msg1 = "Brewing process initializing..." # for debugging purpose print("[-] Printing: %s" % msg) show_message(device, msg, fill="white", font=proportional(CP437_FONT), scroll_delay=0.1) # for debugging purpose print("[-] Printing: %s" % msg1) show_message(device, msg1, fill="white", font=proportional(CP437_FONT), scroll_delay=0.1)
def showDepartures(d): hbf = [] turm = [] wedding = [] for bus in d['DepartureBoard']['Departure']: date_time_obj = datetime.strptime( bus.get('@rtDate', bus.get('@date')) + ' ' + bus.get('@rtTime', bus.get('@time')), '%Y-%m-%d %H:%M:%S') minutes = int((date_time_obj - datetime.now()).total_seconds() / 60) if (minutes > 1): if (bus['@direction'] == 'S+U Hauptbahnhof'): hbf.append(minutes) if (bus['@direction'] == 'S+U Jungfernheide'): wedding.append(minutes) if (bus['@direction'] == 'S+U Pankow'): turm.append(minutes) msg = 'hbf: ' + ", ".join( map(str, hbf[:2])) + ' ' + 'wedding: ' + ", ".join( map(str, wedding[:2])) + ' ' + 'turm: ' + ", ".join( map(str, turm[:2])) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.03)
def show(msg): show_message(device, msg, fill='white', font=proportional(CP437_FONT), scroll_delay=0.2) time.sleep(2)
def mostrar_mensaje(self, msg, delay=0.1, font=1): """Muestra mensaje en la matriz""" show_message(self.device, msg, fill="white", font=proportional(self.font[font]), scroll_delay=delay)
def get_time_and_temp(): print("get_Time_and_temp") # Get the current time displaystring = datetime.now().strftime('%A %I:%M %p') print(displaystring) try: #Try to grab a sensor reading. temperature_c = dhtDevice.temperature temperature_f = temperature_c * (9 / 5) + 32 humidity = dhtDevice.humidity tempstring = ' {0:0.1f}* {1:0.1f}%'.format(temperature_f, humidity) print(tempstring) displaystring = displaystring + tempstring except RuntimeError as error: # Errors happen fairly often, DHT's are hard to read, just keep going print(error.args[0]) time.sleep(0.5) except Exception as error: dhtDevice.exit() raise error print("Displaying message") show_message(device, displaystring, fill="white", font=proportional(LCD_FONT), scroll_delay=0.08)
def demo(msg, n, block_orientation, rotate, provided_font): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0) print("***Created device***") # start demo print(msg) show_message(device, msg, fill="white", font=proportional(SINCLAIR_FONT), scroll_delay=0.1) img_path = os.path.abspath( os.path.join(os.path.dirname(__file__), 'images', 'pi_logo.png')) logo = Image.open(img_path).convert("RGBA") #logo = Image.open(img_path) #fff = Image.new(logo.mode, logo.size, (255,) * 4) bg = Image.new("RGBA", device.size, "white") print("2nd try") img = logo.resize((16, 8)) posn = ((device.width - img.width) // 2, -1) bg.paste(img, posn) #fff.paste(img, posn) #device.display(fff.convert(device.mode)) device.display(bg.convert(device.mode)) time.sleep(5)
def scrollMessage(msg): print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.04)
def demo(n, block_orientation, rotate, inreverse): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=10, block_orientation=block_orientation, rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse) print("Enter message to display (Ctl-C to End): ") while (True): now = datetime.datetime.now() nowString = str(now.strftime('%m-%d-%Y %H:%M:%S')) msg = input() if msg == "": msg = nowString + " Hours: 8:88 AM - 5:00 PM \ Inspirational thoughtfor the day \ Covid-19 Safety Tips 1, 2, 3, ... \ Fun Fact 24: there are 30 days in September" print("Speed (1-10): ") speed = float(input()) delay = float(11.0 - speed) delay = float(delay / 10) print("Msg: ", msg, " New Speed: ", speed, " Delay: ", delay) print("Watch message board") show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=delay) time.sleep(10) print("Enter message to display (Ctl-C to End): ")
def demo(): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=1, block_orientation=0, rotate=0) print("Created device") msg = "Hello Kareem!" show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1) time.sleep(1) with canvas(device) as draw: text(draw, (0, 0), "A", fill="white") time.sleep(1) for _ in range(5): for intensity in range(16): device.contrast(intensity * 16) time.sleep(0.1) device.contrast(0x80) time.sleep(1)
def main(): # Setup for Banggood version of 4 x 8x8 LED Matrix (https://bit.ly/2Gywazb) serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=4, block_orientation=-90, blocks_arranged_in_reverse_order=True) device.contrast(16) # The time ascends from the abyss... animation(device, 8, 1) toggle = False # Toggle the second indicator every second while True: toggle = not toggle sec = datetime.now().second if sec == 59: # When we change minutes, animate the minute change minute_change(device) elif sec == 30: # Half-way through each minute, display the complete date/time, # animating the time display into and out of the abyss. full_msg = time.ctime() animation(device, 1, 8) show_message(device, full_msg, fill="white", font=proportional(CP437_FONT)) animation(device, 8, 1) else: # Do the following twice a second (so the seconds' indicator blips). # I'd optimize if I had to - but what's the point? # Even my Raspberry PI2 can do this at 4% of a single one of the 4 cores! hours = datetime.now().strftime('%H') minutes = datetime.now().strftime('%M') with canvas(device) as draw: text(draw, (0, 1), hours, fill="white", font=proportional(CP437_FONT)) text(draw, (15, 1), ":" if toggle else " ", fill="white", font=proportional(TINY_FONT)) text(draw, (17, 1), minutes, fill="white", font=proportional(CP437_FONT)) time.sleep(0.5)
def demo(n, block_orientation, rotate): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0) print("Created device") # start demo msg = "Hello AgilityContest" print(msg) show_message(device, msg, fill="white", font=proportional(CP437_FONT)) time.sleep(1) for x in xrange(5): msg = "Ring 1 Agility STD-G2 - Now running 28 " print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.05) with canvas(device) as draw: text(draw, (0, 0), " 28 ", fill="white") time.sleep(5)
def now_playing(): response = urllib2.urlopen( 'https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user='******'&api_key=' + LASTFM_API_KEY + '&limit=1') html = response.read() udata = html.decode("utf-8") asciidata = udata.encode("ascii", "ignore") import xml.etree.ElementTree as ET tree = ET.fromstring(asciidata) artist = tree.find('artist') artist = "unknown" track = "unknown" for elem in tree.iter(): if elem.tag == 'artist': if artist == "unknown": artist = elem.text if artist is None: artist = "???" if elem.tag == 'name': if track == "unknown": track = elem.text if track is None: track = "???" msg = "" + artist + " - " + track show_message(device, msg, fill="white", font=proportional(CP437_FONT)) time.sleep(1)
def vertical_scroll(device, msg): logging.debug("vertical scroll '{}'".format(msg)) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1)
def loop_time_and_temperature(temp, feels_like): rounded_temp = str(int(temp)) rounded_feels_like = str(int(feels_like)) feels_like_message = "Se simt ca" if language == "RO" else "Feels like" index = 0 while index < 20: index += 1 with canvas(virtual) as draw: current_time = datetime.now() offset = 4 if current_time.hour > 9: offset = 1 text(draw, (offset, 0), "{}:{}".format(str(current_time.hour), format_minute(current_time.minute)), fill="white", font=proportional(CP437_FONT)) sleep(5) with canvas(virtual) as draw: text(draw, (format_temperature_offset(temp), 0), "{}`C".format(rounded_temp), fill="white", font=proportional(CP437_FONT)) sleep(5) show_message(device, "{} {}`C".format(feels_like_message, rounded_feels_like), fill="white", font=proportional(LCD_FONT), scroll_delay=0.04)
def _clear(self): show_message( self.device, "", fill="white", font=proportional(LCD_FONT), scroll_delay=0) # write a blank message to clear the screen
def scrollText(text): if PI: show_message(device,text,fill="white", font=proportional(CP437_FONT)) else: titleSurf, titleRect = makeTextObjs(str(text), BASICFONT, TEXTCOLOR) titleRect.center = (int(WINDOWWIDTH / 2) - 3, int(WINDOWHEIGHT / 2) - 3) DISPLAYSURF.blit(titleSurf, titleRect)
def display(display_type, payload): if (display_type == 'input'): with canvas(device) as draw: text(draw, (0, 0), payload, fill='white', font=proportional(CP437_FONT)) elif (display_type == 'message'): if (payload != ''): show_message(device, payload, fill='white', font=proportional(CP437_FONT), y_offset=0, scroll_delay=0.03)
def main(): while True: lightLevel = readLight() msg = ("Poziom " + format(lightLevel, '.2f') + " lx") print("Light Level : " + format(lightLevel, '.2f') + " lx") show_message(device, msg, fill="white", font=proportional(LCD_FONT)) time.sleep(5)
def showtime(): # setup display serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=4, block_orientation=-90) device.contrast(4) device.persist = True # between 6 and 10 show trains present = datetime.now() if (present.hour >= 6 and present.hour <= 10): # show next three trains train_times = [tm.strftime('%H:%M') for tm in get_trains()[:3]] trains = ', '.join(train_times) show_message(device, ' Trains: ' + trains, fill="white", font=proportional(CP437_FONT)) weather = get_weather() show_message(device, ' Weather: ' + weather, fill="white", font=proportional(CP437_FONT)) show_message(device, read_sensor_data(), fill="white", font=proportional(CP437_FONT)) show_message(device, format_tides(), fill="white", font=proportional(CP437_FONT)) show_message(device, datetime.now().strftime("%a %d %b %Y"), fill="white", font=proportional(CP437_FONT)) minute_change(device)
def messagebar_scrolling(ctx): if ctx.message is None: ctx.message = input("Your message: ") logger(ctx.message, "scrolling") if system: label = 'Displaying' fill_char = click.style('#', fg='green') empty_char = click.style('-', fg='white', dim=True) length = 100 print('Message "' + ctx.message + '" sent successfully.') with click.progressbar(label=label, length=length, fill_char=fill_char, empty_char=empty_char, show_eta=False) as bar: bar.update(0) for letter in range(ctx.count): show_message(device, ctx.message, fill='white', font=proportional(TINY_FONT), scroll_delay=0.06) bar.update(length / ctx.count) else: print('Message "' + ctx.message + '" has been logged successfully.')
def display_time(): global displaying_code, prev_time_of_day displaying_code = False daylight_saving_time = datetime.now() + timedelta( hours=1) # change hour to zero for winter time time_of_day = daylight_saving_time.strftime('%H:%M') if time_of_day == prev_time_of_day: return else: logger.info( "time changed: time_of_day: {} prev_time_of_day: {}".format( time_of_day, prev_time_of_day)) prev_time_of_day = time_of_day if display_mode == 'static': with canvas(device) as draw: text(draw, (1, 0), time_of_day, fill="white", font=proportional(CP437_FONT)) else: show_message(device, time_of_day, fill="white", font=proportional(CP437_FONT))
def text_display(self): """ """ self.get_github_api() with canvas(self.virtual) as led_canvas: show_message(self.device, self.led_attrs['message'], fill="red", font=proportional(SINCLAIR_FONT)) for repo in self.git_repos: show_message(self.device, repo, fill="red", font=proportional(LCD_FONT)) time.sleep(1)
def scroll_str(s, device, scroll_delay=0.03): with canvas(device) as draw: device.contrast(8) show_message(device, s, fill="white", font=proportional(LCD_FONT), scroll_delay=scroll_delay)
def demo(n, block_orientation, rotate, msg): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0) show_message(device, msg, fill="white", font=proportional(LCD_FONT))
def show_time(): import time t = time.localtime(time.time()) time_string = time.strftime(" * %a, %b %d - %I:%M * ", t) show_message(device, time_string, fill="white", font=proportional(LCD_FONT))
def hofok(n, block_orientation, rotate): serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=8, block_orientation=-90 , rotate=rotate) print("Hofok") msg = "Muhahhaa." print(msg) show_message(device, msg, fill="white", font=proportional(CP437_FONT)) time.sleep(1)
def demo(n, block_orientation, rotate, inreverse): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse) print("Created device") # start demo msg = "MAX7219 LED Matrix Demo" print(msg) show_message(device, msg, fill="white", font=proportional(CP437_FONT)) time.sleep(1) msg = "Fast scrolling: Lorem ipsum dolor sit amet, consectetur adipiscing\ elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut\ enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut\ aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in\ voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint\ occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit\ anim id est laborum." msg = re.sub(" +", " ", msg) print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0) msg = "Slow scrolling: The quick brown fox jumps over the lazy dog" print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1) print("Vertical scrolling") words = [ "Victor", "Echo", "Romeo", "Tango", "India", "Charlie", "Alpha", "Lima", " ", "Sierra", "Charlie", "Romeo", "Oscar", "Lima", "Lima", "India", "November", "Golf", " " ] virtual = viewport(device, width=device.width, height=len(words) * 8) with canvas(virtual) as draw: for i, word in enumerate(words): text(draw, (0, i * 8), word, fill="white", font=proportional(CP437_FONT)) for i in range(virtual.height - device.height): virtual.set_position((0, i)) time.sleep(0.05) msg = "Brightness" print(msg) show_message(device, msg, fill="white") time.sleep(1) with canvas(device) as draw: text(draw, (0, 0), "A", fill="white") time.sleep(1) for _ in range(5): for intensity in range(16): device.contrast(intensity * 16) time.sleep(0.1) device.contrast(0x80) time.sleep(1) msg = "Alternative font!" print(msg) show_message(device, msg, fill="white", font=SINCLAIR_FONT) time.sleep(1) msg = "Proportional font - characters are squeezed together!" print(msg) show_message(device, msg, fill="white", font=proportional(SINCLAIR_FONT)) # http://www.squaregear.net/fonts/tiny.shtml time.sleep(1) msg = "Tiny is, I believe, the smallest possible font \ (in pixel size). It stands at a lofty four pixels \ tall (five if you count descenders), yet it still \ contains all the printable ASCII characters." msg = re.sub(" +", " ", msg) print(msg) show_message(device, msg, fill="white", font=proportional(TINY_FONT)) time.sleep(1) msg = "CP437 Characters" print(msg) show_message(device, msg) time.sleep(1) for x in range(256): with canvas(device) as draw: text(draw, (0, 0), chr(x), fill="white") time.sleep(0.1)
def displayScroll(msg): # print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.03)
import re import time import argparse from luma.led_matrix.device import max7219 from luma.core.interface.serial import spi, noop from luma.core.render import canvas from luma.core.virtual import viewport from luma.core.legacy import text, show_message from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=4, block_orientation=-90) print("Created device") msg = "Slow scrolling: The quick brown fox jumps over the lazy dog" print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1)
def show_text_message(self,data): msg = data.data print(msg) show_message(self.device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1)