def main(): while True: disp = display.open() disp.clear().update() render_bat(disp, bat) init = True for pos in range(len(x_position)): for pixel_str in NYAN: # x,y,r,g,b x, y, r, g, b = pixel_str.split(',') x = int(x) + x_position[pos] y = int(y) + y_shift r = int(r) g = int(g) b = int(b) pix_color = create_color(r, g, b) set_pixel(disp, x, y, pix_color) # creates line-by-line rendering (kind of cool) if init: disp.update() init = False # put disp.update() here to render all at once disp.update() utime.sleep(5) disp.close()
def loop(self): colored = False try: with display.open() as disp: button_pressed = False while True: self.updateClock(disp) if self.run_once: break # check for button presses v = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) if v == 0: button_pressed = False if not button_pressed and v & buttons.BOTTOM_LEFT != 0: button_pressed = True self.setTheme(self.theme - 1) self.writeConfig() elif not button_pressed and v & buttons.BOTTOM_RIGHT != 0: button_pressed = True self.setTheme(self.theme + 1) self.writeConfig() except KeyboardInterrupt: for i in range(11): leds.set(i, (0, 0, 0)) return
def animate(): teeth = False fps = False shadow = True pressed = False ms1 = utime.time_ms() with display.open() as disp: while True: t = utime.localtime() ms0 = ms1 ms1 = utime.time_ms() % 1000 disp.clear() volt = os.read_battery() charge = (volt - 3.4) / 0.8 draw_spring(disp, charge, shadow) draw_gears(disp, t, ms1, teeth, shadow) draw_hands(disp, t, shadow) if fps: disp.print("{:.1f} fps".format(1000.0 / (ms1 - ms0)), posx=100, posy=60) disp.update() butt = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT | buttons.TOP_RIGHT) if butt == 0: pressed = False if not pressed and butt & buttons.BOTTOM_LEFT != 0: teeth = not teeth pressed = True if not pressed and butt & buttons.BOTTOM_RIGHT != 0: fps = not fps pressed = True if not pressed and butt & buttons.TOP_RIGHT != 0: shadow = not shadow pressed = True
def welcome_msg(): with display.open() as disp: disp.clear() disp.print("Press") disp.print("any key", posy=22) disp.print("to exit", posy=44) disp.update()
def main(): _brightness.start_light_sensor() while True: load_config() # setting_menu() with display.open() as _display: render_gui(_display)
def render_error(err1, err2): with display.open() as disp: disp.clear() disp.print(err1, posx=80 - round(len(err1) / 2 * 14), posy=18) disp.print(err2, posx=80 - round(len(err2) / 2 * 14), posy=42) disp.update() disp.close()
def loop(self): colored = False try: with display.open() as disp: while True: localtime = utime.localtime() self.updateClock(disp, localtime) if self.run_once: break # check for button presses v = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT | buttons.TOP_RIGHT) button_pressed = v != 0 if button_pressed and v & buttons.BOTTOM_LEFT != 0: self.setTheme(self.theme - 1) self.writeConfig() elif button_pressed and v & buttons.BOTTOM_RIGHT != 0: self.setTheme(self.theme + 1) self.writeConfig() elif button_pressed and v & buttons.TOP_RIGHT != 0: self.setTime(disp, localtime) utime.sleep_ms(23) except KeyboardInterrupt: for i in range(11): leds.set(i, (0, 0, 0)) return
def render_message(msg1, msg2): with display.open() as disp: disp.clear() disp.print(msg1, posx=80 - round(len(msg1) / 2 * 14), posy=18) disp.print(msg2, posx=80 - round(len(msg2) / 2 * 14), posy=42) disp.update() disp.close()
def main(): with display.open() as d: while True: bs = checkButtons() CTRL_FNS[MODE](bs) render(d) utime.sleep_ms(200)
def main(): disp = display.open() numstates = len(states) current, _ = personal_state.get() for ev in button_events(): if ev == buttons.BOTTOM_RIGHT: # Scroll down draw_menu(disp, current, -8) current = (current + 1) % numstates state = states[current] personal_state.set(state[1], False) elif ev == buttons.BOTTOM_LEFT: # Scroll up draw_menu(disp, current, 8) current = (current + numstates - 1) % numstates state = states[current] personal_state.set(state[1], False) elif ev == buttons.TOP_RIGHT: state = states[current] personal_state.set(state[1], True) # Select & start disp.clear().update() disp.close() os.exit(0) draw_menu(disp, current, 0)
def loop(self): try: with display.open() as disp: button_pressed = False while True: localtime = utime.localtime() disp.clear() disp = self.clock.updateClock(disp, localtime[3], localtime[4], localtime[5]) disp.update() # check for button presses v = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) if v == 0: button_pressed = False if not button_pressed and v & buttons.BOTTOM_LEFT != 0: button_pressed = True self.clock.cycleTheme(-1) elif not button_pressed and v & buttons.BOTTOM_RIGHT != 0: button_pressed = True self.clock.cycleTheme(1) sleep(self.timeout) except KeyboardInterrupt: for i in range(11): leds.set(i, (0, 0, 0)) return
def loop(shifts): shift_index = 0 last_btn_poll = utime.time() - 2 while True: pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) if utime.time() - last_btn_poll >= 1: last_btn_poll = utime.time() if pressed & buttons.BOTTOM_RIGHT != 0: shift_index = shift_index + 1 if shift_index >= len(shifts): shift_index = 0 if pressed & buttons.BOTTOM_LEFT != 0: shift_index = shift_index - 1 if shift_index < 0: shift_index = len(shifts) - 1 with display.open() as disp: disp.clear() shift = shifts[shift_index] disp.print(shift['name']) disp.print(shift['Name'], posy=20) disp.print(make_timestamp(shift['start']), posy=40) disp.print(make_timestamp(shift['end']), posy=60) disp.update() disp.close() utime.sleep(0.5)
def main(): global conf global theme global updated try: load_nickname() conf = config.Config() theme = THEMES[conf.themeid] with display.open() as d: last_secs, secs = 0, 0 last_msecs, msecs = 0, 0 while True: updated = False bs = checkButtons() saveConfig = (MODE != DISPLAY) CTRL_FNS[MODE](bs) if saveConfig and MODE == DISPLAY: conf.writeConfig() # store config on leaving settings last_secs, secs = secs, utime.time_monotonic() if updated or secs > last_secs: render(d) last_msecs, msecs = msecs, utime.time_monotonic_ms() if msecs - last_msecs < BUTTON_UPDATE_TIME: utime.sleep_ms(BUTTON_UPDATE_TIME - (msecs - last_msecs)) except KeyboardInterrupt: pass
def play(): global counter global game global DispPosition if ((DispPosition[0] + catWidth) == 159 or (DispPosition[0] == 0) or (DispPosition[1] == 0) or (DispPosition[1] + catHeight == 79)): print(counter) game = False while not game: with display.open() as disp: disp.clear() disp.print("Game Over", fg=[255, 0, 0], posy=0, posx=20) disp.print("Your Score:%s" % str(counter), posy=20, font=2) disp.print("<-New Game", posy=60, font=2) disp.update() utime.sleep(1) if buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) & buttons.BOTTOM_LEFT != 0: counter = 0 game = True DispPosition[0] = midpointX DispPosition[1] = midpointY else: if game: counter = counter + 1
def main(): image_file = open(FILENAME, "rb") magic = image_file.readline() with display.open() as disp: if magic.decode('utf-8')[:2] != "P6": disp.print('Incorrect', fg=color.WHITE, bg=color.RED) disp.print('image', fg=color.WHITE, bg=color.RED, posy=20) disp.print('format', fg=color.WHITE, bg=color.RED, posy=40) dimensions = image_file.readline() dimensions_array = dimensions.decode('utf-8').split(" ") width = dimensions_array[0] height = dimensions_array[1] max_value = image_file.readline() disp.print('Loading img', fg=color.WHITE, bg=color.BLACK) disp.print(width, fg=color.WHITE, bg=color.BLACK, posy=20) disp.print(height, fg=color.WHITE, bg=color.BLACK, posy=40) disp.update() for y in range(int(height)): for x in range(int(width)): r_string = bytes_to_int(image_file.read(1)) g_string = bytes_to_int(image_file.read(1)) b_string = bytes_to_int(image_file.read(1)) pixelColor = [r_string, g_string, b_string] disp.pixel(x, y, col=pixelColor) disp.update() disp.close() image_file.close()
def main(): create_folders() disp = display.open() applist = list_apps() numapps = len(applist) current = 0 lineoffset = 0 timerscrollspeed = 1 timerstartscroll = 5 timercountpopped = 0 for ev in button_events(10): if numapps == 0: disp.clear(color.COMMYELLOW) disp.print( " No apps ", posx=17, posy=20, fg=color.COMMYELLOW_DARK, bg=color.COMMYELLOW, ) disp.print( "available", posx=17, posy=40, fg=color.COMMYELLOW_DARK, bg=color.COMMYELLOW, ) disp.update() continue if ev == buttons.BOTTOM_RIGHT: # Scroll down current = (current + 1) % numapps lineoffset = 0 timercountpopped = 0 elif ev == buttons.BOTTOM_LEFT: # Scroll up current = (current + numapps - 1) % numapps lineoffset = 0 timercountpopped = 0 elif ev == BUTTON_TIMER_POPPED: timercountpopped += 1 if (timercountpopped >= timerstartscroll and (timercountpopped - timerstartscroll) % timerscrollspeed == 0): lineoffset += 1 elif ev == buttons.TOP_RIGHT: # Select & start disp.clear().update() disp.close() try: os.exec(applist[current][0]) except OSError as e: print("Loading failed: ", e) os.exit(1) draw_menu(disp, applist, current, numapps, lineoffset)
def __init__(self, entries): if len(entries) == 0: raise ValueError("at least one entry is required") self.entries = entries self.idx = 0 self.select_time = utime.time_ms() self.disp = display.open()
class Ui: offset = 0 highlight = 0 pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT | buttons.TOP_RIGHT) lastPressed = pressed disp = display.open()
def drawImage(self, image): with display.open() as d: d.clear() for x in range(len(image)): for y in range(len(image[x])): d.pixel(x + self.offsetx, y, col=(255, 255, 255) if image[x][y] else (0, 0, 0)) d.update()
def draw_display(): '''Draws the clock display''' # Start draw functions disp = display.open() disp.clear() display_battery_bars(disp, 0) display_time(disp, 18) display_date(disp, 50) disp.update()
def main(): light_sensor.start() with display.open() as d: while True: bs = checkButtons() CTRL_FNS[MODE](bs) ctrl_backlight(d) render(d) utime.sleep_ms(200)
def main(): light_sensor.start() with display.open() as d: while True: bs = check_buttons() CTRL_FNS[MODE](bs) if MODE == DISPLAY: render_every_second(d) else: render(d)
def main(): try: detect_workaround_offset() load_nickname() with display.open() as d: while True: bs = checkButtons() CTRL_FNS[MODE](bs) render(d) except KeyboardInterrupt: pass
def loop(self): colored = False try: with display.open() as disp: while True: self.updateClock(disp) if self.run_once: break except KeyboardInterrupt: for i in range(11): leds.set(i, (0, 0, 0)) return
def __init__(self, entries): if len(entries) == 0: raise ValueError("at least one entry is required") self.entries = entries self.idx = 0 self.select_time = utime.time_ms() self.disp = display.open() self.button_scroll_up = (buttons.TOP_RIGHT if self.right_buttons_scroll else buttons.BOTTOM_LEFT) self.button_select = (buttons.BOTTOM_LEFT if self.right_buttons_scroll else buttons.TOP_RIGHT)
def render_error(err1, err2): """ Function to render two lines of text (each max 11 chars). Useful to display error messages :param err1: line one :param err2: line two """ with display.open() as disp: disp.clear() disp.print(err1, posx=80 - round(len(err1) / 2 * 14), posy=18) disp.print(err2, posx=80 - round(len(err2) / 2 * 14), posy=42) disp.update() disp.close()
def compass(): disp = display.open() sensor = bhi160.BHI160Orientation() while True: samples = sensor.read() if len(samples) > 0: disp.clear() sample = samples[0] draw_scale(disp, 80, 40) draw_needle(disp, 80, 40, sample.x) disp.update() utime.sleep(0.1)
def main(): light_sensor.start() with display.open() as d: while True: bs = check_buttons() CTRL_FNS[MODE](bs) if MODE == DISPLAY: render( d ) #update continously, TODO: check for current consumption increase #render_every_second(d)#update clock every second else: render(d)
def draw_cat(X, Y): with display.open() as disp: disp.clear() for y, row in enumerate(SIZER): if (right == True): for x, p in enumerate(row): if p: disp.pixel(X + x, Y + y, col=HCOLORS[p]) else: for x, p in enumerate(row[::-1]): if p: disp.pixel(X + x, Y + y, col=HCOLORS[p]) disp.update()
def calibrate(): global Orientation # samples = sensors[sensor]["sensor"].read() if len(samples) > 0: vibra.vibrate(40) sample = samples[0] Orientation[2] = sample.z Orientation[1] = sample.y with display.open() as disp: disp.clear() disp.print("Calibration successful", posy=20) disp.update() utime.sleep(1)