Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
 def enter(self):
     self.next_state = S_CONTINUE
     self.station_code = database.get('trains.station_code', 'LBG')
     self.last_update = 0
     Buttons.enable_interrupt(Buttons.BTN_A,
                              lambda t: self.set_next_state(S_TO_SETTINGS),
                              on_press=True,
                              on_release=False)
     Buttons.enable_interrupt(Buttons.BTN_Menu,
                              lambda t: self.set_next_state(S_EXIT),
                              on_press=True,
                              on_release=False)
Ejemplo n.º 5
0
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()
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0

def playback():
    global isRecording

    if isRecording:
        isRecording = False
        sim800.stoprecording()
        setRecordingStatus()
        displayStatus("")

    sim800.startplayback(1, 0, 100, False)


Buttons.enable_interrupt(Buttons.BTN_A,
                         lambda button_id: startRecording(),
                         on_press=True,
                         on_release=False)

Buttons.enable_interrupt(Buttons.BTN_B,
                         lambda button_id: playback(),
                         on_press=True,
                         on_release=False)

Buttons.enable_interrupt(Buttons.BTN_Menu,
                         lambda button_id: app.restart_to_default(),
                         on_press=True,
                         on_release=False)

isRecording = False
displayControls()
setRecordingStatus()
Ejemplo n.º 11
0
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()))
Ejemplo n.º 12
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()
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
    GreenLEDNum = random.randint(0, 1)

    if RedLEDNum == 0:
        LED(LED.RED).on()
    else:
        LED(LED.RED).off()

    if GreenLEDNum == 0:
        LED(LED.GREEN).on()
    else:
        LED(LED.GREEN).off()

    colourNum1 = colourList[random.randint(0, 510)]
    colourNum2 = colourList[random.randint(0, 510)]
    n.display([colourNum1, colourNum2])


def badgeQuit():
    restart_to_default()  # call on exit of main.py'''


Buttons.enable_interrupt(Buttons.BTN_B,
                         lambda button_id: ledChange(),
                         on_press=True,
                         on_release=False)

Buttons.enable_interrupt(Buttons.BTN_A,
                         lambda button_id: badgeQuit(),
                         on_press=True,
                         on_release=False)
Ejemplo n.º 15
0
                      "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()
Ejemplo n.º 16
0
		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)
Ejemplo n.º 17
0
 def exit(self):
     self._destroy_old_names()
     self._destroy_names()
     Buttons.disable_all_interrupt()
Ejemplo n.º 18
0
___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()
Ejemplo n.º 19
0
from tilda import Buttons

n = Neopix()

mapping = {0: 0x000001, 1: 0x000100, 2: 0x010000}

exit = False


def breakout(x):
    global exit
    exit = True


Buttons.enable_interrupt(Buttons.BTN_Menu,
                         breakout,
                         on_press=True,
                         on_release=False)

while True:
    store = [0, 0]
    incs = [random.randint(0, 2) for _ in range(2)]
    for i in range(0xff):
        store[0] += mapping[incs[0]]
        store[1] += mapping[incs[1]]
        n.display(store)
    if exit:
        break

restart_to_default()
Ejemplo n.º 20
0
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
Ejemplo n.º 21
0
"""Weather

Displays the weather where you are.
"""

___name___ = "Weather"
___license___ = "MIT"
___dependencies___ = ["ugfx_helper"]
___categories___ = ["Homescreens"]
___bootstrapped___ = True  # Whether or not apps get downloaded on first install. Defaults to "False", mostly likely you won't have to use this at all.

import ugfx_helper, ugfx, app
from tilda import Buttons
# import weather

ugfx_helper.init()
ugfx.clear(ugfx.BLACK)

ugfx.text(5, 5, "Hi Alan!", ugfx.WHITE)

Buttons.enable_interrupt(Buttons.BTN_B,
                         lambda button_id: app.restart_to_default(),
                         on_press=True,
                         on_release=False)

while True:
    sleep.wfi()

ugfx.clear()
app.restart_to_default()
Ejemplo n.º 22
0
        ugfx.orientation(90)
        orientation = 90
        draw_screen()


