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 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 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 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 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 _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 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 display_row(self, row, menuEntry): lcd.set_cursor_position(1, row) if "number" in menuEntry: lcd.write("%02d. %s" % (menuEntry["number"], menuEntry["title"][:7])) lcd.set_cursor_position(11, row) lcd.write(menuEntry["duration"]) else: lcd.write(menuEntry["title"])
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 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_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 lcd_display(dict, delay=0.1): while True: try: lcd.clear() lcd.set_cursor_position(0, 0) lcd.write(selected_sensor.desc) lcd.set_cursor_position(0, 2) val = selected_sensor.value if val == "-1": backlight.rgb(255, 0, 0) else: backlight.rgb(255, 255, 255) if selected_sensor == dict[LIDAR_LEFT_TOPIC]: lcd.write(val + " mm") elif selected_sensor == dict[LIDAR_RIGHT_TOPIC]: lcd.write(val + " mm") elif selected_sensor == dict[LIDAR_FRONT_TOPIC]: lcd.write(val + " cm") elif selected_sensor == dict[LIDAR_REAR_TOPIC]: lcd.write(val + " cm") elif selected_sensor == dict[CAMERA_VALUE_TOPIC]: lcd.write(val) if val == NOT_SEEN: backlight.rgb(255, 0, 0) elif val == NOT_ALIGNED: backlight.rgb(0, 0, 255) elif val == ALIGNED: backlight.rgb(0, 255, 0) elif selected_sensor == dict[HEADING_CALIBRATION_TOPIC]: lcd.write(val.replace(" ", "", 10)) if val == CALIBRATION_BY_VALUES: backlight.rgb(0, 255, 0) elif selected_sensor == dict[HEADING_DEGREES_TOPIC]: lcd.write(val) elif selected_sensor == dict[METRICS_TOPIC]: lcd.write(val) else: lcd.write("") time.sleep(delay) except BaseException as e: logger.error("%s", e, exc_info=True) time.sleep(1)
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 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 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 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 set_state(self, state): lcd.clear() print("set_state(%s)" % state) if state == self.state_loading or state == self.state_scanning: lcd.set_cursor_position(0, 0) lcd.write("Please wait...") self.controller.display_repline_animation(0, 1) lcd.set_cursor_position(0, 2) if state == self.state_loading: lcd.write("Loading recordin") else: lcd.write("Finding tracks ") self.state = state
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 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 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 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 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 _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 run(self): # update the ip address eth0_address = [i['addr'] for i in ifaddresses("eth0").setdefault(AF_INET, [{'addr':'No IP addr'}] )] # check if internet connection try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("google.com",80)) s.close() status = " up" except: status = "dwn" lcd.clear() lcd.set_cursor_position(0,2) lcd.write(eth0_address[0]) lcd.set_cursor_position(13,2) lcd.write(status) print "update ip " + eth0_address[0] + status time.sleep(1)
def callbackfunction(self, deviceId, method, value, callbackId, context): dt = datetime.now() sdt = dt.strftime('%Y-%m-%d %H:%M') # For some reason the motion sensor sends the same event twice if (sdt == self.last_event): return self.last_event = sdt if (deviceId == 7): if (method == 1): lcd.clear() lcd.set_cursor_position(0, 0) lcd.write(sdt) backlight.rgb(0, 255, 0) self.set_leds() self.send(sdt) print sdt if (method == 2): lcd.set_cursor_position(0, 1) lcd.write('Waiting...') backlight.off() sys.stdout.flush()
def _default(): while 1: if message_lock.locked() == False: lcd.clear() if terminal_enabled != True: backlight.value = (1, 0.125, 0.125) lcd.write(terminal_locked_message) lcd.set_cursor_position(0, 2) lcd.write(unlock) else: backlight.on() lcd.write(terminal_message) lcd.set_cursor_position(0, 2) lcd.write(chr(7)) if terminal_amount > 0: lcd.write(refill) else: lcd.write(amount) terminal_amount_string = locale.format('%.2f', abs(terminal_amount), True, True) lcd.set_cursor_position( lcd.COLS - len(terminal_amount_string) - 1, 2) lcd.write(terminal_amount_string) lcd.write(chr(7)) lcd.update_animations() time.sleep(1) else: time.sleep(0.25)
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 redraw_file_exists(self): lcd.set_cursor_position(0, 0) lcd.write("Prev. file found") lcd.set_cursor_position(0, 1) lcd.write("Split or delete?") lcd.set_cursor_position(0, 2) lcd.write("DELETE SPLIT")
def redraw_recording(self): lcd.set_cursor_position(0, 0) duration = self.recorder.get_recording_duration() hours, remainder = divmod(duration.total_seconds(), 3600) minutes, seconds = divmod(remainder, 60) if hours > 0: lcd.write('{:02}:{:02}'.format(int(hours), int(minutes))) else: lcd.write('{:02}:{:02}'.format(int(minutes), int(seconds))) 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 display_scoreboard(): lcd.clear() backlight.set_graph(0.0) set_entire_backlight(0xff, 0xff, 0xff) str_score_1 = str(score_yellow).rjust(2) str_score_2 = str(score_black).ljust(2) lcd.set_cursor_position(0, 0) lcd.write('Yellow Black') lcd.set_cursor_position(0, 1) lcd.write(' ') lcd.set_cursor_position(1, 1) lcd.write(str_score_1) lcd.set_cursor_position(13, 1) lcd.write(str_score_2)
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)
#!/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)
lcd.clear() backlight.off() backlight.graph_off() sys.exit() elif command == 'reset': lcd.clear() backlight.off() backlight.graph_off() elif component == 'LCD': if command == 'clear': lcd.clear() elif command == 'setContrast': lcd.set_contrast(parameters['contrast']) elif command == 'setCursorPosition': lcd.set_cursor_position(parameters['column'], parameters['row']) elif command == 'write': lcd.write(parameters['value']) elif command == 'createCharacter': lcd.create_char(parameters['memoryPosition'], parameters['map']) elif command == 'writeCharacter': lcd.write(chr(parameters['memoryPosition'])) elif component == 'Backlight': if command == 'turnOff': backlight.off() elif command == 'setBrightnessOfLed': backlight.set(parameters['ledIndex'], parameters['brightness']) elif command == 'setToHue': backlight.hue(parameters['hue']) elif command == 'setLeftToHue': backlight.left_hue(parameters['hue'])
def set_status_lines(self, lines): lcd.clear() for i in range(min(len(lines), DotHatGadget.NUM_ROWS)): lcd.set_cursor_position(0, i) lcd.write(lines[i][:DotHatGadget.NUM_COLS])
def write_line(self,line,text): line = int(line) text = str(text)[:16] # Truncate to 16 characters lcd.set_cursor_position(0,line) lcd.write(text)