예제 #1
0
def start(lap_delta, max_reaction_time):
    # Draw the red start lights one at a time
    clear_screen()
    display.set_pen(255, 0, 0)
    for light in range(5):
        display.circle(40 + (light * 40), 50, 10)
        display.update()
        utime.sleep(1)
    delay = math.fmod(utime.ticks_ms(), 4) + 1
    utime.sleep(delay)  # Random delay before go lights out

    # Remove lights
    display.set_pen(0, 0, 0)
    display.rectangle(20, 35, 200, 30)
    # No effect until next display.update()

    # Click the correct side to "Go"
    display.set_pen(0, 255, 0)  # Green for GO
    #     display.circle(120, 50, 20)
    # Pick side randomly for the start button, indicated by GO
    side = random.choice(["<", ">"])
    if side == "<":
        display.text("G0", 20, 105, 240, 2)
    else:
        display.text("G0", 200, 105, 240, 2)
    # Cover up start lights and display "Go"
    display.update()

    # Time the user's reaction
    lap_delta += time_user(side, max_reaction_time)
    return lap_delta
예제 #2
0
def time_user(side, max_reaction_time):
    # Time user's reactions
    t1 = utime.ticks_ms()  # Start timer
    while True:
        utime.sleep_ms(1)
        if ( (side == "<") and (display.is_pressed(display.BUTTON_B)) and (display.is_pressed(display.BUTTON_Y) == False) ) \
                or ( (side == ">") and (display.is_pressed(display.BUTTON_Y)) and (display.is_pressed(display.BUTTON_B) == False) ):
            t2 = utime.ticks_ms()  # End timer
            break
        elif utime.ticks_diff(
                utime.ticks_ms(),
                t1) > max_reaction_time:  # If 3 seconds has passed
            t2 = utime.ticks_add(
                t1, max_reaction_time
            )  # End timer, set to max time even if it's slightly passed 3 seconds
            break
    # Calculate reaction time and display results
    reaction_time = utime.ticks_diff(t2, t1) / 1000
    time_text = "T: " + "{:0<5}".format(
        str(reaction_time))  # Display reaction time to 3 decimals (ms)
    clear_screen()
    display.set_pen(255, 255, 255)
    display.text(time_text, 50, 30, 240, 4)
    display.update()
    utime.sleep_ms(750)  # Pause to read reaction time
    return reaction_time
예제 #3
0
 def flash_b():
     picodisplay.set_pen(100, 100, 100)
     picodisplay.clear()
     picodisplay.set_pen(255, 255, 255)
     picodisplay.text("F#$%!", 5, 10, 240, 5)
     picodisplay.set_pen(0, 0, 0)
     picodisplay.text("Its monday!", 5, 50, 240, 5)
     picodisplay.update()
예제 #4
0
 def flash_a():
     picodisplay.set_pen(175, 175, 175)
     picodisplay.clear()
     picodisplay.set_pen(255, 255, 255)
     picodisplay.text("Morning...", 5, 10, 240, 4)
     picodisplay.set_pen(0, 0, 0)
     picodisplay.text("Its monday!", 5, 50, 240, 5)
     picodisplay.update()
예제 #5
0
def makemagazin():
    display.set_pen(makeRed)
    display.text("Make:", 10, 10, 64, 6)

    display.set_pen(makeBlue)
    #display.rectangle(20, 20, 40, 20)
    display.text("Deutschlands gefaehrlichstes DIY-Magazin", 10, 5, 240, 1)

    display.set_pen(makeGray)
    display.rectangle(5, 50, width - 10, height - 55)
예제 #6
0
def intro():
    clear_screen("white")
    # Draw red border
    display.set_pen(255, 0, 0)
    display.rectangle(1, 1, 238, 133)
    display.set_pen(255, 255, 255)
    display.rectangle(4, 4, 232, 127)
    # Display "Pico"
    pico_x_base = 30  # 93 works well for centre, 70 original
    pico_y_base = 20
    display.set_pen(0, 0, 0)
    display.text("Pico", pico_x_base, pico_y_base, 0, 3)
    # Display "F-Won"
    logo_x_base = 30  ## 70  original
    logo_y_base = 50
    display.set_pen(255, 0, 0)
    display.text("F-Won", logo_x_base, logo_y_base, 0, 4)
    display.set_pen(0, 0, 0)
    display.text("o", logo_x_base + 60, logo_y_base, 0, 4)
    display.set_pen(255, 255, 255)
    display.rectangle(logo_x_base + 76, logo_y_base + 4, 4, 4)
    # Display "By CT"
    name_x_base = 140  # 100 original
    name_y_base = 100
    display.set_pen(0, 0, 0)
    display.text("By CT", name_x_base, name_y_base, 240, 3)
    display.update()
    utime.sleep(3)
