def draw_leds(vmin, vmax): # vmin should be in [0, -1] # vmax should be in [0, 1] global pulse, samples_since_last_pulse, last_pulse_blink # stop blinking if not bool(led_mode): return # update led bar if "bar" in led_mode: for i in reversed(range(6)): leds.prep_hsv( 5 + i, COLORS[5 + i] if vmin <= 0 and i <= vmin * -6 else (0, 0, 0)) for i in reversed(range(6)): leds.prep_hsv( i, COLORS[i] if vmax >= 0 and 5 - i <= vmax * 6 else (0, 0, 0)) # blink red on pulse if ("pulse" in led_mode and pulse > 0 and samples_since_last_pulse < last_pulse_blink): for i in range(4): leds.prep(11 + i, (255, 0, 0)) elif "pulse" in led_mode: for i in range(4): leds.prep(11 + i, (0, 0, 0)) last_pulse_blink = samples_since_last_pulse leds.update()
def update_leds(batteryLevel): lastIndex = round(batteryLevel * 11) for i in range(0, lastIndex): leds.prep(10 - i, [0, brightness, 0]) for i in range(lastIndex, 11): leds.prep(10 - i, [brightness, 0, 0])
def pov_char(char, reverse=False): if reverse: col_seq = font[char][::-1] else: col_seq = font[char] for col in col_seq: for i in range(8): if masks[i] & col: leds.prep(i + 1, color.GREEN) else: leds.prep(i + 1, color.BLACK) leds.update() utime.sleep(0.0025) for i in range(8): leds.prep(i + 1, color.BLACK) leds.update() utime.sleep(0.0025)
def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg): anim = 0 posy = 30 if sub != '': posy = 18 r = 255 g = 0 b = 0 r_sub = sub last_btn_poll = utime.time() - 2 while True: sleep = 0.5 if sub == '#time': r_sub = get_time() dark = 0 if light_sensor.get_reading() < 40: dark = 1 r_fg_color = fg[dark] r_bg_color = bg[dark] r_fg_sub_color = fg_sub[dark] r_bg_sub_color = bg_sub[dark] r_bg = main_bg[dark] # Button handling 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: anim = anim + 1 if anim >= len(ANIM_TYPES): anim = 0 if pressed & buttons.BOTTOM_LEFT != 0: anim = anim - 1 if anim < 0: anim = len(ANIM_TYPES) - 1 # Animations if ANIM_TYPES[anim] == 'fade': sleep = 0.1 leds.clear() toggle_rockets(False) if r > 0 and b == 0: r = r - 1 g = g + 1 if g > 0 and r == 0: g = g - 1 b = b + 1 if b > 0 and g == 0: r = r + 1 b = b - 1 r_bg = [r, g, b] r_bg_color = r_bg r_bg_sub_color = r_bg if ANIM_TYPES[anim] == 'led': if dark == 1: for i in range(0, 11): leds.prep(i, r_bg) leds.update() leds.dim_top(4) toggle_rockets(True) else: leds.clear() toggle_rockets(False) if ANIM_TYPES[anim] == 'gay': toggle_rockets(False) leds.gay(0.4) if ANIM_TYPES[anim] == 'none': leds.clear() toggle_rockets(False) with display.open() as disp: disp.rect(0, 0, 160, 80, col=r_bg, filled=True) disp.print(title, fg=r_fg_color, bg=r_bg_color, posx=80 - round(len(title) / 2 * 14), posy=posy) if r_sub != '': disp.print(r_sub, fg=r_fg_sub_color, bg=r_bg_sub_color, posx=80 - round(len(r_sub) / 2 * 14), posy=42) disp.update() disp.close() utime.sleep(sleep)
def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat): """ Main function to render the nickname on screen. Pretty ugly but not time for cleanup right now (and some APIs missing) :param title: first row of text :param sub: second row of text :param fg: tuple of (day, night) rgb for title text color :param bg: tuple of (day, night) rgb for title background color :param fg_sub: tuple of (day, night) rgb for subtitle text color :param bg_sub: tuple of (day, night) rgb for subtitle background color :param main_bg: tuple of (day, night) rgb for general background color :param mode: default animation to start in (index of ANIM_TYPES array) :param bat: battery config tuple (boolean: indicator on/off, array: good rgb, array: ok rgb, array: bad rgb) """ anim = mode posy = 30 if sub != "": posy = 18 r = 255 g = 0 b = 0 rainbow_led_pos = 0 r_sub = sub last_btn_poll = utime.time() - 2 while True: sleep = 0.5 if sub == "#time": r_sub = get_time() dark = 0 if light_sensor.get_reading() < 30: dark = 1 r_fg_color = fg[dark] r_bg_color = bg[dark] r_fg_sub_color = fg_sub[dark] r_bg_sub_color = bg_sub[dark] r_bg = main_bg[dark] # Button handling 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: anim = anim + 1 if anim >= len(ANIM_TYPES): anim = 0 blink_led(0) if pressed & buttons.BOTTOM_LEFT != 0: anim = anim - 1 if anim < 0: anim = len(ANIM_TYPES) - 1 blink_led(0) # Animations if ANIM_TYPES[anim] == "fade": sleep = 0.1 leds.clear() toggle_rockets(False) if r > 0 and b == 0: r -= 1 g += 1 if g > 0 and r == 0: g -= 1 b += 1 if b > 0 and g == 0: r += 1 b -= 1 r_bg = [r, g, b] r_bg_color = r_bg r_bg_sub_color = r_bg if ANIM_TYPES[anim] == "led": if dark == 1: for i in range(0, 11): leds.prep(i, r_bg) leds.update() leds.dim_top(4) toggle_rockets(True) else: leds.clear() toggle_rockets(False) if ANIM_TYPES[anim] == "rnd_led": if dark == 1: for i in range(0, 11): leds.prep(i, random_rgb()) leds.update() leds.dim_top(4) toggle_rockets(True) else: leds.clear() toggle_rockets(False) if ANIM_TYPES[anim] == "gay": toggle_rockets(False) leds.gay(0.4) if ANIM_TYPES[anim] == "rainbow": for i in range(0, 11): lr, lg, lb = wheel(rainbow_led_pos + i * 3) leds.prep(i, [lr, lg, lb]) rainbow_led_pos += 1 if rainbow_led_pos > 255: rainbow_led_pos = 0 leds.update() leds.dim_top(3) toggle_rockets(True) if ANIM_TYPES[anim] == "none": leds.clear() toggle_rockets(False) with display.open() as disp: disp.rect(0, 0, 160, 80, col=r_bg, filled=True) if bat[0]: render_battery(disp, bat) disp.print( title, fg=r_fg_color, bg=r_bg_color, posx=80 - round(len(title) / 2 * 14), posy=posy, ) if r_sub != "": disp.print( r_sub, fg=r_fg_sub_color, bg=r_bg_sub_color, posx=80 - round(len(r_sub) / 2 * 14), posy=42, ) disp.update() disp.close() utime.sleep(sleep)
def check_Border(): # Q = [0,0] # Q[0] = DispPosition[0]/6 # Berrechnung des X Quadranten # Q[1] = DispPosition[1]/6 # Berrechnung des Y Quadranten # ColorValues = [[255,186,255], [222,135,255], [164,85,255], [104,29,255], [16,0,202], [0,0,152]] # if (Q[0] >= 0 and Q[0] <= 3.34): # leds.prep(14, []) if DispPosition[0] > 120: leds.prep(12, [255, 0, 0]) leds.prep(13, [255, 0, 0]) elif DispPosition[0] < 10: leds.prep(11, [255, 0, 0]) leds.prep(14, [255, 0, 0]) else: leds.prep(12, [0, 0, 0]) leds.prep(13, [0, 0, 0]) if DispPosition[1] < 10: leds.prep(13, [255, 0, 0]) leds.prep(14, [255, 0, 0]) elif DispPosition[1] > 60: leds.prep(11, [255, 0, 0]) leds.prep(12, [255, 0, 0]) else: leds.prep(12, [0, 0, 0]) leds.prep(14, [0, 0, 0]) leds.update()
import math import leds import utime import os while True: # leds.set_all(os.urandom(3)) for i in range(0, 11): leds.prep(i, os.urandom(3)) leds.update() utime.sleep_ms(5)
while True: # reset if button pressed pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) if pressed & buttons.BOTTOM_LEFT != 0: highest = 0 # read accel samples = bhi.read() if len(samples) == 0: utime.sleep(0.25) continue for val in samples: complete = abs(val.x) + abs(val.y) + abs(val.z) - 1 if complete > highest: highest = complete # update display disp.clear() disp.print("Slap force:", posy=0, fg=[255, 255, 255]) disp.print("<- reset", posy=60, fg=[255, 0, 0]) disp.print(str(highest), posy=20, posx=20, fg=[255, 255, 255]) disp.update() # Update LEDs color = [0, 255, 0] if highest < 3 else [255, 0, 0] for i in range(0, 11): if highest * 2 < i: color = [0, 0, 0] leds.prep(10 - i, color) leds.update() utime.sleep(0.25)
def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg): anim = 'led' posy = 30 if sub != '': posy = 18 r = 255 g = 0 b = 0 while True: dark = 0 if light_sensor.get_reading() < 30: dark = 1 r_fg_color = fg[dark] r_bg_color = bg[dark] r_fg_sub_color = fg_sub[dark] r_bg_sub_color = bg_sub[dark] r_bg = main_bg[dark] if anim == 'fade': if r > 0 and b == 0: r = r - 1 g = g + 1 if g > 0 and r == 0: g = g - 1 b = b + 1 if b > 0 and g == 0: r = r + 1 b = b - 1 r_bg = [r, g, b] if anim == 'led': for i in range(0, 11): leds.prep(i, r_bg) leds.update() leds.dim_top(3) leds.set_rocket(0, 15) leds.set_rocket(1, 15) leds.set_rocket(2, 15) if anim == 'none': leds.clear() leds.set_rocket(0, 0) leds.set_rocket(1, 0) leds.set_rocket(2, 0) with display.open() as disp: disp.rect(0, 0, 160, 80, col=r_bg, filled=True) disp.print(title, fg=r_fg_color, bg=r_bg_color, posx=80 - round(len(title) / 2 * 14), posy=posy) if sub != '': disp.print(sub, fg=r_fg_sub_color, bg=r_bg_sub_color, posx=80 - round(len(sub) / 2 * 14), posy=42) disp.update() disp.close() pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) if pressed & buttons.BOTTOM_LEFT != 0: anim = ANIM_TYPES[1] if pressed & buttons.BOTTOM_RIGHT != 0: anim = ANIM_TYPES[0] utime.sleep(0.3)
zeile1 = [1, 2, 2, 1, 1, 1, 1, 1, 2, 2, 1] zeile2 = [2, 2, 2, 2, 1, 1, 1, 2, 2, 2, 2] feld = [ zeile1, zeile2, [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2], [2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2], [2, 3, 4, 3, 3, 3, 3, 3, 4, 3, 2], [2, 3, 3, 3, 4, 3, 4, 3, 3, 3, 2], [2, 2, 3, 3, 4, 4, 4, 3, 3, 2, 2], [1, 2, 2, 3, 3, 3, 3, 3, 2, 2, 1], [1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1], ] while True: for zeilenindex, zeile in enumerate(feld): for lama, colorcode in enumerate(zeile): if 1 == colorcode: leds.prep(lama, htmlcolor.RED) if 2 == colorcode: leds.prep(lama, htmlcolor.BLUE) if 3 == colorcode: leds.prep(lama, htmlcolor.WHITE) if 4 == colorcode: leds.prep(lama, htmlcolor.BLACK) leds.update() utime.sleep(0.004)