def redraw_complete(self): lcd.set_cursor_position(0, 0) status = self.recorder.get_dispatcher_status() index = status[self.recorder.dispatcher_response_file_index] processes_remaining = status[ self.recorder.dispatcher_response_process_count] time_remaining = status[ self.recorder.dispatcher_response_time_remaining] print( "Dispatcher status: index: %s (%s) processes: %s (%s) time remaining: %s (%s)" % (index, type(index), processes_remaining, type(processes_remaining), time_remaining, type(time_remaining))) if processes_remaining == 0: print("Done") self.go_to_track_alignment() else: lcd.write("Finding tracks") lcd.set_cursor_position(0, 1) lcd.write("Time remaining:") lcd.set_cursor_position(0, 2) if time_remaining is None: lcd.write("Unknown") elif time_remaining > 0: minutes, seconds = divmod(time_remaining, 60) lcd.write('{:02}:{:02}'.format(int(minutes), int(seconds))) else: lcd.write('Just a moment...')
def handle_cancel(ch, evt): lcd.set_cursor_position(0, 0) lcd.write(pad_text('Startup...')) res = con.startup() txt = 'Complete' if res else 'Failure' lcd.set_cursor_position(0, 0) lcd.write(pad_text(txt))
def light_side(): print("Light side of the force!") l.clear() b.rgb(0,0,255) l.write("Moege die Macht mit Dir sein, Jedi Meister") sleep(10) test()
def write_mode_line(): lcd.set_cursor_position(0, 2) if con.connected: txt = 'MODE: {}'.format(con.mode.name) else: txt = 'DISCONNECTED' lcd.write(pad_text(txt))
def dark_side(): print("Dark side of the force!") l.clear() b.rgb(255,0,0) l.write("Ergib dich der dunklen Seite der Macht") sleep(10) test()
def temp(): print 'Starting Temp' from dothat import backlight from dothat import lcd import time lcd.set_contrast(50) while True: tempC = int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1e3 # Change backlight if temp changes if tempC < 60: backlight.rgb(0, 255, 0) elif tempC > 70: backlight.rgb(255, 0, 0) else: backlight.rgb(0, 255, 255) # Convert Temp to String tempF = str(tempC) # Write Temp and wait 1 sec. lcd.set_cursor_position(0, 0) lcd.write("Temp: " + tempF + " C") time.sleep(1) lcd.clear() print 'backlight: finishing'
def pregame_display(): set_entire_backlight(0xff, 0xff, 0xff) lcd.clear() lcd.set_cursor_position(0, 0) lcd.write(' Game Over') lcd.set_cursor_position(0, 2) lcd.write(' Touch To Start')
def lcd(data): if data["command"] == "write": lcd.write(data["value"]) return True if data["command"] == "clear": lcd.clear() return True if data["command"] == "set_contrast": lcd.set_contrast(data["contrast"]) return True if data["command"] == "set_cursor_position": lcd.set_cursor_position(data["column"], data["row"]) return True if data["command"] == "set_cursor_offset": lcd.set_cursor_offset(data["offset"]) return True if data["command"] == "set_display_mode": lcd.set_display_mode(data["enable"], data["cursor"], data["blink"]) return True if data["command"] == "create_char": lcd.create_char(data["char_pos"], data["char_map"]) return True if data["command"] == "create_animation": lcd.create_animation(data["anim_pos"], data["anim_map"], data["frame_rate"]) return True if data["command"] == "update_animations": lcd.update_animations() return True
def _write_cell_scrollable(self, col, row, offset): string = self.cells[row][col] lcd.set_cursor_position(self.starting_point[col], row) if len(string) <= self.col_lenths[col]: offset = 0 else: offset %= (len(string) + 2) lcd.write((string + padding)[offset:self.col_lenths[col] + offset])
def handle_left(ch,evt): print("Left pressed!") l.clear() l.write("BBC News Feed") time.sleep(1) l.clear() b.rgb(0,0,128) feedme("http://feeds.bbci.co.uk/news/rss.xml")
def handle_right(ch,evt): print("Right pressed!") l.clear() b.rgb(0,128,0) l.write("Hackaday RSS") time.sleep(1) l.clear() feedme("https://hackaday.com/blog/feed/")
def handle_down(ch, evt): global compression global A compression = True A = A - 5 A = np.clip(A, 1, 255) lcd.clear() lcd.write("Compr. strength=" + str(A))
def displayCurrentValues(): humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) color = temp_color(int(temperature)) backlight.rgb(int(color.red * 255), int(color.green * 255), int(color.blue * 255)) lcd.set_cursor_position(0, 0) lcd.write("Temperatur: " + str(temperature)) lcd.set_cursor_position(0,1) lcd.write("Humidity: " + str(humidity)) time.sleep(10.01)
def assign_selected_sensor(): global selected_sensor selected_sensor = item_deque[0] logger.info(selected_sensor.desc) lcd.clear() backlight.rgb(255, 255, 255) lcd.set_cursor_position(0, 0) lcd.write(selected_sensor.desc) lcd.set_cursor_position(0, 2)
def handle_down(ch, evt): #def handle_down(pin): global loopcount loopcount = 0 lcd.clear() backlight.rgb(255, 0, 0) lcd.write("Shutting Down!") #time.sleep(1) os.system('systemctl poweroff')
def displayCurrentValues(): humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) color = temp_color(int(temperature)) backlight.rgb(int(color.red * 255), int(color.green * 255), int(color.blue * 255)) lcd.set_cursor_position(0, 0) lcd.write("Temperatur: " + str(temperature)) lcd.set_cursor_position(0, 1) lcd.write("Humidity: " + str(humidity)) time.sleep(10.01)
def handle_up(ch, evt): settings = (int(filenum), int(shutter)) temp = settings[0] temp += 1 print('filenum is {}'.format(int(temp)) ) l.clear() b.rgb(0, 255, 0) l.write('filenum is {}'.format(int(temp))) global filenum filenum = int(temp)
def test(): print("Testing") l.clear() l.write("Jedi oder Sith?") x = 0 while True: x+=1 b.sweep( (x%360)/360.0) sleep(0.01)
def handle_button(ch, evt): global compression global A compression = not compression lcd.clear() if compression == False: #cv2.putText(bartext,"Compression off", (20,70), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,100,100)) lcd.write("Compression off!") else: #cv2.putText(bartext,"Compr. strength="+str(A), (20,70), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,100,100)) lcd.write("Compr. strength=" + str(A))
def handle_down(ch, evt): global dtemp, rtemp, display_status l.clear() b.rgb(128, 128, 0) #blue dtemp=dtemp-1 l.clear() l.set_cursor_position(0,1) l.write(str(room) + str(dtemp) + chr(223) + 'C') time.sleep(1) display_status="ON" default_display()
def speakIPAddress(): wlan = get_ip_address('wlan0') backlight.rgb(0, 255, 0) lcd.set_contrast(50) lcd.clear() lcd.set_cursor_position(2, 0) lcd.write("IP Address:") lcd.set_cursor_position(1, 1) lcd.write(wlan) command = "flite -voice rms -t 'My I P address is " + wlan + "' " print command os.system(command)
def touch_left(channel, event): global vestigo_sensor_name, pause pause = True backlight_rgb(255, 0, 255) location_index = locations.index(vestigo_sensor_name) if location_index < len(locations) - 1: vestigo_sensor_name = locations[location_index + 1] lcd.set_cursor_position(0, 0) lcd.write(vestigo_sensor_name.ljust(16)) config['general']['current_location'] = vestigo_sensor_name with open('/boot/air.ini', "w+") as configfile: config.write(configfile)
def scrollText(scrollBlurb): if len(scrollBlurb) > 16: padding = " " * 16 scrollBlurb = padding + scrollBlurb + " " for i in range(0,len(scrollBlurb)): l.set_cursor_position(0,0) l.write(scrollBlurb[i:(i+16)]) time.sleep(0.25) else: l.set_cursor_position(0,0) l.write(scrollBlurb) print(scrollBlurb)
def display_NIC(rowposition): lcd.set_cursor_position(0, rowposition) enxaddr = get_addr(get_NIC()) if enxaddr != 'Disconnected': outputeth = ('E:' + enxaddr) #Take the output of outputeth and get the length less 16chars on display and add the difference as white spaces outputeth = outputeth + (16 - len(outputeth)) * ' ' lcd.write(outputeth) #print outputeth else: outputeth = ('E:{}'.format(enxaddr)) outputeth = outputeth + (16 - len(outputeth)) * ' ' lcd.write(outputeth)
def display_WNIC(rowposition): lcd.set_cursor_position(0, rowposition) wlxaddr = get_addr(get_WNIC()) if wlxaddr != 'Disconnected': outputwlan = ('W:' + wlxaddr) #Take the output of outputwlan and get the length less 16chars on display and add the difference as white spaces outputwlan = outputwlan + (16 - len(outputwlan)) * ' ' lcd.write(outputwlan) #print outputwlan else: outputwlan = ('W:{}'.format(wlxaddr)) outputwlan = outputwlan + (16 - len(outputwlan)) * ' ' lcd.write(outputwlan)
def handle_button(ch,evt): print("Button pressed!") l.clear() b.rgb(0,0,0) l.set_cursor_position(0,0) l.write("Linux Voice") for i in range(256): b.left_rgb(i,0,0) time.sleep(0.01) b.mid_rgb(i,0,0) time.sleep(0.01) b.right_rgb(i,0,0) time.sleep(0.01)
def main(): lcd.clear() backlight.set_graph(0) backlight.rgb(255,255,255) lcd.set_cursor_position(1,0) lcd.write("MIFARE Cloner") lcd.set_cursor_position(3,2) lcd.write("by Cypaubr") time.sleep(3) lcd.clear() backlight.rgb(100,200,255) lcd.set_cursor_position(1,0) lcd.write("Place your tag") lcd.set_cursor_position(2,2) lcd.write("PRESS START") while True: @touch.on(touch.BUTTON) def start_detection(ch, evt): lcd.clear() detect() @touch.on(touch.CANCEL) def cancel_detection(ch, evt): lcd.clear() lcd.write("Canceling...") backlight.rgb(255,0,0) time.sleep(1) exit(0)
def check_if_someone_won(): global goals_locked global score_yellow global score_black global has_anyone_won if (score_yellow >= 5 and (score_yellow - score_black) >= 2): set_team_color(0) lcd.clear() lcd.set_cursor_position(0, 0) lcd.write(' Yellow wins!') lcd.set_cursor_position(0, 1) lcd.write(' ' + str(score_yellow) + ' - ' + str(score_black)) notify_slack() notify_replay_bot('game_end') sleep(5) has_anyone_won = True elif (score_black >= 5 and (score_black - score_yellow) >= 2): set_team_color(1) lcd.clear() lcd.set_cursor_position(0, 0) lcd.write(' Black wins!') lcd.set_cursor_position(0, 1) lcd.write(' ' + str(score_black) + ' - ' + str(score_yellow)) notify_slack() notify_replay_bot('game_end') sleep(5) has_anyone_won = True else: display_scoreboard() goals_locked = False
def redraw(self, menu): if self.millis() - self.lastUpdate <= 250: return if not self.running: return False self.lastUpdate = self.millis() lcd.set_cursor_position(0, 1) if not self.back: lcd.write(self.indices[self.currentIndex]) else: lcd.write(self.cards[self.indices[self.currentIndex]])
def handle_down(ch, evt): settings = (int(filenum), int(shutter)) temp = settings[0] if int(temp) == 1: print("Can't do more") l.clear() b.rgb(255, 0, 0) l.write("Can't go lower") else: temp -= 1 print('filenum is {}'.format(int(temp))) l.clear() b.rgb(0, 255, 0) l.write('filenum is {}'.format(int(temp))) global filenum filenum = int(temp)
def run(self): CMPFUNC = CFUNCTYPE(None, c_int, c_int, POINTER(c_ubyte), c_int, c_void_p) cmp_func = CMPFUNC(self.callbackfunction) lib.tdInit() lib.tdRegisterDeviceEvent(cmp_func, 0) lcd.clear() lcd.set_cursor_position(0, 1) lcd.write('Waiting...') backlight.off() backlight.graph_off() print 'Started' while True: time.sleep(1)
def redraw_idle(self): lcd.set_cursor_position(0, 0) lcd.write("Record") if self.audio_metadata is not None: # TODO: Alternate/scroll artist and title lcd.set_cursor_position(0, 1) lcd.write(self.audio_metadata["title"][:16]) # Line up labels with buttons on bottom row lcd.set_cursor_position(3, 2) lcd.write(chr(0)) lcd.set_cursor_position(6, 2) lcd.write("META") lcd.set_cursor_position(13, 2) lcd.write(chr(2))
def detect(): try: card= rfidiot.card except: throwexception() args= rfidiot.args card.info('multiselect v0.1n') card.settagtype(card.ALL) if(card.uid != None): lcd.clear() lcd.write(card.uid) lcd.set_cursor_position(0,1) lcd.write(card.tagtype)
def handle_right(ch, evt): settings = (int(filenum), int(shutter)) temp = settings[1] if int(temp) == 6000000: print("Can't do more") l.clear() b.rgb(255, 0, 0) l.write("Can't go higher") else: temp = int(temp) + 500000 print('shutter is {}'.format(int(temp))) l.clear() b.rgb(0, 0, 255) l.write('shutter is {}'.format(int(temp))) global shutter shutter = int(temp)
def _message(code, credit_balance=None): message_lock.acquire() _message_output(code) lcd.clear() lcd.write(message_code[code]) if credit_balance is not None: lcd.set_cursor_position(0, 2) lcd.write(" ") lcd.write(balance) credit_balance_string = locale.format('%.2f', credit_balance, monetary=True) lcd.set_cursor_position(lcd.COLS - len(credit_balance_string) - 1, 2) lcd.write(credit_balance_string) lcd.write(" ") time.sleep(2.5) message_lock.release()
def on_message(client, userdata, msg): """Handle incoming messages.""" # print("Topic:", msg.topic + ' : Message: ' + msg.payload) print(str(msg.topic), str(msg.payload)) if str(msg.topic) == "orchestra/cue": """Fire the cue playback function.""" play_cue(msg.payload.decode("utf-8")) elif str(msg.topic) == "orchestra/song": print("Song title received") # Display song title on the HAT lcd.set_cursor_position(0, 1) lcd.write(str(msg.payload[:16].decode("utf-8")).ljust(16)) else: print("Well, that didn't work")
def main(): # Get the current SSID SSID = None try: SSID = subprocess.check_output(["iwgetid", "-r"]).strip() except subprocess.CalledProcessError: # If there is no connection subprocess throws a 'CalledProcessError' pass # Show status on the LCD display if SSID is None: backlight.rgb(255, 0, 0) lcd.clear() lcd.write("Not connected") else: backlight.rgb(0, 255, 0) lcd.clear() lcd.write("SSID: " + SSID)
def takelongphoto(): print("Takeing Photo") l.clear() b.rgb(255, 255, 255) l.write("Taking Photo Don't Move") settings = (int(filenum), int(shutter)) with picamera.PiCamera() as camera: camera.resoluion = (1024, 768) camera.hflip = True camera.vflip = True camera.framerate = Fraction(1, 6) camera.shutter_speed = settings[1] camera.expodure_mode = 'off' camera.iso = 100 sleep(10) camera.capture('/home/pi/photo/longexp_{}.jpg'.format(int(settings[0]))) print("DONE!") l.clear() b.rgb(0, 255, 255) l.write("We are done")
def default_display(): global dtemp, rtemp, heat, display_status, heatc l.clear() if display_status == "ON": b.rgb(128,128,128) else: b.rgb(0,0,0) l.set_cursor_position(0,0) l.write(str(room) + str(dtemp) + chr(223) + 'C') l.set_cursor_position(0,1) l.write("Heating: " + str(heat)) l.set_cursor_position(0,2) x= "Now:" + str(rtemp) + chr(223) + 'C ' + time.strftime("%H:%M") l.write(x) count_heat() time.sleep(1)
[0,0,0,0,0,0,0,16], [0,0,0,0,0,0,0,0] ] def tidyup(): backlight.off() lcd.clear() def get_anim_frame(char,fps): return char[ int(round(time.time()*fps) % len(char)) ] backlight.graph_off() backlight.off() lcd.set_cursor_position(0,0) lcd.write(chr(0) * 16) lcd.set_cursor_position(0,1) lcd.write(chr(0) * 16) lcd.set_cursor_position(0,2) lcd.write(chr(0) * 16) time.sleep(1) for x in range(0,255,5): backlight.single_rgb(3,x,x,x) atexit.register(tidyup) while True: lcd.create_char(0,get_anim_frame(rain,20)) time.sleep(0.1) #signal.pause()
def handle_down(ch,evt): print("Playing BBC 6 Music") l.clear() b.rgb(87,145,146) l.write("BBC 6 Music") player(radio6)
#!/usr/bin/env python print(""" This basic example display a simple text and terminates executaion immediately. """) import dothat.backlight as backlight import dothat.lcd as lcd # Turn off led bar backlight.set_graph(0) # Set backlight colour to cyan backlight.rgb(0,255,255) # Display text in FIRST line of the LCD lcd.set_cursor_position(0, 0) lcd.write("Hello world.") # Display text in SECOND line of the LCD lcd.set_cursor_position(0, 1) lcd.write("This is fun!") # Display text in THIRD line of the LCD lcd.set_cursor_position(0, 2) lcd.write(":)")
def handle_cancel(ch,evt): print("Cancel pressed!") l.clear() b.rgb(0,0,0) l.write("Boom!")
def handle_button(ch,evt): print("Button pressed!") l.clear() b.rgb(255,255,255) l.write("Ouch!")
def handle_right(ch,evt): print("Right pressed!") l.clear() b.rgb(0,255,255) l.write("Rightie tighty!")
def handle_left(ch,evt): print("Left pressed!") l.clear() b.rgb(0,0,255) l.write("Leftie left left!")
def handle_down(ch,evt): print("Down pressed!") l.clear() b.rgb(0,255,0) l.write("Down down doobie down!")
def handle_up(ch,evt): print("Up pressed!") l.clear() b.rgb(255,0,0) l.write("Up up and away!")
import dothat.lcd as lcd import dothat.backlight as backlight import time from datetime import datetime import subprocess while True: lcd.clear() backlight.rgb(0, 255, 0) try: hostname = subprocess.check_output(['hostname']).split()[0] ip = subprocess.check_output(['hostname', '-I']).split()[0] t = '{:%H:%M:%S}'.format(datetime.now()) lcd.write(hostname) lcd.set_cursor_position(0, 1) lcd.write(ip) lcd.set_cursor_position(0, 2) lcd.write(t) except: backlight.rgb(255, 0, 0) time.sleep(1)
def stop(): p.stop() b.rgb(255,0,0) l.write("S T O P") b.graph_off()
def handle_up(ch,evt): print("Playing BBC Radio 2") l.clear() b.rgb(255,0,255) l.write("BBC Radio 2") player(radio2)
#!/usr/bin/env python import dothat.lcd as lcd import dothat.backlight as backlight from time import sleep lcd.set_cursor_position(0, 1) lcd.write('Happy Christmas!') #for x in range(50): # backlight.hue(x / 50.0) # sleep(0.05) backlight.rgb(0, 255, 0)
def handle_button(ch, evt): print("Confirm settings!") l.clear() b.rgb(255, 255, 255) settings = (int(filenum), int(shutter)) l.write('filename = %s and shutter = %s' % settings)