Beispiel #1
0
def initDisplay():
    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)
    clearDisplay()
def initDisplay():
    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
Beispiel #3
0
# It then displays the info on the screen of Pico Display or Pico Explorer.
# Remember to save this code as main.py on your Pico if you want it to run automatically!

from machine import ADC, Pin
import time

# Uncomment one of these lines, depending on what display you have
import picodisplay as display
# import picodisplay2 as display
# import picoexplorer as display

# Set up and initialise display
buf = bytearray(display.get_width() * display.get_height() * 2)
display.init(buf)
display.set_backlight(
    0.8
)  # comment out this line if you have a Pico Explorer as it doesn't have a controllable backlight

vsys = ADC(29)  # reads the system input voltage
charging = Pin(
    24, Pin.IN)  # reading GP24 tells us whether or not USB power is connected
conversion_factor = 3 * 3.3 / 65535

full_battery = 4.2  # these are our reference voltages for a full/empty battery, in volts
empty_battery = 2.8  # the values could vary by battery size/manufacturer so you might need to adjust them

while True:
    # convert the raw ADC read into a voltage, and then a percentage
    voltage = vsys.read_u16() * conversion_factor
    percentage = 100 * ((voltage - empty_battery) /
                        (full_battery - empty_battery))
Beispiel #4
0
import time, random
import picodisplay as display

# based on initial code demo for the PiMoroni PicoDisplay for the RaspberyPiPico

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.0)


class Ball:
    def __init__(self, x, y, r, dx, dy, pen):
        self.x = x
        self.y = y
        self.r = r
        self.dx = dx
        self.dy = dy
        self.pen = pen


class Bat:
    def __init__(self, y):
        self.y = y


# initialise shapes
balls = []
Beispiel #5
0
# pico-simon by Simon May.
import utime, random
import picodisplay as display

# Set up and initialise Pico Display
buf = bytearray(display.get_width() * display.get_height() * 2)
display.init(buf)
display.set_backlight(0.8)

WHITE = display.create_pen(255, 255, 255)
BLACK = display.create_pen(0, 0, 0)
RED = display.create_pen(255, 0, 0)
GREEN = display.create_pen(0, 255, 0)
BLUE = display.create_pen(0, 0, 255)
YELLOW = display.create_pen(255, 255, 0)
rwidth = 120
rheight = 67
rect = [{
    "x": 0,
    "y": 0
}, {
    "x": 120,
    "y": 0
}, {
    "x": 0,
    "y": 68
}, {
    "x": 120,
    "y": 68
}]
rpen = [RED, YELLOW, BLUE, GREEN]
Beispiel #6
0
# This example shows you a simple, non-interrupt way of reading Pico Display's buttons with a loop that checks to see if buttons are pressed.

import picodisplay as display  # Comment this line out to use PicoDisplay2
# import picodisplay2 as display  # Uncomment this line to use PicoDisplay2
import utime

# Initialise display with a bytearray display buffer
buf = bytearray(display.get_width() * display.get_height() * 2)
display.init(buf)
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()
Beispiel #7
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()
Beispiel #8
0
import time
import picodisplay
from Blinky import LCD
from Blinky import Blink
from Blinky import Buttons
from Blinky import FileManage
from copy import copy

# Initialise Picodisplay with a bytearray display buffer
buf = bytearray(picodisplay.get_width() * picodisplay.get_height() * 2)
picodisplay.init(buf)
picodisplay.set_backlight(1)

#set colors
blue = (0, 0, 255)
orange = (255, 102, 0)
gray = (125, 128, 128)
white = (200, 255, 255)
red = (255, 0, 0)

#set variables
buttons = (picodisplay.BUTTON_A, picodisplay.BUTTON_B, picodisplay.BUTTON_X,
           picodisplay.BUTTON_Y)
led_orange = (picodisplay.set_led, orange)
led_blue = (picodisplay.set_led, blue)
led_gray = (picodisplay.set_led, gray)
led_white = (picodisplay.set_led, white)
led_red = (picodisplay.set_led, red)

#save stuff
last_save = time.ticks_ms()
Beispiel #9
0
def setup_screen():
    # Set up the display screen
    buf = bytearray(display.get_width() * display.get_height() * 2)
    display.init(buf)
    display.set_backlight(1.0)
Beispiel #10
0
    max_reaction_time = 1000  # ms

    lap_delta = start(lap_delta, max_reaction_time)

    last_turn_time = 0
    time_to_line = 1  ## Default in case of bad track, with no finish set

    for turn in track_list[track][1]:
        # I wanted to use cumulative times for turn so need to minus previous turn time
        new_turn_time = turn[0]
        time_to_turn = new_turn_time - last_turn_time
        direction = turn[1]
        if direction != "F":
            # Each race section adds time to the lap_delta
            lap_delta = next_turn(lap_delta, max_reaction_time, direction,
                                  time_to_turn)
            last_turn_time = new_turn_time  ## Ready for next turn
        else:
            time_to_line = time_to_turn  ## Set ready for finish line function
            break

    finish(lap_delta, time_to_line)
    # Save final time ???
    clear_screen()
    utime.sleep(3)
#     break

display.set_backlight(0)

## Program End
Beispiel #11
0
import utime
from random import randint
import picodisplay as display

# picodisplay boilerplate code
width = display.get_width()
height = display.get_height()

display_buffer = bytearray(width * height * 2)
display.init(display_buffer)

backlight_intensity = 0.6
display.set_backlight(backlight_intensity)

# initialize global variables for game
tile_size = 12            # size in pixels of square tiles
grid_w, grid_h = 20, 11   # 20*11 tiles

# color data
snake_color = (0, 200, 0)
food_color  = (200, 0, 0)
wall_color  = (200, 0, 200)
title_color = (255, 255, 0)
score_color = (255, 255, 255)



class SnakeNode:
    def __init__(self, position=None, direction=None, next=None):
        self.pos = position
        self.dir = direction