예제 #7
0
def menu():
    display.set_led(0, 0, 0)
    display.set_pen(BLACK)
    display.clear()
    display.set_pen(WHITE)
    display.text("Press any button!", 10, 10, 240, (3, 6)[best == 0])
    if best > 0:
        display.text("Hiscore: " + str(best), 10, 68, 240, 3)
    display.update()  # Update the display
    while True:
        if display.is_pressed(display.BUTTON_A) or display.is_pressed(
                display.BUTTON_B) or display.is_pressed(
                    display.BUTTON_X) or display.is_pressed(display.BUTTON_Y):
            return
        utime.sleep(0.5)
예제 #8
0
def failed():
    global best
    display.set_pen(RED)
    display.clear()
    display.set_pen(YELLOW)
    display.text("Game Over!", 10, 10, 240, 6)  # Add some text
    display.update()  # Update the display
    utime.sleep(1)
    display.set_pen(RED)
    display.clear()
    display.set_pen(YELLOW)
    display.text("Score: " + str(score), 10, 10, 240, 3)
    if score > best:
        display.text("New Hiscore!", 10, 68, 240, 3)
        best = score
    else:
        display.text("Hiscore: " + str(best), 10, 68, 240, 3)
    display.update()  # Update the display
    utime.sleep(3)
예제 #9
0
def next_turn(lap_delta, max_reaction_time, direction, lead_time):
    clear_screen()
    utime.sleep_ms(250)  # Small pause for transition
    straight(lead_time)
    # Prepare large chevrons indicating turn direction
    turn_text = direction * 3
    display.set_pen(255, 255, 255)
    display.text(turn_text, 100, 50, 240, 4)
    # Prepare correct key, label with chevrons for the turn
    display.set_pen(0, 255, 0)
    if direction == "<":
        display.text(turn_text, 20, 105, 240, 2)
    else:
        display.text(turn_text, 200, 105, 240, 2)
    # Show the turn direction now
    display.update()

    # Time the user's reaction
    lap_delta += time_user(direction, max_reaction_time)
    return lap_delta
예제 #10
0
def finish(lap_delta, time_to_line):
    clear_screen()
    straight(time_to_line)
    # Draw chequered flag
    display.set_pen(255, 255, 255)
    display.rectangle(29, 19, 182, 102)
    pen_white = True
    rw = 20
    rh = 20
    for ry in range(20, 120, 20):  # 20 to 100 in 20's
        for rx in range(30, 210, 20):  # 30 to 190 in 20's
            if pen_white:
                display.set_pen(0, 0, 0)
            else:
                display.set_pen(255, 255, 255)
            pen_white = not (pen_white)
            display.rectangle(rx, ry, rw, rh)
    # Display the chequered flag for a few seconds
    display.update()
    utime.sleep(5)
    # Show finish time
    clear_screen()
    display.set_pen(255, 255, 255)
    display.text("Lap Delta:", 50, 20, 240, 3)
    display.update()
    display.set_pen(255, 0, 255)
    time_text = "{:.3f}".format(
        lap_delta)  # Display reaction time to 3 decimals (ms)
    display.text(time_text, 50, 50, 240, 4)
    # Wait for key press to continue
    display.set_pen(0, 255, 0)
    display.text("Continue", 125, 105, 240, 2)
    display.update()
    while True:
        utime.sleep_ms(1)
        if display.is_pressed(display.BUTTON_Y):
            break  # Break loop to continue
    return lap_delta
예제 #11
0
# Test eines Punktes
def one_sample():
    y, x = random.random(), random.random()
    if math.pow(y, 2) + math.pow(x, 2) <= 1.0:
        display.set_pen(0, 255, 0)
        display.pixel(int(x * height), int(y * height))
        return 1
    else:
        display.set_pen(255, 0, 0)
        display.pixel(int(x * height), int(y * height))
        return 0


display.set_pen(0, 0, 200)
display.text("Happy Pi-Day!", 140, 90, 100, 3)

runs = 100  #wieviele Iterationen zwischen Screen Refresh
iterations = 100000  # Durchläufe

pi = 0.0
for it in range(1, iterations):
    for i in range(runs):
        pi += one_sample()
    # Text Info
    display.set_pen(255, 255, 255)
    display.rectangle(140, 10, 120, 46)
    display.set_pen(0, 0, 200)
    display.text("Pi: " + str(pi * 4.0 / runs / it), 140, 10, 200, 2)  # Pi
    display.text("It: " + str(runs * it), 140, 26, 200, 2)  # Iterationen
    display.text("Fe: " + str((pi * 4.0 / runs / it - math.pi) * 100), 140, 42,
예제 #12
0
print('CPU frequency is {:3.0f} MHz'.format(machine.freq() / 1e6))

offsetADC = offset.read_u16() * conversion_factor
print('ADC(0) offset voltage is {:3.3f} mV'.format(offsetADC * 1000))

reading = temp.read_u16() * conversion_factor

# The temperature sensor measures the Vbe voltage of a biased bipolar diode, connected to the fifth ADC channel
# Typically, Vbe = 0.706V at 27 degrees C, with a slope of -1.721mV (0.001721) per degree.
intTemp = 27 - (reading - 0.706) / 0.001721
print('On-Chip temperature is {:3.1f} °C'.format(intTemp))

initDisplay()
width = display.get_width()
txt = '{}'.format(uos.uname().machine)
display.text(txt, 10, 10, width, 2)
txt = 'Firmware v.{:}'.format(uos.uname().version)
display.text(txt, 10, 40, width, 2)
txt = 'Clock is {:3.0f} MHz'.format(machine.freq() / 1e6)
display.text(txt, 10, 85, width, 2)
txt = 'Temp is {:3.1f} *C'.format(intTemp)
display.text(txt, 10, 100, width, 2)
txt = 'ADC Offset is {:3.1f} mV'.format(offsetADC * 1000)
display.text(txt, 10, 115, width, 2)
display.update()

print('Press the X button for fast blinking & Y botton for slow blinking')
print('Ctrl-C stopps the running program')

global state
state = 0
예제 #13
0
# set drawing color
display.set_pen(255, 255, 255)

# define pens/colors
makeRed = display.create_pen(255, 0, 0)
makeBlue = display.create_pen(0, 0, 200)
makeGray = display.create_pen(220, 220, 220)

# "clear" (just fills display with color=
display.clear()

# update/push changes to display (to avoid flicker)
display.update()

makemagazin()

display.set_pen(makeRed)
while not (display.is_pressed(display.BUTTON_A)):
    display.pixel(random.randint(5, 234), random.randint(50, 129))
    if display.is_pressed(display.BUTTON_Y):
        display.set_pen(makeBlue)
        display.text("Pico", random.randint(5, 234), random.randint(50, 129),
                     100, 2)
        display.set_pen(makeRed)

    display.update()

# wait a second
time.sleep(1)
예제 #14
0
display.set_backlight(0.5)


# sets up a handy function we can call to clear the screen
def clear():
    display.set_pen(0, 0, 0)
    display.clear()
    display.update()


while True:
    if display.is_pressed(
            display.BUTTON_A):  # if a button press is detected then...
        clear()  # clear to black
        display.set_pen(255, 255, 255)  # change the pen colour
        display.text("Button A pressed", 10, 10, 240,
                     4)  # display some text on the screen
        display.update()  # update the display
        utime.sleep(1)  # pause for a sec
        clear()  # clear to black again
    elif display.is_pressed(display.BUTTON_B):
        clear()
        display.set_pen(0, 255, 255)
        display.text("Button B pressed", 10, 10, 240, 4)
        display.update()
        utime.sleep(1)
        clear()
    elif display.is_pressed(display.BUTTON_X):
        clear()
        display.set_pen(255, 0, 255)
        display.text("Button X pressed", 10, 10, 240, 4)
        display.update()
예제 #15
0
        temperatures.pop(0)

    i = 0
    for t in temperatures:
        # chooses a pen colour based on the temperature
        display.set_pen(*temperature_to_color(t))

        # draws the reading as a tall, thin rectangle
        display.rectangle(i, height - (round(t) * 4), bar_width, height)

        # the next tall thin rectangle needs to be drawn
        # "bar_width" (default: 5) pixels to the right of the last one
        i += bar_width

    # heck lets also set the LED to match
    display.set_led(*temperature_to_color(temperature))

    # draws a white background for the text
    display.set_pen(255, 255, 255)
    display.rectangle(1, 1, 100, 25)

    # writes the reading as text in the white rectangle
    display.set_pen(0, 0, 0)
    display.text("{:.2f}".format(temperature) + "c", 3, 3, 0, 3)

    # time to update the display
    display.update()

    # waits for 5 seconds
    utime.sleep(5)
예제 #16
0
import time
import picodisplay as display 

width = display.get_width()
height = display.get_height()

display_buffer = bytearray(width * height * 2)  # 2-bytes per pixel (RGB565)
display.init(display_buffer)

display.set_backlight(1)


display.set_pen(0, 0, 0)    # black
display.clear()
display.set_pen(100, 100, 100) # white

#display.circle(100,100,10)
#display.pixel(10,10)
#display.pixel_span(20,20,200) // wagerechte Linie
#display.rectangle(10,10,width-10,height-10)
display.text('01234567890123456789\n',10,10, 0, 2)
display.text('01234567890123456789\n',10,24, 0, 2)
        
display.update()
예제 #17
0
    if val >= 800 and val < 1200:
        display.set_led(241, 196, 15)  #Yellow
    if val >= 1200:
        display.set_led(255, 0, 0)  # Red


print('\nThis program measures air quality by Sensirion SGP30')
print(
    'and displays results on Pimoroni Pico Display using Raspberry Pi Pico Board\n'
)
print('Installed firmware version is {}\n'.format(uos.uname().version))

initDisplay()
width = display.get_width()
txt = 'Air Quality by SGP30'
display.text(txt, 10, 10, width, 3)

# Initialize SGP-30 internal drift compensation algorithm.
sgp30.iaq_init()

# Wait 15 seconds for the SGP30 to properly initialize
print("Waiting 15 seconds for SGP30 initialization.")
txt = 'Waiting 15 seconds...'
display.text(txt, 10, 60, width, 2)
display.update()
time.sleep(15)

# Retrieve previously stored baselines, if any (helps the compensation algorithm).
has_baseline = False
try:
    f_co2 = open('co2eq_baseline.txt', 'r')
예제 #18
0
                pillar.x -= 1
            else:
                pillar.x = width
                hole = random.randint(1, height - 100)
                pillar.holetop = hole
                pillar.holebottom = hole + 75
                score += 1
            if pillar.x < 39 and pillar.x > 6:
                if bird.y < pillar.holetop or bird.y + 28 > pillar.holebottom:
                    bird.crashed = True

    #draw the bird
    drawbird(bird.x, bird.y, 2)

    display.set_pen(white)
    display.text(str(score), width - 70, 5, 1, 5)

    #move the bird
    if not bird.crashed:
        if display.is_pressed(display.BUTTON_A):
            #flap!
            if bird.y > -22:
                bird.y -= 3
        else:
            if bird.y < height - 25:
                bird.y += 3

    if display.is_pressed(display.BUTTON_B):
        colonade = []
        reset()
        #Thanks to Stephan who pointed out was easy to get a massive high score
예제 #19
0
    def show_game_text(self):
        title_red, title_green, title_blue = title_color
        display.set_pen(title_red, title_green, title_blue)

        if self.state == self.game_state['title_screen']:
            display.text("PiCo", int(width/6), int(height/16), 10, 8)
            display.text("Snake", int(width/16), int(height/2), 10, 8)
            
        elif self.state == self.game_state['level_name']:            
            display.set_pen(150, 255, 255)   
            display.text("Level", int(width/12), int(height/16), 10, 8)           
            display.set_pen(255, 255, 255)
            display.text(str(self.level_number), int(7*width/16), int(height/2), 10, 8)
            
        elif self.state == self.game_state['lives_left']:            
            display.set_pen(0, 255, 0)
            display.text("Lives", int(width/12), int(height/16), 10, 8)
            
            if self.lives_left == 3:
                display.set_pen(220, 220, 0)
            elif self.lives_left == 2:
                display.set_pen(220, 110, 0)
            elif self.lives_left == 1:
                display.set_pen(220, 0, 0)
            
            display.text(str(self.lives_left), int(14*width/16), int(height/2), 10, 8)
            
        elif self.state == self.game_state['show_score']:
            self.draw_game_objects()
            display.set_pen(255, 255, 255)
            display.text("SCORE", int(width/16), int(height/16), 10, 8)
            display.text(str(self.score), int(2*width/5), int(height/2), 10, 8)
        
        elif self.state == self.game_state['game_over']:
            self.draw_game_objects()
            display.set_pen(255, 255, 255)
            display.text("Game", int(width/6), int(height/16), 10, 8)
            display.text("Over", int(width/16), int(height/2), 10, 8)
예제 #20
0

def convert(seconds):
    min, sec = divmod(seconds, 60)
    hour, min = divmod(min, 60)
    return "%d:%02d:%02d" % (hour, min, sec)


timeCount = 0

while True:

    display.set_pen(255, 255, 0)
    display.clear()
    display.set_pen(0, 0, 0)  # Set pen to black
    display.text("Timer", 10, 10, 240, 5)  # Add some text
    display.text("Press Y to Start", 10, 60, 240, 4)  # Add some text
    if display.is_pressed(display.BUTTON_A):
        display.set_pen(255, 255, 0)
        display.clear()
        timeCount += 60
        display.set_pen(0, 0, 0)  # change the pen colour
        display.text(str(timeCount / 60) + " minutes", 10, 10, 240,
                     4)  # display some text on the screen
        display.update()  # update the display
        utime.sleep(0.5)  # pause for a sec
    elif display.is_pressed(display.BUTTON_B):
        display.set_pen(255, 255, 0)
        display.clear()
        timeCount -= 60
        display.set_pen(0, 0, 0)  # change the pen colour
예제 #21
0
def run_game():
    global key_mode, game_state

    while True:
        ## Draw methods
        display.set_pen(*SKY_COLOR)
        display.clear()
        ground.draw()
        tank1.draw()
        tank2.draw()

        if (game_state == "player1fire" or game_state == "player2fire"):
            shell.draw()

        display.set_pen(*TEXT_COLOR)
        if (game_state == "player1" or game_state == "player1fire"):
            display.text("Player 1", 10, 10, 240, 1)
            if (key_mode == "power"):
                display.set_pen(*TEXT_COLOR_ACTIVE)
            display.text("Power " + str(tank1.get_gun_power()) + "%", 10, 20,
                         240, 1)  #
            if (key_mode == "angle"):
                display.set_pen(*TEXT_COLOR_ACTIVE)
            else:
                display.set_pen(*TEXT_COLOR)
            display.text("Angle " + str(tank1.get_gun_angle()), 10, 30, 240, 1)
        if (game_state == "player2" or game_state == "player2fire"):
            display.text("Player 2", 180, 10, 240, 1)
            if (key_mode == "power"):
                display.set_pen(*TEXT_COLOR_ACTIVE)
            display.text("Power " + str(tank2.get_gun_power()) + "%", 180, 20,
                         240, 1)
            if (key_mode == "angle"):
                display.set_pen(*TEXT_COLOR_ACTIVE)
            else:
                display.set_pen(*TEXT_COLOR)
            display.text("Angle " + str(tank2.get_gun_angle()), 180, 30, 240,
                         1)
        if (game_state == "game_over_1"):
            display.text("Game Over", 50, 20, 240, 3)
            display.text("Player 1 wins!", 30, 40, 240, 3)
        if (game_state == "game_over_2"):
            display.text("Game Over", 50, 20, 240, 3)
            display.text("Player 2 wins!", 30, 40, 240, 3)
        display.update()

        ## Update methods
        # Only read keyboard in certain states
        if (game_state == 'player1'):
            player1_fired = player_keyboard("left")
            if (player1_fired == True):
                # Set shell position to end of gun
                # Use gun_positions so we can get start position
                gun_positions = tank1.calc_gun_positions()
                start_shell_pos = (gun_positions[3][0],
                                   gun_positions[3][1] + 2)
                shell.set_start_position(start_shell_pos)
                shell.set_current_position(start_shell_pos)
                game_state = 'player1fire'
                shell.set_angle(math.radians(tank1.get_gun_angle()))
                shell.set_power(tank1.get_gun_power() / 40)
                shell.set_time(0)
        if (game_state == 'player1fire'):
            shell.update_shell_position("left")
            # shell value is whether the shell is inflight, hit or missed
            shell_value = detect_hit("left")
            # shell_value 20 is if other tank hit
            if (shell_value >= 20):
                game_state = 'game_over_1'
            # 10 is offscreen and 11 is hit ground, both indicate missed
            elif (shell_value >= 10):
                # reset key mode to angle
                key_mode = "angle"
                game_state = 'player2'
        if (game_state == 'player2'):
            player2_fired = player_keyboard("right")
            if (player2_fired == True):
                # Set shell position to end of gun
                # Use gun_positions so we can get start position
                gun_positions = tank2.calc_gun_positions()
                start_shell_pos = (gun_positions[3][0],
                                   gun_positions[3][1] + 2)
                shell.set_start_position(start_shell_pos)
                shell.set_current_position(start_shell_pos)
                game_state = 'player2fire'
                shell.set_angle(math.radians(tank2.get_gun_angle()))
                shell.set_power(tank2.get_gun_power() / 40)
                shell.set_time(0)
        if (game_state == 'player2fire'):
            shell.update_shell_position("right")
            # shell value is whether the shell is inflight, hit or missed
            shell_value = detect_hit("right")
            # shell_value 20 is if other tank hit
            if (shell_value >= 20):
                game_state = 'game_over_2'
            # 10 is offscreen and 11 is hit ground, both indicate missed
            elif (shell_value >= 10):
                game_state = 'player1'
                # reset key mode to angle
                key_mode = "angle"
        if (game_state == 'game_over_1' or game_state == 'game_over_2'):
            # Allow space key or left-shift (picade) to continue
            if (display.is_pressed(display.BUTTON_B)):
                # Reset position of tanks and terrain
                setup()
예제 #22
0
def menu(track_list):
    clear_screen()
    display.set_pen(255, 255, 255)
    display.text("Select Track:", 20, 20, 240, 2)
    track_selected = 0
    max_tracks = len(track_list)
    for track_num in range(max_tracks):
        track_name = track_list[track_num][0]
        track_text = (" " * 3) + track_name
        display.text(track_text, 20, 40 + (20 * track_num), 240, 2)
    display.set_pen(255, 255, 0)
    display.text(">", 20, 40, 240, 2)  # Track selector, initial position
    display.set_pen(0, 255, 0)
    display.text("Start Game", 115, 105, 240, 2)
    display.update()
    while True:
        utime.sleep_ms(1)
        track_change = False
        display.set_pen(0, 0, 255)

        if display.is_pressed(display.BUTTON_Y):
            # Select current highlighted track
            break
        elif display.is_pressed(display.BUTTON_A):
            # Up
            track_selected = int(
                math.fmod(track_selected + (max_tracks - 1), max_tracks))
            track_change = True
            utime.sleep_ms(250)
        elif display.is_pressed(display.BUTTON_B):
            # Down
            track_selected = int(math.fmod(track_selected + 1, max_tracks))
            track_change = True
            utime.sleep_ms(250)
        if track_change:
            for track in range(max_tracks):
                if track == track_selected:
                    display.set_pen(255, 255, 0)
                    display.text(">", 20, 40 + (20 * track), 240,
                                 2)  # Track selector
                else:
                    display.set_pen(0, 0, 0)
                    display.text(">", 20, 40 + (20 * track), 240,
                                 2)  # Remove track selector
            display.update()
            track_change = False  # Reset ready for next change
    return track_selected
예제 #23
0
    q = v * (1.0 - s * f)
    t = v * (1.0 - s * (1.0 - f))
    i = i % 6
    if i == 0:
        return v, t, p
    if i == 1:
        return q, v, p
    if i == 2:
        return p, v, t
    if i == 3:
        return p, q, v
    if i == 4:
        return t, p, v
    if i == 5:
        return v, p, q


h = 0

while True:
    h += 1
    r, g, b = [int(255 * c)
               for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)]  # rainbow magic
    display.set_led(r, g, b)  # Set LED to a converted HSV value
    display.set_pen(r, g, b)  # Set pen to a converted HSV value
    display.clear()  # Fill the screen with the colour
    display.set_pen(0, 0, 0)  # Set pen to black
    display.text("pico disco!", 10, 10, 240, 6)  # Add some text
    display.update()  # Update the display
    utime.sleep(1.0 / 60)
예제 #24
0
    width = display.get_width()
    height = display.get_height()

    display_buffer = bytearray(width * height * 2)  # 2-bytes per pixel (RGB565)
    display.init(display_buffer)
    display.set_backlight(1)

    display.set_pen(0, 0, 0)    # black
    display.clear()
    display.set_pen(100, 100, 100) # white

t.init(period=1000, mode=Timer.PERIODIC, callback = blink)

initDisplay()
width = display.get_width()

while True:
    reading = sensor_temp.read_u16() * conversion_factor
    intTemp = 27 - (reading - 0.706)/0.001721
    print('On-Chip temperature is {:3.1f} °C'.format(intTemp))
    display.set_pen(0, 0, 0)    # black
    display.clear()
    display.set_pen(128, 128, 128) # white
    txt = 'Temp {:3.1f} *C'.format(intTemp)
    display.text(txt,10, 55, width, 4)
    display.update()
    if   intTemp > UL: display.set_led(128, 0, 0)
    elif intTemp < LL: display.set_led(0, 0, 128)
    else: display.set_led(0, 128, 0)
    time.sleep(5)
    
예제 #25
0
        percentage = 100.00

    # draw the battery outline
    display.set_pen(0, 0, 0)
    display.clear()
    display.set_pen(190, 190, 190)
    display.rectangle(0, 0, 220, 135)
    display.rectangle(220, 40, 20, 55)
    display.set_pen(0, 0, 0)
    display.rectangle(3, 3, 214, 129)

    # draw a green box for the battery level
    display.set_pen(0, 255, 0)
    display.rectangle(5, 5, round(210 / 100 * percentage), 125)

    # add text
    display.set_pen(255, 0, 0)
    if charging.value() == 1:  # if it's plugged into USB power...
        display.text("Charging!", 15, 55, 240, 4)
    else:  # if not, display the battery stats
        display.text('{:.2f}'.format(voltage) + "v", 15, 10, 240, 5)
        display.text('{:.0f}%'.format(percentage), 15, 50, 240, 5)

    # uncomment for low battery alarm (Pico Explorer only, you'll need to have GP0 and AUDIO connected with a jumper wire)
    # display.set_audio_pin(0)
    # if percentage < 5:               # if the battery is less than 5%
    #     display.set_tone(262)        # then make an annoying noise

    display.update()
    time.sleep(0.5)
예제 #26
0
display_buffer = bytearray(width * height * 2)  # 2-bytes per pixel (RGB565)
display.init(display_buffer)
# setting the backlight intensity
display.set_backlight(1.0)

# Get all files
files = sorted(os.listdir(), key=str.lower)
print(files)

#clear
display.set_pen(255, 255, 255)
display.clear()

# "GUI"
display.set_pen(200, 30, 30)
display.text("Exit", 5, 15, 230, 3)
display.set_pen(30, 200, 30)
display.text("Up", 200, 15, 30, 3)
display.set_pen(30, 30, 200)
display.text("Start", 5, 99, 230, 3)
display.set_pen(30, 200, 30)
display.text("Down", 164, 99, 230, 3)
display.update()

p = 0
while not (display.is_pressed(display.BUTTON_A)):
    display.set_pen(255, 255, 255)
    display.rectangle(0, 40, 240, 60)

    if display.is_pressed(display.BUTTON_Y):
        p = p + 1