def playMusic(stopTime=99999): global noteCount, notes index = 0 startTime = utime.ticks_ms() while True: # Stop playing if index >= noteCount or buttons.is_pressed(Buttons.BTN_A): speaker.stop() break # How long have we been playing for currentTime = utime.ticks_ms() timeDiff = currentTime - startTime # End early if told if timeDiff > stopTime: speaker.stop() break # Play note note = notes[index] if timeDiff > (note['time'] * 1000): if 'midi' in note: freq = 27.5 * pow(2, (note['midi'] - 21) / 12) speaker.frequency(round(freq)) else: speaker.stop() index += 1 sleep_or_exit(0.1)
given_name = homescreen.name("Set your name in the settings app") if len(given_name) <= max_name: ugfx.set_default_font(ugfx.FONT_NAME) else: ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD) # Draw name ugfx.Label(0, ugfx.height() - name_height, ugfx.width(), name_height, given_name, justification=ugfx.Label.CENTER) # Draw for the user to see ugfx.orientation(270) ugfx.set_default_font(ugfx.FONT_SMALL) # WiFi/Battery update loop while True: ugfx.area(0, ugfx.height() - info_height, ugfx.width(), info_height, ugfx.WHITE) wifi_strength_value = homescreen.wifi_strength() if wifi_strength_value: wifi_message = 'WiFi: %s%%' % int(wifi_strength_value) wifi_text = ugfx.text(center[0], ugfx.height() - info_height, wifi_message, ugfx.BLACK) battery_value = homescreen.battery() if battery_value: battery_message = 'Battery: %s%%' % int(battery_value) battery_text = ugfx.text(0, ugfx.height() - info_height, battery_message, ugfx.BLACK) homescreen.sleep_or_exit(1.5) restart_to_default()
ugfx.text(5, 5, ">", ugfx.BLACK) url = json.loads( http.get( "https://e621.net/post/index.json?limit=1&tags=order:random", headers={ "User-Agent": "TiLDA MK4 (itlin)" }).content)[0]["file_url"] ugfx.text(5, 5, ">>", ugfx.BLACK) ugfx.text(5, 5, ">>", ugfx.GREEN) print(url[-3:]) if url[-3:] == "png": print("png") ugfx.display_image( 0, 0, bytearray( http.get( "https://process.filestackapi.com/AhTgLagciQByzXpFGRI0Az/resize=width:240,height:320,fit:crop/rotate=deg:180/" + url).raise_for_status().content)) else: print("jpg") ugfx.display_image( 0, 0, bytearray( http.get( "https://process.filestackapi.com/AhTgLagciQByzXpFGRI0Az/resize=width:240,height:320,fit:crop/rotate=deg:180/output=format:png/" + url).raise_for_status().content)) except (OSError, ValueError) as e: print(e) ugfx.text(5, 5, ">>", ugfx.RED) sleep_or_exit(1)
enableLights = False enableScroll = True while True: # Toggle lights if buttons.is_triggered(Buttons.BTN_B): enableLights = not enableLights neopix.display([0, 0]) # Lights off # Play music elif buttons.is_triggered(Buttons.BTN_A): neopix.display([0, 0]) # Lights off drawTutorial() drawLogo() playMusic() # Toggle scroll elif buttons.is_triggered(Buttons.JOY_Center): enableScroll = not enableScroll if not enableScroll: blankScreen() drawLogo() else: if enableLights: doLights() if enableScroll: doScroll() sleep_or_exit(0.1)