コード例 #1
0
ファイル: pico-simon.py プロジェクト: may88s/pico-simon
def play():
    count = 0
    seq = []
    while True:
        seq.append(random.randint(0, 3))
        for i in seq:  # display the sequence
            clearDisplay()
            utime.sleep(0.5)
            display.set_pen(rpen[i])
            display.rectangle(rect[i]["x"], rect[i]["y"], rwidth, rheight)
            display.update()
            utime.sleep(sleep)
        clearDisplay()
        for i in seq:  # get buttons for the sequence
            b = getButton()
            display.set_pen(rpen[b])
            display.rectangle(rect[b]["x"], rect[b]["y"], rwidth, rheight)
            display.update()
            if b != i:
                display.set_led(255, 0, 0)
                utime.sleep(2)
                display.set_led(0, 0, 0)
                return len(seq) - 1
            display.set_led(0, 255, 0)
            utime.sleep(1)
            display.set_led(0, 0, 0)
            clearDisplay()
コード例 #2
0
ファイル: pico-simon.py プロジェクト: may88s/pico-simon
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)
コード例 #3
0
def showLED(val):
    if val < 800:
        display.set_led(0, 128, 0)  # Green
    if val >= 800 and val < 1200:
        display.set_led(241, 196, 15)  #Yellow
    if val >= 1200:
        display.set_led(255, 0, 0)  # Red
コード例 #4
0
        ball.x += ball.dx
        ball.y += ball.dy

        if ball.x <= 0:
            if ball.y > bat.y + 25 or ball.y < bat.y:
                #display.set_led(255,0,0)
                ball.dx = 0
                ball.dy = 0
                ball.x = 500
                ball.y = 500

        if ball.x < 0 or ball.x > width:
            ball.dx *= -1
        if ball.y < 0 or ball.y > height:
            ball.dy *= -1

        display.set_pen(ball.pen)
        display.circle(int(ball.x), int(ball.y), int(ball.r))

    if display.is_pressed(display.BUTTON_Y) and bat.y < height - 25:
        bat.y = bat.y + 1
    if display.is_pressed(display.BUTTON_X) and bat.y > 0:
        bat.y = bat.y - 1

    display.set_pen(100, 100, 100)
    display.rectangle(0, bat.y, 10, 25)

    if display.is_pressed(display.BUTTON_B):
        display.set_led(0, 0, 0)
    display.update()
コード例 #5
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)
コード例 #6
0
    # this if statement clears the display once the graph reaches the right hand side of the display
    if i >= (width + 1):
        i = 0
        display.set_pen(0, 0, 0)
        display.clear()

    # chooses a pen colour based on the temperature
    display.set_pen(0, 255, 0)
    if temperature > 20:
        display.set_pen(255, 0, 0)
    if temperature < 13:
        display.set_pen(0, 0, 255)

    # heck lets also set the LED to match
    display.set_led(0, 255, 0)
    if temperature > 20:
        display.set_led(255, 0, 0)
    if temperature < 13:
        display.set_led(0, 0, 255)

    # draws the reading as a tall, thin rectangle
    display.rectangle(i, height - (temperature * 4), 5, height)

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

    # writes the reading as text in the white rectangle
    display.set_pen(0, 0, 0)
    display.text("{:.0f}".format(temperature) + "c", 3, 3, 0, 3)
コード例 #7
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)
    
コード例 #8
0
ファイル: rainbow.py プロジェクト: slabua/pimoroni-pico
    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)