def write_large_number(largenumber, spidevice): # split number over the displays device = led.sevensegment(cascaded=2, spi_device=spidevice) num_str = str(largenumber) num_len = len(str(largenumber)) device.clear(deviceId=0) device.clear(deviceId=1) print i if num_len > MAX_NUM_DIGITS_D1: str_d1 = num_str[-MAX_NUM_DIGITS_D1:] print str_d1 num_d1 = int(str_d1) print num_d1 str_d2 = num_str[0 : len(num_str) - MAX_NUM_DIGITS_D1] print str_d2 num_d2 = int(str_d2) print num_d2 device.write_number(deviceId=1, zeroPad=True, value=num_d1) device.write_number(deviceId=0, value=num_d2) elif num_len > (MAX_NUM_DIGITS_D1 + MAX_NUM_DIGITS_D2): print "Number too large for display" else: device.write_number(deviceId=1, value=largenumber)
def write_large_number(largenumber, spidevice): # split number over the displays device = led.sevensegment(cascaded=2, spi_device=spidevice) num_str = str(largenumber) num_len = len(str(largenumber)) device.clear(deviceId=0) device.clear(deviceId=1) print i if (num_len > MAX_NUM_DIGITS_D1): str_d1 = num_str[-MAX_NUM_DIGITS_D1:] print str_d1 num_d1 = int(str_d1) print num_d1 str_d2 = num_str[0:len(num_str) - MAX_NUM_DIGITS_D1] print str_d2 num_d2 = int(str_d2) print num_d2 device.write_number(deviceId=1, zeroPad=True, value=num_d1) device.write_number(deviceId=0, value=num_d2) elif num_len > (MAX_NUM_DIGITS_D1 + MAX_NUM_DIGITS_D2): print "Number too large for display" else: device.write_number(deviceId=1, value=largenumber)
def main(): # create seven segment device device = led.sevensegment(cascaded=1) print('Simple text...') for _ in range(8): device.write_text(0, "HELLO") time.sleep(0.6) device.write_text(0, " GOODBYE") time.sleep(0.6) # Scrolling Alphabet Text print('Scrolling alphabet text...') device.show_message("HELLO EVERYONE!") device.show_message("0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ") # Digit futzing date(device, 0) time.sleep(5) clock(device, 0, seconds=10) # Brightness print('Brightness...') for x in range(5): for intensity in range(16): device.brightness(intensity) time.sleep(0.1) device.brightness(7) # Scrolling print('Scrolling...') for x in range(2): for _ in range(8): device.scroll_right() time.sleep(0.1) time.sleep(1) device.clear() # Negative numbers print('Negative numbers...') for x in range(-30, 128): device.write_number(deviceId=0, value=x) time.sleep(0.05) # Hex numbers print('Hex numbers...') for x in range(0xfa909, 0xfab2a): device.write_number(deviceId=0, value=x, base=16, leftJustify=True) time.sleep(0.025) print('Clear device...') device.clear() time.sleep(1) print('Random numbers...') a = random.randint(-999, 999) # b = random.randint(-3223, 999) device.brightness(3) for x in range(500): a += random.random() * 10 # b -= 1 # c = a + b / (random.random() * 43) device.write_number(deviceId=0, value=a, decimalPlaces=1) # device.write_number(deviceId=1, value=b, zeroPad=True) # device.write_number(deviceId=2, value=c, decimalPlaces=2) time.sleep(0.5)
import max7219.led as led from time import * MAX_NUM_DIGITS_D2 = 8 MAX_NUM_DIGITS_D1 = 8 device = led.sevensegment() def write_large_number(largenumber, spidevice): # split number over the displays device = led.sevensegment(cascaded=2, spi_device=spidevice) num_str = str(largenumber) num_len = len(str(largenumber)) device.clear(deviceId=0) device.clear(deviceId=1) print i if num_len > MAX_NUM_DIGITS_D1: str_d1 = num_str[-MAX_NUM_DIGITS_D1:] print str_d1 num_d1 = int(str_d1) print num_d1 str_d2 = num_str[0 : len(num_str) - MAX_NUM_DIGITS_D1] print str_d2 num_d2 = int(str_d2) print num_d2 device.write_number(deviceId=1, zeroPad=True, value=num_d1) device.write_number(deviceId=0, value=num_d2) elif num_len > (MAX_NUM_DIGITS_D1 + MAX_NUM_DIGITS_D2): print "Number too large for display" else:
month = now.month year = now.year - 2000 # Set day device.letter(deviceId, 8, int(day / 10)) # Tens device.letter(deviceId, 7, day % 10) # Ones device.letter(deviceId, 6, '-') # dash # Set day device.letter(deviceId, 5, int(month / 10)) # Tens device.letter(deviceId, 4, month % 10) # Ones device.letter(deviceId, 3, '-') # dash # Set day device.letter(deviceId, 2, int(year / 10)) # Tens device.letter(deviceId, 1, year % 10) # Ones device = led.sevensegment() # Write date date(device, 0) # Adjust Brightness for x in xrange(5): for intensity in xrange(16): device.brightness(intensity) time.sleep(0.1) device.brightness(7) # Scroll Text for i in xrange(8): device.scroll_right()
def main(): # create seven segment device device = led.sevensegment(cascaded=1) print('Simple text...') for _ in range(8): device.write_text(0, "HELLO") time.sleep(0.6) device.write_text(0, " GOODBYE") time.sleep(0.6) # Scrolling Alphabet Text print('Scrolling alphabet text...') device.show_message("HELLO EVERYONE!") device.show_message( "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ") # Digit futzing date(device, 0) time.sleep(5) clock(device, 0, seconds=10) # Brightness print('Brightness...') for x in range(5): for intensity in range(16): device.brightness(intensity) time.sleep(0.1) device.brightness(7) # Scrolling print('Scrolling...') for x in range(2): for _ in range(8): device.scroll_right() time.sleep(0.1) time.sleep(1) device.clear() # Negative numbers print('Negative numbers...') for x in range(-30, 128): device.write_number(deviceId=0, value=x) time.sleep(0.05) # Hex numbers print('Hex numbers...') for x in range(0xfa909, 0xfab2a): device.write_number(deviceId=0, value=x, base=16, leftJustify=True) time.sleep(0.025) print('Clear device...') device.clear() time.sleep(1) print('Random numbers...') a = random.randint(-999, 999) # b = random.randint(-3223, 999) device.brightness(3) for x in range(500): a += random.random() * 10 # b -= 1 # c = a + b / (random.random() * 43) device.write_number(deviceId=0, value=a, decimalPlaces=1) # device.write_number(deviceId=1, value=b, zeroPad=True) # device.write_number(deviceId=2, value=c, decimalPlaces=2) time.sleep(0.5)
#!/usr/bin/env python import max7219.led as led import time from max7219.font import proportional, SINCLAIR_FONT, TINY_FONT, CP437_FONT from random import randrange # device = led.matrix(cascaded=1) device = led.sevensegment(cascaded=2, vertical=False) # device.orientation(180); device.show_message("MAX7219 LED Matrix Demo")
def binary_clock(device): dt = datetime.now() hour = dt.hour if (dt.hour > 12): hour = dt.hour - 12 draw_wide_row(device, hour, 0) draw_wide_row(device, hour, 1) draw_bcd_row(device, dt.minute, 3) draw_bcd_row(device, dt.second, 5) def totp(device, deviceId, secret): token = otp.get_totp(secret) device.write_number(deviceId, value=token) # Main Program device = led.sevensegment(cascaded=3) device.brightness(0) with open('config.json') as json_data_file: config = json.load(json_data_file) secret = config['otp']['secret'] while True: time.sleep(.5) totp(device, 2, secret) binary_clock(device) clock(device, 1)
for _ in xrange(seconds): now = datetime.now() hour = now.hour minute = now.minute second = now.second dot = second % 2 == 0 # calculate blinking dot # Set hours device.letter(deviceId, 4, int(hour / 10)) # Tens device.letter(deviceId, 3, hour % 10, dot) # Ones # Set minutes device.letter(deviceId, 2, int(minute / 10)) # Tens device.letter(deviceId, 1, minute % 10) # Ones time.sleep(1) device = led.sevensegment(cascaded=3) # Alphabet Text device.show_message("HELLO EVERYONE!") device.show_message( "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ") # Digit futzing date(device, 1) clock(device, 0, seconds=10) # Brightness for x in xrange(5): for intensity in xrange(16): device.brightness(intensity) time.sleep(0.1)
#!/usr/bin/env python import max7219.led as led import time import random display = led.sevensegment(cascaded=3) for x in range(-30, 128): display.write_number(deviceId=0, value=x) time.sleep(0.05) for x in range(99823, 100023): display.write_number(deviceId=1, value=x, leftJustify=True) time.sleep(0.05) display.clear(deviceId=1) time.sleep(1) display.clear() time.sleep(1) a = random.randint(-999, 9999) b = random.randint(-3223, 9999) for x in range(500): a += random.random() * 10 b -= 1 c = a + b / random.random() display.write_number(deviceId=0, value=a, decimalPlaces=3) display.write_number(deviceId=1, value=b, zeroPad=True)
def __init__(self): self.device = led.sevensegment(cascaded=1) self.device.brightness(7)