Toggle Navigation
Hatchery
Eggs
jNickname
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import uinterface, system, machine, time, random import rgb, buttons, defines nickname = machine.nvs_getstr('badge', 'nickname') should_set = False rgb.framerate(10) exit = 0 speed = 0.15 def set_nickname(): rgb.clear() rgb.scrolltext('Set nickname:') time.sleep(5) new_name = uinterface.text_input() if new_name is not None and new_name != '': machine.nvs_setstr('badge', 'nickname', new_name) system.start('nickname') tag = "" nick = "" colTag = (200, 200, 200) colNick = (200, 200, 200) def prep_render(): #nickname = "Paddewratje" global tag, nick global colTag, colNick data = nickname.split("]") #print("array length is {}".format(len(data))) if len(data) < 2: data.append(data[0]) data[0] = "" tag = data[0] if len(data[0]) > 0: tag = data[0] + "]" #global nick nick = data[1] print("nickame is {}, length is".format(nickname), len(nickname)) print("tag is {}, length is".format(tag), len(tag)) print("nick is {}, length is".format(nick), len(nick)) colTag = (0, 255, 0) colNick = (200, 200, 200) def reset_nickname(_): global should_set should_set = True if nickname is None or nickname == '': should_set = True # defines.BTN_UP, defines.BTN_DOWN, defines.BTN_LEFT, defines.BTN_RIGHT def callback_btn_UP(button_is_down): if button_is_down: print("callback_btn_UP") col1 = random.randrange(0, 255) col2 = random.randrange(0, 255) col3 = random.randrange(0, 255) global colTag colTag = (col1, col2, col3) print("colTag RGB is now {}, {}, {}".format(col1, col2, col3)) def callback_btn_DOWN(button_is_down): if button_is_down: print("callback_btn_DOWN") col1 = random.randrange(0, 255) col2 = random.randrange(0, 255) col3 = random.randrange(0, 255) global colNick colNick = (col1, col2, col3) print("colNick RGB is now {}, {}, {}".format(col1, col2, col3)) def callback_btn_LEFT(button_is_down): if button_is_down: print("callback_btn_LEFT") global speed speed += 0.05 #print("sleep is ".format(speed)) def callback_btn_RIGHT(button_is_down): if button_is_down: print("callback_btn_RIGHT") global speed speed -= 0.05 #print("sleep is ".format(speed)) def callback_btn_B(button_is_down): if button_is_down: print("callback_btn_B") global exit exit = 1 buttons.register(defines.BTN_UP, callback_btn_UP) buttons.register(defines.BTN_DOWN, callback_btn_DOWN) buttons.register(defines.BTN_LEFT, callback_btn_LEFT) buttons.register(defines.BTN_RIGHT, callback_btn_RIGHT) buttons.register(defines.BTN_A, reset_nickname) buttons.register(defines.BTN_B, callback_btn_B) # Because we can't use uinterface from within interrupt handlers while not exit == 1: if should_set: set_nickname() should_set = False prep_render() #render() global locTagXdefault, locTagX, locTagY, tagWidth global locNickdefault, locNickX, locNickY, nickWidth global totalWidth locTagXdefault = 30 locNickdefault = locTagXdefault + rgb.textwidth(tag + " ") locTagX = locTagXdefault locTagY = 0 locNickX = locNickdefault locNickY = 0 tagWidth = (rgb.textwidth(tag) * -1) - 10 nickWidth = (rgb.textwidth(nick) * -1) - 10 totalWidth = tagWidth + nickWidth while not exit == 1: #print("exit is ".format(exit)) rgb.clear() rgb.text(tag, colTag, (locTagX, locTagY)) rgb.text(nick, colNick, (locNickX, locNickY)) time.sleep(speed) locTagX -= 1 locNickX -= 1 if locTagX <= totalWidth: locTagX = locTagXdefault locNickX = locNickdefault time.sleep(0.15)