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(w, h, block_orientation, rotate): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=w, height=h, rotate=rotate, block_orientation=block_orientation) print("Created device") with canvas(device) as draw: draw.rectangle(device.bounding_box, outline="white") text(draw, (2, 2), "Hello", fill="white", font=proportional(LCD_FONT)) text(draw, (2, 10), "World", fill="white", font=proportional(LCD_FONT)) time.sleep(300)
def test_reversed_max7219(): device = max7219(serial, cascaded=4, blocks_arranged_in_reverse_order=True) serial.reset_mock() with canvas(device) as draw: draw.rectangle((0, 0, 15, 3), outline="white") serial.data.assert_has_calls([ call([1, 15, 1, 9, 1, 0, 1, 0]), call([2, 9, 2, 9, 2, 0, 2, 0]), call([3, 9, 3, 9, 3, 0, 3, 0]), call([4, 9, 4, 9, 4, 0, 4, 0]), call([5, 9, 5, 9, 5, 0, 5, 0]), call([6, 9, 6, 9, 6, 0, 6, 0]), call([7, 9, 7, 9, 7, 0, 7, 0]), call([8, 9, 8, 15, 8, 0, 8, 0]) ])
def test_display_16x8(): device = max7219(serial, cascaded=2) serial.reset_mock() with canvas(device) as draw: draw.rectangle(device.bounding_box, outline="white") serial.data.assert_has_calls([ call([1, 0x81, 1, 0xFF]), call([2, 0x81, 2, 0x81]), call([3, 0x81, 3, 0x81]), call([4, 0x81, 4, 0x81]), call([5, 0x81, 5, 0x81]), call([6, 0x81, 6, 0x81]), call([7, 0x81, 7, 0x81]), call([8, 0xFF, 8, 0x81]) ])
def demo(n, block_orientation, rotate, x): # 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) device.contrast(16) time.sleep(1) for screen_drawing in vent: for i in range(5): with canvas(device) as draw: for pos in bin_to_position(screen_drawing): draw.point(pos, fill="white") time.sleep(0.1)
def test_display_16x16(): device = max7219(serial, width=16, height=16) serial.reset_mock() with canvas(device) as draw: draw.rectangle(device.bounding_box, outline="white") serial.data.assert_has_calls([ call([1, 0x80, 1, 0xFF, 1, 0x01, 1, 0xFF]), call([2, 0x80, 2, 0x80, 2, 0x01, 2, 0x01]), call([3, 0x80, 3, 0x80, 3, 0x01, 3, 0x01]), call([4, 0x80, 4, 0x80, 4, 0x01, 4, 0x01]), call([5, 0x80, 5, 0x80, 5, 0x01, 5, 0x01]), call([6, 0x80, 6, 0x80, 6, 0x01, 6, 0x01]), call([7, 0x80, 7, 0x80, 7, 0x01, 7, 0x01]), call([8, 0xFF, 8, 0x80, 8, 0xFF, 8, 0x01]) ])
def test_display_16x8(): device = max7219(serial, cascaded=2) serial.reset_mock() with canvas(device) as draw: draw.rectangle(device.bounding_box, outline="white") serial.data.assert_has_calls([ call([1, 0x81, 1, 0xFF]), call([2, 0x81, 2, 0x81]), call([3, 0x81, 3, 0x81]), call([4, 0x81, 4, 0x81]), call([5, 0x81, 5, 0x81]), call([6, 0x81, 6, 0x81]), call([7, 0x81, 7, 0x81]), call([8, 0xFF, 8, 0x81]) ])
def test_display_16x16(): device = max7219(serial, width=16, height=16) serial.reset_mock() with canvas(device) as draw: draw.rectangle(device.bounding_box, outline="white") serial.data.assert_has_calls([ call([1, 0x80, 1, 0xFF, 1, 0x01, 1, 0xFF]), call([2, 0x80, 2, 0x80, 2, 0x01, 2, 0x01]), call([3, 0x80, 3, 0x80, 3, 0x01, 3, 0x01]), call([4, 0x80, 4, 0x80, 4, 0x01, 4, 0x01]), call([5, 0x80, 5, 0x80, 5, 0x01, 5, 0x01]), call([6, 0x80, 6, 0x80, 6, 0x01, 6, 0x01]), call([7, 0x80, 7, 0x80, 7, 0x01, 7, 0x01]), call([8, 0xFF, 8, 0x80, 8, 0xFF, 8, 0x01]) ])
def test_normal_alignment(): device = max7219(serial, cascaded=2, block_orientation=0) serial.reset_mock() with canvas(device) as draw: draw.rectangle((0, 0, 15, 3), outline="white") serial.data.assert_has_calls([ call([1, 0x09, 1, 0x0F]), call([2, 0x09, 2, 0x09]), call([3, 0x09, 3, 0x09]), call([4, 0x09, 4, 0x09]), call([5, 0x09, 5, 0x09]), call([6, 0x09, 6, 0x09]), call([7, 0x09, 7, 0x09]), call([8, 0x0F, 8, 0x09]) ])
def test_block_realignment_plus180(): device = max7219(serial, cascaded=2, block_orientation=180) serial.reset_mock() with canvas(device) as draw: draw.rectangle((0, 0, 15, 3), outline="white") serial.data.assert_has_calls([ call([1, 0xF0, 1, 0x90]), call([2, 0x90, 2, 0x90]), call([3, 0x90, 3, 0x90]), call([4, 0x90, 4, 0x90]), call([5, 0x90, 5, 0x90]), call([6, 0x90, 6, 0x90]), call([7, 0x90, 7, 0x90]), call([8, 0x90, 8, 0xF0]) ])
def test_reversed_max7219(): device = max7219(serial, cascaded=4, blocks_arranged_in_reverse_order=True) serial.reset_mock() with canvas(device) as draw: draw.rectangle((0, 0, 15, 3), outline="white") serial.data.assert_has_calls([ call([1, 15, 1, 9, 1, 0, 1, 0]), call([2, 9, 2, 9, 2, 0, 2, 0]), call([3, 9, 3, 9, 3, 0, 3, 0]), call([4, 9, 4, 9, 4, 0, 4, 0]), call([5, 9, 5, 9, 5, 0, 5, 0]), call([6, 9, 6, 9, 6, 0, 6, 0]), call([7, 9, 7, 9, 7, 0, 7, 0]), call([8, 9, 8, 15, 8, 0, 8, 0]) ])
def demo(n, block_orientation): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=2) device.contrast(0) while True: now = time.localtime() with canvas(device) as draw: text(draw, (0,0), "{:02}:{:02}".format(now.tm_hour, now.tm_min), fill="white", font=proportional(CP437_FONT)) if now.tm_hour < 6 or now.tm_hour > 22: device.hide() device.clear() sleep(60*(60 - now.tm_min)) device.show()
def test_block_realignment_plus180(): device = max7219(serial, cascaded=2, block_orientation=180) serial.reset_mock() with canvas(device) as draw: draw.rectangle((0, 0, 15, 3), outline="white") serial.data.assert_has_calls([ call([1, 0xF0, 1, 0x90]), call([2, 0x90, 2, 0x90]), call([3, 0x90, 3, 0x90]), call([4, 0x90, 4, 0x90]), call([5, 0x90, 5, 0x90]), call([6, 0x90, 6, 0x90]), call([7, 0x90, 7, 0x90]), call([8, 0x90, 8, 0xF0]) ])
def test_normal_alignment(): device = max7219(serial, cascaded=2, block_orientation=0) serial.reset_mock() with canvas(device) as draw: draw.rectangle((0, 0, 15, 3), outline="white") serial.data.assert_has_calls([ call([1, 0x09, 1, 0x0F]), call([2, 0x09, 2, 0x09]), call([3, 0x09, 3, 0x09]), call([4, 0x09, 4, 0x09]), call([5, 0x09, 5, 0x09]), call([6, 0x09, 6, 0x09]), call([7, 0x09, 7, 0x09]), call([8, 0x0F, 8, 0x09]) ])
def update_times(): global off_t, on_t, off_str, on_str schedule.clear('relays') #Clear schedules tagged with 'relays' to prevent doubles p = Popen("php times_output_071.php", shell=True, stdout=PIPE) #Run PHP script needs shell=True to run. logging.info('update_times() Script activated') getOutput = p.stdout.read().decode('ascii') #outputs in bytes, needs to be decoded. #Extract twilight flavours nautical = getOutput[4:14] astronomical = getOutput[18:28] civil = getOutput[32:42] theTimes = astronomical #Select which flavour #Chop up data as integers off_H = int(theTimes[0:2]) off_M = int(theTimes[3:5]) on_H = int(theTimes[5:7]) on_M = int(theTimes[8:10]) disp_times = theTimes[0:2]+"."+theTimes[3:5]+theTimes[5:7]+"."+theTimes[8:10] #combine extracted integers as time for init check off_t = datetime.time(hour = off_H, minute = off_M) on_t = datetime.time(hour = on_H, minute = on_M) #extract as string for schedules and logging off_str = theTimes[0:5] on_str = theTimes[5:10] #print(theTimes) #print(off_str) #print(on_str) #exit() # create seven segment device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=1) seg = sevensegment(device) seg.device.contrast(0x00) seg.text = disp_times #Set relay schedules schedule.every().day.at(off_str).do(switch_off, off_at = off_str).tag('relays') schedule.every().day.at(on_str).do(switch_on, on_at = on_str).tag('relays') theLog = 'Times updated. Switch on at: ' + on_str + ' Switch off at: ' + off_str logging.info(theLog)
def sad(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) device.contrast(20) print("Created device") while (True): with canvas(device) as draw: draw.point((0, 2), fill="white") draw.point((0, 3), fill="white") draw.point((0, 4), fill="white") draw.point((0, 5), fill="white") draw.point((2, 0), fill="white") draw.point((3, 0), fill="white") draw.point((4, 0), fill="white") draw.point((5, 0), fill="white") draw.point((2, 7), fill="white") draw.point((3, 7), fill="white") draw.point((4, 7), fill="white") draw.point((5, 7), fill="white") draw.point((7, 2), fill="white") draw.point((7, 3), fill="white") draw.point((7, 4), fill="white") draw.point((7, 5), fill="white") draw.point((1, 1), fill="white") draw.point((6, 1), fill="white") draw.point((6, 6), fill="white") draw.point((1, 6), fill="white") draw.point((2, 2), fill="white") draw.point((5, 2), fill="white") draw.point((2, 5), fill="white") draw.point((5, 5), fill="white") draw.point((3, 4), fill="white") draw.point((4, 4), fill="white")
def main(): # create seven segment device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=1) seg = sevensegment(device) print('Simple text...') for _ in range(8): seg.text = "HELLO" time.sleep(0.6) seg.text = " GOODBYE" time.sleep(0.6) # Digit slicing print("Digit slicing") seg.text = "_" * seg.device.width time.sleep(1.0) for i, ch in enumerate([9, 8, 7, 6, 5, 4, 3, 2]): seg.text[i] = str(ch) time.sleep(0.6) for i in range(len(seg.text)): del seg.text[0] time.sleep(0.6) # Scrolling Alphabet Text print('Scrolling alphabet text...') show_message_vp(device, "HELLO EVERYONE!") show_message_vp(device, "PI is 3.14159 ... ") show_message_vp(device, "IP is 127.0.0.1 ... ") show_message_alt(seg, "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ") # Digit futzing date(seg) time.sleep(5) clock(seg, seconds=10) # Brightness print('Brightness...') for x in range(5): for intensity in range(16): seg.device.contrast(intensity * 16) time.sleep(0.1) device.contrast(0x7F)
def main(): # create seven segment device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=1) seg = sevensegment(device) print('Simple text...') for _ in range(8): seg.text = "HELLO" time.sleep(0.6) seg.text = " GOODBYE" time.sleep(0.6) # Digit slicing print("Digit slicing") seg.text = "_" * seg.device.width time.sleep(1.0) for i, ch in enumerate([9, 8, 7, 6, 5, 4, 3, 2]): seg.text[i] = str(ch) time.sleep(0.6) for i in range(len(seg.text)): del seg.text[0] time.sleep(0.6) # Scrolling Alphabet Text print('Scrolling alphabet text...') show_message_vp(device, "HELLO EVERYONE!") show_message_vp(device, "PI is 3.14159 ... ") show_message_vp(device, "IP is 127.0.0.1 ... ") show_message_alt(seg, "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ") # Digit futzing date(seg) time.sleep(5) clock(seg, seconds=10) # Brightness print('Brightness...') for x in range(5): for intensity in range(16): seg.device.contrast(intensity * 16) time.sleep(0.1) device.contrast(0x7F)
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(device.bounding_box) print("Created device") time.sleep(1) device.contrast(2) while True: usedNum = randrange(0,6) if usedNum < 2: goodCondition(device) elif usedNum < 4: notsogoodCondition(device) else: badCondition(device)
def test_init_16x8(): device = max7219(serial, width=16, height=8) assert device.cascaded == 2 serial.data.assert_has_calls([ call([11, 7, 11, 7]), call([9, 0, 9, 0]), call([15, 0, 15, 0]), call([10, 7, 10, 7]), call([1, 0, 1, 0]), call([2, 0, 2, 0]), call([3, 0, 3, 0]), call([4, 0, 4, 0]), call([5, 0, 5, 0]), call([6, 0, 6, 0]), call([7, 0, 7, 0]), call([8, 0, 8, 0]), call([12, 1, 12, 1]) ])
def test_init_8x8(): device = max7219(serial) assert device.cascaded == 1 serial.data.assert_has_calls([ call([11, 7]), call([9, 0]), call([15, 0]), call([10, 7]), call([1, 0]), call([2, 0]), call([3, 0]), call([4, 0]), call([5, 0]), call([6, 0]), call([7, 0]), call([8, 0]), call([12, 1]) ])
def get_device(width, height): """ Devuelve un dispositivo. En caso de que la matriz esté conectada devuelve la misma, en caso contrario devuelve un dispositivo de simulación de pygame. """ try: serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=width, height=height, block_orientation=-90) except DeviceNotFoundError: device = pygame(width=width, height=height, mode="1", transform='led_matrix') return device
def __init__(self): self.serial = spi(port=0, device=0, gpio=noop()) self.device = max7219(self.serial, width=32, height=8, block_orientation=-90) self.device.contrast(5) self.virtual = viewport(self.device, width=32, height=16) self.sensor_val = 0 # Connect sensor topic self.sensor_topic = "/boxID_activation" # self.sensor_sub = rospy.Subscriber(self.sensor_topic, Int32, self.callback) self.sensor_sub = rospy.Subscriber(self.sensor_topic, Int32) # Allow up to one second to connection rospy.sleep(1)
def run(n, block_orientation, rotate, inreverse): serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, width=16, height=8, block_orientation=block_orientation, rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse) virtual = viewport(device, width=16, height=16) device.contrast(16) while True: data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes print "received message:", data with canvas(virtual) as draw: text(draw, (0, 0), data, fill="white", font=proportional(LCD_FONT))
def __init__(self, numero_matrices=1, orientacion=0, rotacion=0, ancho=8, alto=8): """Inicializador de la clase matriz""" #fuentes que se pueden elegir self.font = [CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT] #Inicializar la matriz: identificar el puerto self.serial = spi(port=0, device=0, gpio=noop()) #Crear un objeto matriz self.device = max7219(self.serial, width=ancho, height=alto, cascaded=numero_matrices, rotate=rotacion)
def test_init_8x8(): device = max7219(serial) assert device.cascaded == 1 serial.data.assert_has_calls([ call([11, 7]), call([9, 0]), call([15, 0]), call([10, 7]), call([1, 0]), call([2, 0]), call([3, 0]), call([4, 0]), call([5, 0]), call([6, 0]), call([7, 0]), call([8, 0]), call([12, 1]) ])
def sub_counter(): #create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=32, height=8, block_orientation=-90, rotate=2, contrast=1) try: url = "{API_URL_FOR_YOUR_SOCIAL_MEDIA_PROFILE_GOES_HERE}" res = urllib.request.urlopen(url) data = json.load(res) subs = data['items'][0]['statistics']['subscriberCount'] except: subs='err' #draw the display with canvas(device) as draw: print(subs) text(draw, (2, 1), subs, fill="white", font=proportional(CP437_FONT))
def test_init_16x8(): device = max7219(serial, width=16, height=8) assert device.cascaded == 2 serial.data.assert_has_calls([ call([11, 7, 11, 7]), call([9, 0, 9, 0]), call([15, 0, 15, 0]), call([10, 7, 10, 7]), call([1, 0, 1, 0]), call([2, 0, 2, 0]), call([3, 0, 3, 0]), call([4, 0, 4, 0]), call([5, 0, 5, 0]), call([6, 0, 6, 0]), call([7, 0, 7, 0]), call([8, 0, 8, 0]), call([12, 1, 12, 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 hello world on the matrix display msg = "Hello World" # debugging purpose print("[-] Printing: {}".format(msg)) show_message(device, msg, fill="white", font=proportional(CP437_FONT), scroll_delay=0.1)
def display(msg): serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, height=16, width=96, block_orientation=-90) myFont = ImageFont.truetype("pixelmix.ttf", 16) #msg=" Hello World!!!" virtual = viewport(device, width=myFont.getsize(msg)[0] + 192, height=device.height) #192 = 96 *2 with canvas(virtual) as draw: draw.rectangle(device.bounding_box, outline="black", fill="black") draw.text((96, -1), msg, fill="white", font=myFont) try: for x in range(virtual.width - device.width): virtual.set_position((x, 0)) time.sleep(0.1) except KeyboardInterrupt: pass
def LEDMatrix(cascaded, block_orientation, rotate, msg): # 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("%s" % msg) # print hello world on the matrix display msg = "." # debugging purpose # print("%s" % msg) show_message(device, msg, fill="white", font=proportional(CP437_FONT), scroll_delay=0.1)
def drawRoute(n, block_orientation, rotate, inreverse, routeJson): # this method parses the routeJson and enables leds in # led matrix for 2d coordinates in json data # 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) device = max7219(serial, width=32, height=8, block_orientation=block_orientation, rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse) print("Created device") print(routeJson) route = json.loads(routeJson) # enable leds by using draw.point method with canvas(device) as draw: for hold in route: print("hold pos: " + str(hold["x"]) + " " + str(hold["y"])) draw.point((hold["x"],hold["y"]), fill="white")
def start(self): self.logger.info("Starting") if self.mode == 'emulator': from luma.emulator.device import pygame self.device = pygame(self.width, self.height, 0, '1', "led_matrix") elif self.mode == 'max7219': from luma.core.interface.serial import spi, noop from luma.led_matrix.device import max7219 serial = spi(port=1, device=0, gpio=noop()) self.device = max7219(serial, self.width, self.height, block_orientation=self.config['orientation']) self.device.contrast(self.config.get('contrast', 0) << 4) else: raise Exception("Unsupported mode") self.logger.info("Started")
def demo(block_orientation, rotate): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=16, height=8, block_orientation=block_orientation, rotate=rotate or 0) print("Created device") with canvas(device) as draw: text(draw, (0, 0), "DA", 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)
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) '''heart_shape = np.array( [ [ 0, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 1, 1, 0, 0, 1, 1, 0 ], [ 1, 1, 1, 1, 1, 1, 1, 1 ], [ 1, 1, 1, 1, 1, 1, 1, 1 ], [ 0, 1, 1, 1, 1, 1, 1, 0 ], [ 0, 0, 1, 1, 1, 1, 0, 0 ], [ 0, 0, 0, 1, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0, 0 ], ] ) with canvas(device) as draw: text(draw, (2, 2), "Hello", fill="white", font=proportional(LCD_FONT)) #legacy.text(draw, (-2,-2), ".", fill="white", font=proportional(CP437_FONT)) time.sleep(2) ''' with canvas(device) as draw: text(draw, (0, 1), chr(3), fill="white") #time.sleep(5) time.sleep(1) for _ in range(50): for intensity in range(16): device.contrast(intensity * 16) time.sleep(0.01) device.contrast(0x30) time.sleep(1)
def loop( n, block_orientation, rotate, inreverse, time_format="%H:%M", no_zero=True, font=font, ): print("Initializing device") # 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("Starting infinite loop") while True: now = datetime.datetime.now() msg_time = now.strftime(time_format) # convert first zero to space, notice that %-H produces hours without spaces if no_zero and (msg_time[0] == "0"): msg = " " + msg_time[1:] else: msg = msg_time # draw each letter separately, to allow to have colon sign # still, hours are more squeezed than minutes for readibility with canvas(device) as draw: text(draw, (0, 0), msg[0], fill="white", font=proportional(font)) text(draw, (3, 0), msg[1], fill="white", font=proportional(font)) text(draw, (7, 0), msg[2], fill="white", font=proportional(font)) text(draw, (9, 0), msg[3], fill="white", font=proportional(font)) text(draw, (13, 0), msg[4], fill="white", font=proportional(font)) device.contrast(contrast) time.sleep(1)
def __init__(self,json_settings=None,id=None,fps=AreaUpdate_Default.SIGN_FPS,areas=[],muted=True,\ port=0,device=0,cascaded=4,block_orientation=-90,blocks_arranged_in_reverse_order=False,contrast=128, json_section="max7219"): # setup the hardware device max7219_device = None p = port d = device c = cascaded bo = block_orientation bro = blocks_arranged_in_reverse_order b = contrast if json_settings is not None and json_section in json_settings: display_settings = json_settings[json_section] if "port" in display_settings: p = int(display_settings["port"]) if "device" in display_settings: d = int(display_settings["device"]) if "cascaded" in display_settings: c = int(display_settings["cascaded"]) if "block_orientation" in display_settings: bo = int(display_settings["block_orientation"]) if "blocks_arranged_in_reverse_order" in display_settings: bro = bool( display_settings["blocks_arranged_in_reverse_order"]) if "contrast" in display_settings: b = int(display_settings["contrast"]) serial = spi(port=p, device=d, gpio=noop()) max7219_device = max7219(serial, cascaded=c, block_orientation=bo, blocks_arranged_in_reverse_order=bro) max7219_device.contrast(b) super().__init__(json_settings=json_settings, id=id, fps=fps, areas=areas, muted=muted, device=max7219_device)
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 msg3 = "Start milling..." # for debugging purpose print("[-] Printing: %s" % msg3) show_message(device, msg3, fill="white", font=proportional(CP437_FONT), scroll_delay=0.1)
def __init__(self): global level logger.debug('__init__') threading.Thread.__init__(self) if platform.machine().startswith('arm'): # create matrix7219 device serial = spi(port=0, device=1, gpio=noop()) self.device = max7219(serial, cascaded=4, block_orientation=-90) else: # create emulator device self.device = pygame(width=32, height=8, rotate=0, mode='RGB', transform='led_matrix', scale=2, frame_rate=60) self.device.contrast(level)
def demo(n, block_orientation): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation) print("Created device") print("Drawing on Canvas stage 1") #with canvas(device) as draw: for abc in range(1): with canvas(device) as draw: for y in range(8): for x in range(8): #print("Point " + str(x) + " " + str(y)) draw.point((x, y ), randint(0,1)) time.sleep(0.1) print("Finished Drawing on Canvas stage 2")
def main(): try: logging.basicConfig( filename="log_tfl.txt", format="%(asctime)s %(levelname)s %(name)s: %(message)s", level=logging.DEBUG) serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=1) seg = sevensegment(device) pir = MotionSensor(PIR_GPIO) daemon_thread = threading.Thread(target=daemon, args=( seg, pir, )) #daemon_thread.setDaemon(True) logging.debug("Starting daemon") daemon_thread.start() download(0) except Exception as ex: logging.exception(ex) raise
def __init__(self): rospy.init_node('display') self.rate=100 self.serial = spi(port=0, device=0, gpio=noop()) self.device = max7219(self.serial, cascaded=1, block_orientation=0) self.shift_counter=0 self.peak_counter=3 self.processing_count=0 self.show_grec_bool=False print("Created device") # Init Subscribers rospy.Subscriber("disp/text", String, self.show_text_message) rospy.Subscriber("disp/emotion", disp_emotion, self.emotion) rospy.Subscriber("disp/action", disp_action, self.action) # Init services s_dis = rospy.Service('stop_disp', Empty, self.stop_disp) i_proc = rospy.Service('inc_proc', Empty, self.increase_processing_count) dec_proc = rospy.Service('dec_proc', Empty, self.decrease_processing_count) grec = rospy.Service('show_grec', Empty, self.show_grec) lrec = rospy.Service('show_lrec', Empty, self.show_lrec) self.display_anim=False
from luma.core.interface.serial import spi, noop from luma.core.render import canvas from luma.led_matrix.device import max7219 from time import sleep serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial) #font = ImageFont.truetype("examples/pixelmix.ttf", 8) #with canvas(device) as draw: # draw.rectangle(device.bounding_box, outline="white", fill="black") #sleep(2) import random from PIL import Image image = Image.new('1', (8, 8)) while True: x = random.randint(0,7) y = random.randint(0,7) image.putpixel((x, y), 1) device.display(image) sleep(.05) image.putpixel((x, y), 0) device.display(image)
# luma.led_matrix libuary - Richard Hull # https://github.com/rm-hull/luma.led_matrix # from luma.core.interface.serial import spi, noop from luma.core.render import canvas from luma.led_matrix.device import max7219 from time import sleep #----------------------------------------------------- rotation = 0 #set global rotate (0,1,2,3) #----------------------------------------------------- serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, rotate = rotation) import math from PIL import Image # English Class class DMS_wrdck: def ckdisp(self,mint,hour, prefix=False, rot=0): # Perfor basic error check on variables if mint < 0 or mint > 59:
button = 24 buttonLed = 21 # GPIO setup io.setmode(io.BCM) io.setup(button, io.IN, pull_up_down=io.PUD_UP) io.setup(buttonLed, io.OUT) locale.setlocale(locale.LC_ALL, '') # use system time #################################### # Initialize LED Matrix # create device for linear preassembled 4x8x8 max7219 matrix serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=4, block_orientation=-90) device.contrast(0x05) print("Created device LED Matrix device") # note: change device.contrast value (0xXX) to change leds brightness # TODO GET THE IP ADDRESS AND DISPLAY ON THE MATRIX SO WE DON'T LOSE ACCESS print("booth starting up...") def displayScroll(msg): # print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.03)
def test_unknown_block_orientation(): with pytest.raises(AssertionError): max7219(serial, cascaded=2, block_orientation="sausages")
def test_show(): device = max7219(serial, cascaded=3) serial.reset_mock() device.show() serial.data.assert_called_once_with([12, 1] * 3)
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 test_init_cascaded(): device = max7219(serial, cascaded=4) assert device.width == 32 assert device.height == 8
def test_hide(): device = max7219(serial, cascaded=5) serial.reset_mock() device.hide() serial.data.assert_called_once_with([12, 0] * 5)
# Setup inputs and outputs Last_Led_Test_Mode = "Off" Last_Brightness = "Bright" # Creating Max7219 device print "Creating Max7219 Device" serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=1 or 1, block_orientation=0) print "Created Max7219 Device" sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) while True: try: while True: sock.settimeout(2) data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes #print "received message:", data
COLUMN_DAY = 2 COLUMN_HOUR = 5 COLUMN_MINUTE = 6 COLUMN_MONTH = 1 COLUMN_SECOND = 7 COLUMN_YEAR = 0 COLUMNS = [COLUMN_YEAR, COLUMN_MONTH, COLUMN_DAY, COLUMN_HOUR, COLUMN_MINUTE, COLUMN_SECOND] REFRESH_INTERVAL_SECONDS = 1 YEAR_OFFSET = 2000 def binary_clock(device): while True: now = datetime.now() fields = [now.year - YEAR_OFFSET, now.month, now.day, now.hour, now.minute, now.second] points = [] for i, value in zip(COLUMNS, fields): for j in range(device.height): mask = 2 ** j if value & mask: points.append((i, device.height - 1 - j)) with canvas(device) as draw: draw.point(points, fill='white') time.sleep(REFRESH_INTERVAL_SECONDS) if __name__ == '__main__': serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=2) binary_clock(device)
def test_init_reversed(): device = max7219(serial, cascaded=4, blocks_arranged_in_reverse_order=True) assert device.blocks_arranged_in_reverse_order is True
def test_contrast(): device = max7219(serial, cascaded=6) serial.reset_mock() device.contrast(0x6B) serial.data.assert_called_once_with([10, 6] * 6)