def main(argv): remote = '' key = '' try: opts, args = getopt.getopt(argv,"hr:k:",["remote=","key="]) except getopt.GetoptError: print 'remote.py [-r <remote>] -k <key>' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'remote.py [-r <remote>] -k <key>' sys.exit() elif opt in ("-r", "--remote"): remote = arg elif opt in ("-k", "--key"): key = arg device = led.matrix(cascaded=3) device.brightness(3) if(len(key) == 1): if (key.isdigit()): device.letter(0,ord(key)) else: device.show_message(key, font=proportional(CP437_FONT)) else: device.show_message(key, font=proportional(CP437_FONT)) time.sleep(0.5) device.clear()
def set_font(fontName='DEFAULT_FONT'): return { 'DEFAULT_FONT': DEFAULT_FONT, 'SINCLAIR_FONT': proportional(SINCLAIR_FONT), 'TINY_FONT': proportional(TINY_FONT), 'CP437_FONT': proportional(CP437_FONT) }[fontName]
def poll(): item = 'NO DATA' while True: try: item = queue.get(False) device.show_message(item, font=proportional(CP437_FONT)) queue.task_done() except Queue.Empty: device.show_message(item, font=proportional(CP437_FONT))
def Intro(IntroStr="Pi-Fighter"): device.brightness(15) device.show_message(IntroStr, font=proportional(CP437_FONT), delay=0.04) # Countdown for i in range(5, -1, -1): Str = ("{}".format(i)) device.show_message(Str, font=proportional(CP437_FONT), delay=0.04) time.sleep(.4)
def run(self): self.device.scrollMessage("Clock 1.2 ", font=proportional(LCD_FONT)) self.device.scrollMessage(get_ip_address(), font=proportional(LCD_FONT)) time.sleep(5) self.device.brightness(0) while 1: if (self.displayOn): self.displayTime() #str = datetime.datetime.now().strftime('%H:%M ') #self.device.displayMessage(str, font=proportional(LCD_FONT), delay=0.06) time.sleep(10)
def scrollText(text): if PI: device.show_message(text, 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 updateCounter(job_func, *args, **kwargs): """ Updates the LED matrix with the current count. Values are fetched from the specified job func, """ ret = functools.partial(job_func, *args, **kwargs)() device.show_message(ret, font=proportional(TINY_FONT))
def fuc1(): while True: device = led.matrix(cascaded=1) rd=read_temp() con = str("%.2f" % rd)+"`C" #+"Time is "+str(datetime.datetime.now().time()) "%.2f" %" for TWO decimial point # print(con) #To display on the terminal # print(datetime.datetime.now().time()) device.show_message(con, font=proportional(CP437_FONT))
def continousWriteThread(self): while True: self.lock.acquire() using = self.intensity / 6.666 #print(using) #print(int(using)) device.brightness(int(using)) device.show_message(self.text, font=proportional(CP437_FONT)) self.lock.release() time.sleep(1)
def getUpcomingDeparturesFromStop(stop): try: response = urllib2.urlopen(NEXT_BUS_API_BASE + "command=predictions&a=actransit&stopId=" + stop) bus_departures = xml.etree.ElementTree.parse(response).getroot() for route in bus_departures.findall('predictions'): routeName = route.get("routeTag") if routeName in busRoutes and not route.get("dirTitleBecauseNoPredictions"): for direction in route.findall("direction"): toward = direction.get("title") towardAcronym = changeTowardToAcronym(toward) minutes = direction[0].get("minutes") bus = routeName + " -> " + towardAcronym + " : " + minutes + "m" busList.append(bus) print(bus) except: device.show_message("Error", font=proportional(TINY_FONT))
def numAlert(name, value): device.brightness(1) device.show_message(name, font=proportional(CP437_FONT)) time.sleep(0.5) if value == 0: device.letter(0, 3) else: device.letter(0, ord(str(value))) for x in range(5): for i in range(1, 8): device.brightness(i) time.sleep(0.05) for j in range(1, 8): device.brightness(8 - j) time.sleep(0.05) time.sleep(0.5) for y in range(8): device.scroll_down() time.sleep(0.05)
def countdown(self): """ Display countdown on LED matrix, updatingn in 10 second intervals Determines video recording length :return: """ # Initialize display matrix = led.matrix() # Display message at beginning of recording. matrix.show_message("Seconds left:", font=proportional(CP437_FONT)) time.sleep(1) # Wait for message to display time_remaining = self.video_length while time_remaining > 0: matrix.show_message(str(time_remaining)) time_remaining -= 10 time.sleep(10)
def main(argv): remote = "" key = "" try: opts, args = getopt.getopt(argv, "hr:k:", ["remote=", "key="]) except getopt.GetoptError: print "remote.py [-r <remote>] -k <key>" sys.exit(2) for opt, arg in opts: if opt == "-h": print "remote.py [-r <remote>] -k <key>" sys.exit() elif opt in ("-r", "--remote"): remote = arg elif opt in ("-k", "--key"): key = arg device = led.matrix(cascaded=3) device.brightness(3) device.show_message(key, font=proportional(CP437_FONT)) time.sleep(1) device.clear()
#!/usr/bin/env python try: import max7219.led as led import time from max7219.font import proportional, SINCLAIR_FONT, TINY_FONT, CP437_FONT from random import randrange device = led.matrix5x7(cascaded=2, vertical=True) device.show_message("MAX7219 LED Matrix Demo", font=proportional(CP437_FONT), delay=0.2) time.sleep(1) device.show_message("Brightness") time.sleep(1) device.letter(0, ord('A')) time.sleep(1) for _ in range(5): for intensity in xrange(16): device.brightness(intensity) time.sleep(0.1) device.brightness(7) time.sleep(1) device.show_message("Orientation") time.sleep(1) device.letter(0, ord('A'))
#!/usr/bin/env python try: import max7219.led as led import time from max7219.font import proportional, SINCLAIR_FONT, TINY_FONT, CP437_FONT from random import randrange device = led.matrix5x7(cascaded=2, vertical=True) device.show_message("MAX7219 LED Matrix Demo", font=proportional(CP437_FONT), delay=0.2) time.sleep(1) device.show_message("Brightness") time.sleep(1) device.letter(0, ord('A')) time.sleep(1) for _ in range(5): for intensity in xrange(16): device.brightness(intensity) time.sleep(0.1) device.brightness(7) time.sleep(1) device.show_message("Orientation") time.sleep(1) device.letter(0, ord('A')) time.sleep(1)
[1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 1, 0, 0, 1], [0, 1, 0, 0, 0, 0, 1, 0], [0, 0, 1, 1, 1, 1, 0, 0]] sad_matrix = [[0, 0, 1, 1, 1, 1, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0], [1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 1, 1, 0, 0, 1], [1, 0, 1, 0, 0, 1, 0, 1], [0, 1, 0, 0, 0, 0, 1, 0], [0, 0, 1, 1, 1, 1, 0, 0]] device = led.matrix(cascaded=1) device.brightness(0) # var 1 if you want to write text device.show_message( "Hello", delay=0.2, font=proportional(LCD_FONT), ) # var 2 if you want to draw something def draw_matrix(matrix): for row, row_list in enumerate(matrix): for column, column_value in enumerate(row_list): device.pixel(column, row, column_value) draw_matrix(hearth_matrix) sleep(2) draw_matrix(smile_matrix) sleep(2) draw_matrix(sad_matrix)
def display_on_led_matrix(text): global device device.show_message(text, font=proportional(CP437_FONT))
#!/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.show_message("MAX7219 LED Matrix Demo", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("MAX7219 LED Matrix Demo", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("MAX7219 LED Matrix Demo", font=proportional(CP437_FONT))
def my_action(self, remote, timestamp, key, value, properties): print(key) print(value) if key == 'kill': device.show_message(value['attacker_name'] + " killed " + value['victim_name'], font=proportional(CP437_FONT), delay=0.03)
currentYandex = parseYandex(yandex) except: print "yandex parse err" print yandex gismeteRootNode = None if gismeteo != None: try: gismeteRootNode = ET.fromstring(gismeteo) except: print "parse gismete failed" if gismeteRootNode is None and currentYandex is None: device.brightness(1) device.show_message("Error getting data ...", font=proportional(CP437_FONT)) time.sleep(10) continue fc0 = "" fc1 = "" fc2 = "" if gismeteRootNode is not None: fc0 = formatForecastGismeteo(gismeteRootNode[0][0][0]) fc0 = "gismeteo %s" % (fc0) fc1 = '>%s' % formatForecastGismeteo(gismeteRootNode[0][0][1]) fc2 = '>>%s' % formatForecastGismeteo(gismeteRootNode[0][0][2]) if currentYandex != None: fcYa = formatForecastYandex(currentYandex)
#!/usr/bin/env python import max7219.led as led import time from max7219.font import proportional, SINCLAIR_FONT, TINY_FONT, CP437_FONT device = led.matrix(cascaded=1) try: device.show_message("ROHAN", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("Nigama", font=proportional(CP437_FONT)) time.sleep(1) except KeyboardInterrupt: pass device.clear()
while True: schedule.run_pending() time.sleep(1) elif (args.apiKey is not None and args.channelId is not None): schedule.every(5).seconds.do(updateCounter, getSubscribers, args.channelId, args.apiKey) # Run the scheduler while True: schedule.run_pending() time.sleep(1) elif (args.ticker is not None): oldPriceMap = {} # keeps track of the last price diffPriceMap = {} # keeps track of the last record while True: ret = getCryptoTickerPriceMap() msg = formatCryptoTicker(oldPriceMap, ret) device.show_message(msg + ' ', font=proportional(CUSTOM_FONT)) # if the last record and the current price are differnt, set the old price map to the last record if cmp(ret, diffPriceMap) != 0: oldPriceMap = diffPriceMap diffPriceMap = ret else: # No arguments provided sys.exit(0)
def main(): global FPSCLOCK, DISPLAYSURF, BASICFONT, BIGFONT global a1_counter ,RUNNING, joystick a1_counter=0 RUNNING=True if not PI: pygame.init() FPSCLOCK = pygame.time.Clock() DISPLAYSURF = pygame.display.set_mode((10*SIZE, 22*SIZE)) BASICFONT = pygame.font.Font('freesansbold.ttf', 18) BIGFONT = pygame.font.Font('freesansbold.ttf', 100) pygame.display.set_caption('Pi Games') else: # audio disabled os.environ["SDL_VIDEODRIVER"] = "dummy" #dummy display for pygame audio pygame.init() # pygame.mixer.music.load('tetrisb.mid') device.brightness(1) device.show_message("Waiting for controller...", font=proportional(CP437_FONT),delay=0.015) pygame.joystick.init() try: joystick = pygame.joystick.Joystick(0) # create a joystick instance joystick.init() # init instance # print("Initialized joystick: {}".format(joystick.get_name())) except pygame.error: # print("no joystick found.") clearScreen() drawClock(1) if PI: device.show_message("Let's play", font=proportional(CP437_FONT),delay=0.03) # print("after clock") while True: clearScreen() drawSymbols() updateScreen() pygame.event.pump() for event in pygame.event.get(): # print("event detected {}".format(event)) if event.type == pygame.JOYBUTTONDOWN: # print("Joystick button pressed: {}".format(event.button)) if (event.button == 0): drawClock(1) if (event.button == 1): runPongGame() if (event.button == 2): runSnakeGame() if (event.button == 3): runTetrisGame() time.sleep(.1) terminate()
while i <> 3: a = outrouting.pop(0) i += 1 O = BMD_VideohubOutput-1 while O <> BMD_VideohubOutput+1: ausgabe = outrouting[O].split(' ') outputinteger = int(ausgabe[0]) input = ilabels[int(ausgabe[1])+3][2:] O += 1 name = input.lstrip(' ') device.brightness(0) device.show_message(name, font=proportional(CP437_FONT), delay=0.015) laenge = len(name[:8]) i=0 while i < laenge: device.letter(i, ord(str(str(name)[i]))) i += 1 #wait for changings in Output routing while 1: switch = sockBMD_Videohub.recv(4096) switch = switch.split("\n") time.sleep(0.1) if switch[0] == "VIDEO OUTPUT ROUTING:": ausgabe = switch[1].split(' ') outputinteger = int(ausgabe[0]) if(outputinteger) == BMD_VideohubOutput:
def show_message(self, message): self.matrix.show_message(message, font=proportional(CP437_FONT))
#!/usr/bin/env python import max7219.led as led import time from max7219.font import proportional, SINCLAIR_FONT, TINY_FONT, CP437_FONT device = led.matrix(cascaded=3) try: device.show_message("ROHAN", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("NIGAMA", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("SWETHA", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("RAM", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("LASYA", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("ANUSHA", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("ABHIRAM", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("ABCDEFGHIJKLMNOPQRSTUVWXYZ", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("abcdefghijklmnopqrstuvwxyz", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("1234567890", font=proportional(CP437_FONT)) time.sleep(1) except KeyboardInterrupt: pass
print(key) print(value) if key == 'kill': device.show_message(value['attacker_name'] + " killed " + value['victim_name'], font=proportional(CP437_FONT), delay=0.03) try: import max7219.led as led import time import SourceLib from max7219.font import proportional, SINCLAIR_FONT, TINY_FONT, CP437_FONT from random import randrange device = led.matrix5x7(cascaded=8, vertical=True) device.brightness(15) device.show_message("kilLED", font=proportional(CP437_FONT), delay=0.07) time.sleep(1) ip = '192.168.188.22' server = SourceLog.SourceLogListener((ip, 17015), ('192.168.188.21', 27015), LEDLogParser()) asyncore.loop() except KeyboardInterrupt: print "terminating..." #except: # print "General exception" finally: device.clear()
device = led.matrix(cascaded=1) device.brightness(0) weather_interval = 120.0 # interval in seconds next_weather_check = time.time() + weather_interval weather_info = {'icon': 'default', 'statement': ''} last_connection_failed = False while True: now = time.time() if now > next_weather_check: try: last_connection_failed = False weather_info = check_weather(api_key, lat, lng) except ValueError: print "check_weather raised an exception." except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout, requests.exceptions.ReadTimeout, requests.exceptions.HTTPError): last_connection_failed = True print "connection exception" next_weather_check = now + weather_interval if (len(weather_info['statement'].strip()) > 0): draw_weather_icon(weather_info['icon']) time.sleep(2) device.show_message(weather_info['statement'], font=proportional(SINCLAIR_FONT)) else: draw_time() if last_connection_failed: heartbeat()
while True: # Login if necessary. if worksheet is None: worksheet = login_open_sheet(GDOCS_OAUTH_JSON, GDOCS_SPREADSHEET_NAME) # Attempt to get sensor reading. humidity, temp = Adafruit_DHT.read(DHT_TYPE, DHT_PIN) # Skip to the next reading if a valid measurement couldn't be taken. # This might happen if the CPU is under a lot of load and the sensor # can't be reliably read (timing is critical to read the sensor). if humidity is None or temp is None: time.sleep(2) continue device.show_message("Temperature:{0:0.1f}".format(temp)+chr(223)+"C", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("Humidity:{0:0.1f}%".format(humidity), font=proportional(CP437_FONT)) #print 'Temperature: {0:0.1f}\xb0C'.format(temp) #print 'Humidity: {0:0.1f}%'.format(humidity) # Append the data in the spreadsheet, including a timestamp try: worksheet.append_row((datetime.datetime.now(), temp, humidity)) except: # Error appending data, most likely because credentials are stale. # Null out the worksheet so a login is performed at the top of the loop. print 'Append error, logging in again' worksheet = None time.sleep(FREQUENCY_SECONDS) continue
# very simple logic for showing that script is alive tickFlag = 'l' if os.path.isfile('tick-flag.txt'): with open('tick-flag.txt', 'r') as tickFlagFile: tickFlag=tickFlagFile.read() if (tickFlag =='l'): tickFlag = 'r' else: tickFlag = 'l' with open('tick-flag.txt', 'w') as tickFlagFile: tickFlagFile.write(tickFlag) # draw status icon if (runFailed): if (tickFlag=='l'): # device.letter(0, 1) ipaddr = run_cmd(cmd) device.show_message(ipaddr, font=proportional(CP437_FONT)) else: # device.letter(0, 2) ipaddr = run_cmd(cmd) device.show_message(ipaddr, font=proportional(CP437_FONT)) else: device.letter(0, 3) if (tickFlag=='r'): device.scroll_right() #print ('done')
import time from random import randrange import max7219.led as led from max7219.font import proportional, SINCLAIR_FONT, TINY_FONT, CP437_FONT # create matrix device device = led.matrix(cascaded=1) print("Created device") # start demo msg = "MAX7219 LED Matrix Demo" print(msg) device.show_message(msg, font=proportional(CP437_FONT)) time.sleep(1) msg = "Brightness" print(msg) device.show_message(msg) time.sleep(1) device.letter(0, ord('A')) time.sleep(1) for _ in range(5): for intensity in range(16): device.brightness(intensity) time.sleep(0.1) device.brightness(7)
def displayBus(): if (len(busList) == 0): device.show_message("No buses :(", font=proportional(TINY_FONT)) else: bus = busList.pop(0) device.show_message(bus, font=proportional(TINY_FONT))
import RPi.GPIO as GPIO 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=4) msg = 'www.1001000.io/area51' try: while True: device.show_message(msg, font=proportional(CP437_FONT)) device.flush() except: device.flush() GPIO.cleanup()
print(bus) except: device.show_message("Error", font=proportional(TINY_FONT)) def changeTowardToAcronym(toward): towardSplit = toward.split() acronym = "" for i in range(1, len(towardSplit)): acronym += towardSplit[i][0] return acronym def displayBus(): if (len(busList) == 0): device.show_message("No buses :(", font=proportional(TINY_FONT)) else: bus = busList.pop(0) device.show_message(bus, font=proportional(TINY_FONT)) if __name__ == '__main__': device = led.matrix(cascaded = 8) device.orientation(90) # give pi time to connect to the internet for x in range(0, 1000): device.show_message("Loading ...", font=proportional(TINY_FONT)) time.sleep(.01) while True: showBuses() time.sleep(2)
def main(): global FPSCLOCK, DISPLAYSURF, BASICFONT, BIGFONT global a1_counter, RUNNING a1_counter = 0 RUNNING = True if not PI: pygame.init() FPSCLOCK = pygame.time.Clock() DISPLAYSURF = pygame.display.set_mode((PIXEL_X * SIZE, PIXEL_Y * SIZE)) BASICFONT = pygame.font.Font('freesansbold.ttf', 18) BIGFONT = pygame.font.Font('freesansbold.ttf', 100) pygame.display.set_caption('Pi Games') else: # audio disabled # os.environ["SDL_VIDEODRIVER"] = "dummy" #dummy display for pygame audio # pygame.init() # pygame.mixer.music.load('tetrisb.mid') device.brightness(1) device.show_message("Waiting for controller...", font=proportional(CP437_FONT), delay=0.015) # Port 0 means to select an arbitrary unused port HOST, PORT = '', 4711 server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler) ip, port = server.server_address # Start a thread with the server -- that thread will then start one # more thread for each request server_thread = threading.Thread(target=server.serve_forever) # Exit the server thread when the main thread terminates server_thread.daemon = True server_thread.start() print("Server loop running in thread:", server_thread.name) clearScreen() drawClock(1) if PI: device.show_message("Let's play", font=proportional(CP437_FONT), delay=0.03) while True: clearScreen() drawSymbols() while myQueue.empty(): time.sleep(.1) a1_counter += 1 updateScreen() if not PI: checkForQuit() time.sleep(.1) event = myQueue.get() if event.type == QKEYDOWN: if (event.key == BUTTON_BLUE): runSnakeGame() elif (event.key == BUTTON_YELLOW): # if PI: # pygame.mixer.music.play(-1,0.0) runTetrisGame() # if PI: # pygame.mixer.music.stop() elif (event.key == BUTTON_RED): runPongGame() elif (event.key == BUTTON_GREEN): drawClock(1) terminate()
def error(): device.show_message('Loading...', font=proportional(CP437_FONT)) time.sleep(1)
#!/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.matrix(cascaded=18,vertical=True) # device.orientation(180); device.show_message("MAX7219 LED Matrix Demo", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("Brightness") time.sleep(1) device.letter(0, ord('A')) time.sleep(1) for _ in range(5): for intensity in xrange(16): device.brightness(intensity) time.sleep(0.1) device.brightness(7) time.sleep(1) device.show_message("Orientation") time.sleep(1) device.letter(0, ord('A'))
def displayTime(self): str = datetime.datetime.now().strftime('%H:%M ') self.device.displayMessage(str, font=proportional(LCD_FONT), delay=0.06)
#!/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.show_message("MAX7219 LED Matrix Demo", font=proportional(CP437_FONT)) time.sleep(1) device.show_message("Brightness") time.sleep(1) device.letter(0, ord('A')) time.sleep(1) for _ in range(5): for intensity in range(16): device.brightness(intensity) time.sleep(0.1) device.brightness(7) time.sleep(1) device.show_message("Orientation") time.sleep(1) device.letter(0, ord('A')) time.sleep(1) for _ in range(5):
def displayMessage(self, message): self.device.displayMessage(message, font=proportional(LCD_FONT), delay=0.06)
def DisplayStr(WriteStr): device.brightness(15) device.show_message(WriteStr, font=proportional(CP437_FONT), delay=0.04)
while i <> 3: a = outrouting.pop(0) i += 1 O = BMD_VideohubOutput - 1 while O <> BMD_VideohubOutput + 1: ausgabe = outrouting[O].split(' ') outputinteger = int(ausgabe[0]) input = ilabels[int(ausgabe[1]) + 3][2:] O += 1 name = input.lstrip(' ') device.brightness(0) device.show_message(name, font=proportional(CP437_FONT), delay=0.015) laenge = len(name[:8]) i = 0 while i < laenge: device.letter(i, ord(str(str(name)[i]))) i += 1 #wait for changings in Output routing while 1: switch = sockBMD_Videohub.recv(4096) switch = switch.split("\n") time.sleep(0.1) if switch[0] == "VIDEO OUTPUT ROUTING:": ausgabe = switch[1].split(' ') outputinteger = int(ausgabe[0]) if (outputinteger) == BMD_VideohubOutput: