def update(self): if self.type == 1: if Buttons.is_pressed(Buttons.BTN_Hash): self.needsRedraw = True self.previousX = self.x self.x += self.moveSpeed if Buttons.is_pressed(Buttons.BTN_Star): self.needsRedraw = True self.previousX = self.x self.x -= self.moveSpeed if self.type == 0: if Buttons.is_pressed(Buttons.BTN_3): self.needsRedraw = True self.previousX = self.x self.x += self.moveSpeed if Buttons.is_pressed(Buttons.BTN_1): self.needsRedraw = True self.previousX = self.x self.x -= self.moveSpeed if self.x + self.width/2 > SCREEN_WIDTH: self.x = SCREEN_WIDTH - self.width/2 if self.x -self.width/2 < 0: self.x = self.width/2
def wifi_select(): msg("Please select your wifi\nConfirm with button A") sl = ugfx.List(5, 110, 228, 204) aps = {} while not Buttons.is_pressed(Buttons.BTN_A): for s in (wifi.scan() or []): if s[0] not in aps: sl.add_item(s[0]) aps[s[0]] = s time.sleep(0.01) ugfx.poll() ssid = sl.selected_text() sl.destroy() msg("Wifi: %s\nPlease enter your password\nConfirm with button A" % ssid) kb = ugfx.Keyboard(0, 160, 240, 170) e = ugfx.Textbox(5, 130, 228, 25, text="") while not Buttons.is_pressed(Buttons.BTN_A): time.sleep(0.01) ugfx.poll() pw = e.text() e.destroy() kb.destroy() result = {"ssid": ssid, "pw": pw} with open("wifi.json", "wt") as file: file.write(json.dumps(result)) file.flush() os.sync() return result
def display_help(): global start_time ugfx.display_image(0, 0, "shared/sequencer_info.png") wait_until = time.ticks_ms() + 5000 while time.ticks_ms() < wait_until: time.sleep(0.1) if Buttons.is_pressed(Buttons.BTN_A) or Buttons.is_pressed(Buttons.BTN_B) or Buttons.is_pressed(Buttons.BTN_Menu): break start_time = time.ticks_ms()
def show_card(): url = database.get(DB_KEY_CARD) if url: try: with dialogs.WaitingMessage("Loading data...", title=APP_TITLE): image = http.get(url).raise_for_status().content ugfx.display_image(0, 0, bytearray(image)) while ((not Buttons.is_pressed(Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu))): sleep.wfi() except Exception as ex: dialogs.notice(repr(ex), title="%s - Download failed" % APP_TITLE) else: dialogs.notice("Please answer the questions first", title=APP_TITLE) show_menu()
def show_manual(): ugfx.clear(APP_COLOUR) window = ugfx.Container(0, 0, ugfx.width(), ugfx.height()) window.show() window.text(5, 10, "TiNDA: Dating app for TiLDA", ugfx.BLACK) window.text(5, 30, "Find your perfect EMF match", ugfx.BLACK) window.line(0, 50, ugfx.width(), 50, ugfx.BLACK) window.text(5, 60, "Step 1: Answer all questions", ugfx.BLACK) window.text(5, 80, "and receive an emoji card.", ugfx.BLACK) window.text(5, 110, "Step 2: Compare cards with", ugfx.BLACK) window.text(5, 130, "other people and count", ugfx.BLACK) window.text(5, 150, "matching emoji.", ugfx.BLACK) window.text(5, 180, "Step 3: <3", ugfx.BLACK) while ((not Buttons.is_pressed(Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu))): sleep.wfi()
def runGame(): paddle = Paddle() direction = random.random() - 0.5 initial_speed_up = 4 ball = Ball(x=SCREEN_WIDTH / 2, y=SCREEN_HEIGHT / 2, dx=math.cos(direction) * initial_speed_up, dy=math.sin(direction) * initial_speed_up) blocks = \ [Block(x = x, y = 30, width = 36, height = 10, colour = ugfx.RED) for x in range(24, SCREEN_WIDTH - 24, 40)] + \ [Block(x = x, y = 44, width = 36, height = 10, colour = ugfx.GREEN) for x in range(24, SCREEN_WIDTH - 24, 40)] + \ [Block(x = x, y = 58, width = 36, height = 10, colour = ugfx.BLUE) for x in range(24, SCREEN_WIDTH - 24, 40)] + \ [Block(x = x, y = 72, width = 36, height = 10, colour = ugfx.YELLOW) for x in range(24, SCREEN_WIDTH - 24, 40)] + \ [Block(x = x, y = 86, width = 36, height = 10, colour = ugfx.ORANGE) for x in range(24, SCREEN_WIDTH - 24, 40)] def invisibleBlocks(): return [block for block in blocks if not (block.visible)] for block in blocks: block.draw() while True: paddle.draw() ball.draw() time.sleep(1.0 / framerate) paddle.clear() ball.clear() paddle.tick() ball.tick() if Buttons.is_pressed(Buttons.BTN_Menu): gameRunning = False if all([not (block.visible) for block in blocks]): gameEnd(score=50 + len(invisibleBlocks())) break if ball.hasHitTop(paddle): if ball.hasCollidedWith(paddle): ball.bounceUpwards(ball.horizontalPositionFromMiddle(paddle)) else: gameOver(score=len(invisibleBlocks())) break for block in blocks: if block.visible and ball.hasCollidedWith(block): block.hide() if ball.isHorizontalCollision(block): ball.bounceX() if ball.isVerticalCollision(block): ball.bounceY()
i = 0 j = 0 ugfx.clear() dialogs.notice( "Draw with joystick arrows\nHold joystick centre for circle\nA to clear\nMENU to choose colour\nB to exit", title="Sketchy-Etch") ugfx.area(0, 0, ugfx.width(), maxHeight, ugfx.BLACK) showColourChangeMenu() circleSize = 3 reset() colour = ugfx.WHITE while not Buttons.is_pressed(Buttons.BTN_B): changed = False oldI = i oldJ = j if Buttons.is_pressed(Buttons.JOY_Right) and (i < (ugfx.width() - 1)): i += 1 changed = True elif Buttons.is_pressed(Buttons.JOY_Left) and (i > 0): i -= 1 changed = True if Buttons.is_pressed(Buttons.JOY_Down) and (j < (maxHeight - 1)): j += 1 changed = True elif Buttons.is_pressed(Buttons.JOY_Up) and (j > 0):
import ugfx, wifi, app from tilda import Buttons from time import sleep status_height = 20 ssid = 'emfcamp-legacy18' ugfx.init() ugfx.clear() ugfx.set_default_font(ugfx.FONT_FIXED) ugfx.Label(5, 180, 240, 15, "Press A to scan, MENU to exit") # while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed(Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu)): while not Buttons.is_pressed(Buttons.BTN_Menu): if not Buttons.is_pressed(Buttons.BTN_A) and not Buttons.is_pressed( Buttons.BTN_B): ugfx.poll() continue if Buttons.is_pressed(Buttons.BTN_B): ugfx.clear() ugfx.Label(0, 0, 240, 25, "SSID:") ssid_box = ugfx.Textbox(0, 25, 240, 25, text=ssid) ugfx.Keyboard(0, ugfx.height() // 2, ugfx.width(), ugfx.height() // 2) ssid_box.set_focus() while not Buttons.is_pressed(Buttons.BTN_A): ugfx.poll() continue ssid = ssid_box.text()
ugfx.orientation(270) # Title ugfx.set_default_font(ugfx.FONT_TITLE) ugfx.Label(0, ugfx.height() - info_height * 2, ugfx.width(), info_height, "TiLDA Mk4", justification=ugfx.Label.CENTER) # info ugfx.Label(0, ugfx.height() - info_height, ugfx.width(), info_height, "Press MENU", justification=ugfx.Label.CENTER) ugfx.set_default_font(ugfx.FONT_SMALL) status = ugfx.Label(0, ugfx.height() - info_height * 2 - status_height, ugfx.width(), status_height, "", justification=ugfx.Label.CENTER) # update loop while True: text = ""; value_wifi_strength = wifi_strength() value_battery = battery() if value_wifi_strength: text += "Wi-Fi: %s%%, " % int(value_wifi_strength) if value_battery: text += "Battery: %s%%" % int(value_battery) status.text(text) if Buttons.is_pressed(Buttons.BTN_Star): if torch_on: torch_on = False torch.off() neo.display([0,0]) else: torch_on = True torch.on() neo.display([0xffffff,0xffffff]) sleep_or_exit(0.5)
mode = BACKFACECULL last_polygons = [] last_mode = WIREFRAME # Main loop run = True while run: gc.collect() # Render the scene render(mode, calculateRotation(smoothing, None)) # Button presses y_rotation += 5 x_rotation += 3 z_rotation += 1 if Buttons.is_pressed(Buttons.JOY_Left): y_rotation -= 5 if Buttons.is_pressed(Buttons.JOY_Right): y_rotation += 5 if Buttons.is_pressed(Buttons.JOY_Center): y_rotation = 0 if Buttons.is_pressed(Buttons.BTN_B): selected += 1 if selected >= len(objects): selected = 0 loadObject(objects[selected]) time.sleep_ms( 500 ) # Wait a while to avoid skipping ahead if the user still has the button down if Buttons.is_pressed(Buttons.BTN_A): mode += 1
## # MAIN RUNLOOP # init() if check_warning(): _LABEL = init_label() fetch_and_display() while True: sleep.wfi() if Buttons.is_pressed(Buttons.BTN_A): fetch_and_display() elif Buttons.is_pressed( Buttons.BTN_Menu ) or \ Buttons.is_pressed( Buttons.BTN_B ) or \ Buttons.is_pressed( Buttons.JOY_Center): break # print ("Stories ded...") if _LABEL: _LABEL.destroy() ugfx.clear()
def one_round(): grid_size = 8 body_colour = ugfx.RED back_colour = 0 food_colour = ugfx.YELLOW wall_colour = ugfx.BLUE score = 0 edge_x = math.floor(ugfx.width() / grid_size) - 2 edge_y = math.floor(ugfx.height() / grid_size) - 2 def disp_square(x, y, colour): ugfx.area((x + 1) * grid_size, (y + 1) * grid_size, grid_size, grid_size, colour) def disp_body_straight(x, y, rotation, colour): if (rotation == 0): ugfx.area((x + 1) * grid_size + 1, (y + 1) * grid_size + 1, grid_size - 2, grid_size, colour) elif (rotation == 90): ugfx.area((x + 1) * grid_size + 1, (y + 1) * grid_size + 1, grid_size, grid_size - 2, colour) elif (rotation == 180): ugfx.area((x + 1) * grid_size + 1, (y + 1) * grid_size - 1, grid_size - 2, grid_size, colour) else: ugfx.area((x + 1) * grid_size - 1, (y + 1) * grid_size + 1, grid_size, grid_size - 2, colour) def disp_eaten_food(x, y, colour): ugfx.area((x + 1) * grid_size, (y + 1) * grid_size, grid_size, grid_size, colour) def randn_square(): return [random.randrange(edge_x), random.randrange(edge_y)] body_x = [12, 13, 14, 15, 16] body_y = [2, 2, 2, 2, 2] ugfx.area(0, 0, ugfx.width(), ugfx.height(), 0) ugfx.area(0, 0, grid_size * (edge_x + 1), grid_size, wall_colour) ugfx.area(0, 0, grid_size, grid_size * (edge_y + 1), wall_colour) ugfx.area(grid_size * (edge_x + 1), 0, grid_size, grid_size * (edge_y + 1), wall_colour) ugfx.area(0, grid_size * (edge_y + 1), grid_size * (edge_x + 2), grid_size, wall_colour) keepgoing = 1 food = [20, 20] disp_square(food[0], food[1], food_colour) dir_x = 1 dir_y = 0 orient = 270 #for i in range(0,len(body_x)): # disp_body_straight(body_x[i],body_y[i],orient,body_colour) while keepgoing: if dir_x != -1 and (Buttons.is_pressed(Buttons.JOY_Right) or Buttons.is_pressed(Buttons.BTN_6)): dir_x = 1 dir_y = 0 orient = 270 elif dir_x != 1 and (Buttons.is_pressed(Buttons.JOY_Left) or Buttons.is_pressed(Buttons.BTN_4)): dir_x = -1 dir_y = 0 orient = 90 elif dir_y != -1 and (Buttons.is_pressed(Buttons.JOY_Down) or Buttons.is_pressed(Buttons.BTN_8)): dir_y = 1 dir_x = 0 orient = 180 elif dir_y != 1 and (Buttons.is_pressed(Buttons.JOY_Up) or Buttons.is_pressed(Buttons.BTN_0)): dir_y = -1 dir_x = 0 orient = 0 body_x.append(body_x[-1] + dir_x) body_y.append(body_y[-1] + dir_y) for i in range(0, len(body_x) - 1): if (body_x[i] == body_x[-1]) and (body_y[i] == body_y[-1]): keepgoing = 0 if not ((body_x[-1] == food[0]) and (body_y[-1] == food[1])): x_del = body_x.pop(0) y_del = body_y.pop(0) disp_eaten_food(x_del, y_del, back_colour) else: disp_eaten_food(food[0], food[1], body_colour) food = randn_square() disp_square(food[0], food[1], food_colour) score = score + 1 disp_body_straight(body_x[-1], body_y[-1], orient, body_colour) if ((body_x[-1] >= edge_x) or (body_x[-1] < 0) or (body_y[-1] >= edge_y) or (body_y[-1] < 0)): break sleep.sleep(0.1) return score
ugfx.set_default_font(ugfx.FONT_FIXED) def instructions(duration): ugfx.Label(5, 180, 240, 30, "Press A to start, B to change scan length or MENU to exit") ugfx.Label(5, 210, 240, 15, "Scan requires ~{0} seconds".format(duration)) if not sim800.btison(): sim800.btpoweron() btrestore = True instructions(duration) # while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed(Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu)): while not Buttons.is_pressed(Buttons.BTN_Menu): a = Buttons.is_pressed(Buttons.BTN_A) b = Buttons.is_pressed(Buttons.BTN_B) if not a and not b: ugfx.poll() continue if b: duration = duration + 5 if duration > 60: duration = 5 ugfx.clear() instructions(duration) continue ugfx.clear()
def selectColour(): global shades global hues global scroll global huesToShow global colourI global colourJ global maxHeight boxHeight = int((ugfx.height() - maxHeight) / huesToShow) boxWidth = int(ugfx.width() / shades) (r, g, b) = getColour(colourI / shades, colourJ / hues) ugfx.box(colourI * boxWidth, maxHeight + ((colourJ - scroll) * boxHeight), boxWidth, boxHeight, (int(31 * (1 - r)) << 11) + (int(63 * (1 - g)) << 5) + int(31 * (1 - b))) while not Buttons.is_pressed(Buttons.JOY_Center): positionChanged = False scrollChanged = False oldI = colourI oldJ = colourJ if Buttons.is_pressed(Buttons.JOY_Right) and (colourI < (shades - 1)): colourI += 1 positionChanged = True while Buttons.is_pressed(Buttons.JOY_Right): pass elif Buttons.is_pressed(Buttons.JOY_Left) and (colourI > 0): colourI -= 1 positionChanged = True while Buttons.is_pressed(Buttons.JOY_Left): pass if Buttons.is_pressed(Buttons.JOY_Down) and (colourJ < (hues - 1)): if (colourJ - scroll) == 1: scroll += 1 scrollChanged = True colourJ += 1 positionChanged = True while Buttons.is_pressed(Buttons.JOY_Down): pass elif Buttons.is_pressed(Buttons.JOY_Up) and (colourJ > 0): if (colourJ - scroll) == 0: scroll -= 1 scrollChanged = True colourJ -= 1 positionChanged = True while Buttons.is_pressed(Buttons.JOY_Up): pass if scrollChanged or positionChanged: if scrollChanged: showColourChangeMenu() elif positionChanged: (r, g, b) = getColour(oldI / shades, oldJ / hues) ugfx.box(oldI * boxWidth, maxHeight + ((oldJ - scroll) * boxHeight), boxWidth, boxHeight, (int(31 * r) << 11) + (int(63 * g) << 5) + int(31 * b)) (r, g, b) = getColour(colourI / shades, colourJ / hues) ugfx.box(colourI * boxWidth, maxHeight + ((colourJ - scroll) * boxHeight), boxWidth, boxHeight, (int(31 * (1 - r)) << 11) + (int(63 * (1 - g)) << 5) + int(31 * (1 - b))) sleep(0.05) while Buttons.is_pressed(Buttons.JOY_Center): pass (r, g, b) = getColour(colourI / shades, colourJ / hues) ugfx.box(colourI * boxWidth, maxHeight + ((colourJ - scroll) * boxHeight), boxWidth, boxHeight, (int(31 * r) << 11) + (int(63 * g) << 5) + int(31 * b)) return (int(31 * r) << 11) + (int(63 * g) << 5) + int(31 * b)
___dependencies___ = ["ugfx_helper"] ___categories___ = ["Games"] import ugfx, ugfx_helper, app from tilda import Buttons from time import sleep ugfx_helper.init() ugfx.clear() ugfx.area(0, 0, ugfx.width(), ugfx.height(), ugfx.BLACK) i = int(ugfx.width() / 2) j = int(ugfx.height() / 2) while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed(Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu)): changed = False if Buttons.is_pressed(Buttons.JOY_Right) and (i < (ugfx.width() - 1)): i += 1 changed = True elif Buttons.is_pressed(Buttons.JOY_Left) and (i > 0): i -= 1 changed = True if Buttons.is_pressed(Buttons.JOY_Down) and (j < (ugfx.height() - 1)): j += 1 changed = True elif Buttons.is_pressed(Buttons.JOY_Up) and (j > 0): j -= 1 changed = True
if simphonenumber == None or len(simphonenumber) == 0: ugfx.Label(5, 155, 240, 15, "No Number Yet") else: ugfx.Label(5, 155, 240, 15, simphonenumber) if simoperator == None or len(simoperator) == 0: ugfx.Label(5, 170, 240, 15, "No Operator Yet") else: ugfx.Label(5, 170, 240, 15, "Your network is " + simoperator) ugfx.Label(5, 185, 240, 15, simversion) ugfx.Label(5, 300, 240, 15, "** Hold A or B or MENU to exit **") while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed( Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu)): ugfx.Label( 5, 5, 240, 15, "Temperature (tmp) : {:.2f} C".format(Sensors.get_tmp_temperature())) ugfx.Label( 5, 20, 240, 15, "Temperature (hdc) : {:.2f} C".format(Sensors.get_hdc_temperature())) ugfx.Label( 5, 35, 240, 15, "Humidity (hdc) : {:.2f} %".format(Sensors.get_hdc_humidity())) ugfx.Label(5, 50, 240, 15, "Light (opt) : {:.2f} Lux".format(Sensors.get_lux())) ugfx.Label(5, 65, 240, 15, "Mag Field: (drv) : {:.2f} ".format(mag.convert()))
def tick(self): if Buttons.is_pressed( Buttons.JOY_Right) and self.right() < SCREEN_WIDTH: self.x += self.dx if Buttons.is_pressed(Buttons.JOY_Left) and self.left() > 0: self.x -= self.dx
"shared/nyan/3.png", "shared/nyan/4.png", "shared/nyan/5.png"] ___categories___ = ["Homescreens", "Other"] import ugfx_helper, os, wifi, ugfx, http, time, sleep, app from tilda import Buttons # initialize screen ugfx_helper.init() ugfx.clear(ugfx.BLACK) ugfx.backlight(100) n = 0 r = 270 while True: ugfx.display_image( 0, 90, "shared/nyan/{}.png".format(n) ) n = (n+1) % 6 sleep.sleep_ms(10) if Buttons.is_pressed(Buttons.BTN_B): break elif Buttons.is_pressed(Buttons.BTN_A): r = (r + 180) % 360 ugfx.clear(ugfx.BLACK) ugfx.orientation(r) ugfx.clear() app.restart_to_default()
___categories___ = ["Games"] ___dependencies___ = [ "dialogs", "app", "ugfx_helper", "random", "sleep", "buttons" ] import math, ugfx, ugfx_helper, time, random, sleep, buttons from tilda import Buttons ugfx_helper.init() ugfx.clear() ######################################## while True: ugfx.clear() if Buttons.is_pressed(Buttons.JOY_Left): ugfx.text(5, 5, "Left", ugfx.RED) elif Buttons.is_pressed(Buttons.JOY_Right): ugfx.text(5, 5, "Right", ugfx.RED) elif Buttons.is_pressed(Buttons.JOY_Down): ugfx.text(5, 5, "Down", ugfx.RED) elif Buttons.is_pressed(Buttons.JOY_Up): ugfx.text(5, 5, "Up", ugfx.RED) elif Buttons.is_pressed(Buttons.JOY_Center): ugfx.text(5, 5, "Center", ugfx.RED) elif Buttons.is_pressed(Buttons.BTN_Menu): ugfx.text(5, 5, "Menu", ugfx.RED) elif Buttons.is_pressed(Buttons.BTN_A): ugfx.text(5, 5, "A", ugfx.RED) elif Buttons.is_pressed(Buttons.BTN_B): ugfx.text(5, 5, "B", ugfx.RED) sleep.wfi()
ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD) # Draw name ugfx.Label(0, ugfx.height() - name_height, ugfx.width(), name_height, name_setting, justification=ugfx.Label.CENTER) # Draw for wearer to see ugfx.orientation(270) ugfx.set_default_font(ugfx.FONT_SMALL) status = ugfx.Label(0, ugfx.height() - status_height, ugfx.width(), status_height, "", justification=ugfx.Label.LEFT) # update loop while True: text = ""; value_battery = battery() if value_battery: text += "%s%%" % int(value_battery) if Buttons.is_pressed(Buttons.BTN_Star): if torch_on: torch_on = False torch.off() neo.display([0,0]) else: torch_on = True torch.on() neo.display([0xffffff,0xffffff]) if Buttons.is_pressed(Buttons.BTN_8): draw_trans() if Buttons.is_pressed(Buttons.BTN_0): draw_badge() status.text(text) sleep_or_exit(0.5)
___dependencies___ = ["homescreen", "shared/logo.png", "shared/sponsors.png"] ___launchable___ = False ___bootstrapped___ = True import ugfx from homescreen import * import time from tilda import Buttons # We ❤️ our sponsors init() ugfx.display_image(0, 0, "shared/sponsors.png") wait_until = time.ticks_ms() + 3000 while time.ticks_ms() < wait_until: time.sleep(0.1) if Buttons.is_pressed(Buttons.BTN_A) or Buttons.is_pressed(Buttons.BTN_B) or Buttons.is_pressed(Buttons.BTN_Menu): break # Padding for name intro_height = 30 intro_text = "Hi! I'm" name_height = 60 status_height = 20 info_height = 30 logo_path = "shared/logo.png" logo_height = 150 logo_width = 56 # Maximum length of name before downscaling max_name = 8
[-1, utime.ticks_ms()], ] current_channel = 0 while True: #Main awesome loop which handles all music channels. Can handle and arbitrary amount, but lags at high numbers. for channel in channels: ##print(channel_waits[current_channel][1]) #Uncomment some of these for more debug info :P if channel_waits[current_channel][1] == 0 or channel_waits[ current_channel][1] <= utime.ticks_ms(): print("CHANGING CHANNEL " + str(current_channel)) channel_waits[current_channel][0] += 1 if channel_waits[current_channel][0] == len(channel): channel_waits[current_channel][0] = 0 channel_waits[current_channel][1] += ( channels[current_channel][channel_waits[current_channel][0]][1] * 1000.0) speaker.note(channel[channel_waits[current_channel][0]][0]) ##print(channel[channel_waits[current_channel][0]]) if Buttons.is_pressed(Buttons.BTN_Menu): print("BAIL BAIL BAIL") restart_to_default() current_channel += 1 if current_channel == len(channels): current_channel = 0 ##print(current_channel) utime.sleep( 0.03 ) #Decrease this for more accurate but weirder arps. Comment it out for insane madness restart_to_default()