ugfx.init()
ugfx.clear(ugfx.BLACK)
ugfx.set_default_font(ugfx.FONT_FIXED)

s = ugfx.Style()
s.set_enabled([ugfx.WHITE, ugfx.BLACK, ugfx.BLACK, ugfx.GREY])
s.set_background(ugfx.BLACK)
ugfx.set_default_style(s)

Buttons.enable_interrupt(Buttons.BTN_A,
                         lambda button_id: get_beer(),
                         on_press=True,
                         on_release=False)
Buttons.enable_interrupt(Buttons.BTN_B,
                         lambda button_id: toggle_orientation(),
                         on_press=True,
                         on_release=False)
Buttons.enable_interrupt(Buttons.BTN_Menu,
                         lambda button_id: app.restart_to_default(),
                         on_press=True,
                         on_release=False)

ugfx.text(5, 10, "Instructions:", ugfx.WHITE)
ugfx.text(5, 30, "Press the A button to refresh", ugfx.WHITE)
ugfx.text(5, 45, "Press the B button to rotate", ugfx.WHITE)
ugfx.text(5, 60, "Press the Menu button to exit", ugfx.WHITE)
ugfx.text(5, 90, "!", ugfx.RED)
Ejemplo n.º 23
0

##
# 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()
Ejemplo n.º 24
0
    vip = False
    show_boot()


def cbButton8(button_id):
    global strobe
    strobe = True


def cbButton9(button_id):
    global strobe
    strobe = False


Buttons.enable_interrupt(Buttons.BTN_Call,
                         cbButtonCall,
                         on_press=True,
                         on_release=False)

Buttons.enable_interrupt(Buttons.BTN_A,
                         cbButtonA,
                         on_press=True,
                         on_release=False)

Buttons.enable_interrupt(Buttons.BTN_B,
                         cbButtonB,
                         on_press=True,
                         on_release=False)

Buttons.enable_interrupt(Buttons.BTN_1,
                         cbButton1,
                         on_press=True,
Ejemplo n.º 25
0
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)
Ejemplo n.º 26
0

def get_black():
    x = random.randint(1, 320)
    ugfx.clear(ugfx.html_color(0x000000))
    text = str(d["blackCards"][x]["text"])
    ugfx.Label(0, 0, 240, 400, text, style=b)


def get_white():
    y = random.randint(1, 1271)
    ugfx.clear(ugfx.html_color(0xffffff))
    text = str(d["whiteCards"][y])
    ugfx.Label(0, 0, 240, 400, text, style=w)


Buttons.enable_interrupt(Buttons.BTN_A,
                         lambda button_id: get_black(),
                         on_press=True,
                         on_release=False)

Buttons.enable_interrupt(Buttons.BTN_B,
                         lambda button_id: get_white(),
                         on_press=True,
                         on_release=False)

Buttons.enable_interrupt(Buttons.BTN_Menu,
                         lambda button_id: restart_to_default(),
                         on_press=True,
                         on_release=False)
Ejemplo n.º 27
0
 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
Ejemplo n.º 28
0
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):
Ejemplo n.º 29
0
___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
Ejemplo n.º 30
0
        ugfx.text(5, i * 20 + 5, v + " ", ugfx.BLACK)


lastpushed = 0


def pushed(n):
    global Tape, TP, waiting
    if (waiting):
        output(n + " \n")
        Tape[TP] = ord(n)
        waiting = False


Buttons.enable_interrupt(Buttons.BTN_1,
                         lambda button_id: pushed("1"),
                         on_press=True,
                         on_release=False)
Buttons.enable_interrupt(Buttons.BTN_2,
                         lambda button_id: pushed("2"),
                         on_press=True,
                         on_release=False)
Buttons.enable_interrupt(Buttons.BTN_3,
                         lambda button_id: pushed("3"),
                         on_press=True,
                         on_release=False)
Buttons.enable_interrupt(Buttons.BTN_4,
                         lambda button_id: pushed("4"),
                         on_press=True,
                         on_release=False)
Buttons.enable_interrupt(Buttons.BTN_5,
                         lambda button_id: pushed("5"),