kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Update examples to use PicoGraphics (#428)
* correct filename in name_badge.py for Tufty
* Update 240x240 round breakout examples to work with PicoGraphics
* Update colourlcd240x240demo.py to work with PicoGraphics
* Fixed rainbow.py for Pico Display and Pico Display 2.0
* Update display examples to work with PicoGraphics
* add new display example 🌈
* adventures in rainbow RAM
* add button example for pico inky pack
* tidy up examples, make names more consistent
* Update Pico Explorer and 160x80 LCD breakout examples
* Accommodate dither
pull/431/head
rodzic
4eb54b3ec6
commit
1337d2abdb
|
@ -1,16 +1,14 @@
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
from st7789 import ST7789, PALETTE_USER, DISPLAY_LCD_240X240
|
from picographics import PicoGraphics, DISPLAY_LCD_160X80, PEN_P8
|
||||||
|
|
||||||
display = ST7789(DISPLAY_LCD_240X240, rotate=0)
|
display = PicoGraphics(display=DISPLAY_LCD_160X80, pen_type=PEN_P8)
|
||||||
|
display.set_backlight(1.0)
|
||||||
|
|
||||||
WIDTH, HEIGHT = display.get_bounds()
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
|
|
||||||
# We're creating 100 balls with their own individual colour and 1 BG colour
|
# We're creating 100 balls with their own individual colour and 1 BG colour
|
||||||
# for a total of 101 colours, which will all fit in the 256 entry palette!
|
# for a total of 101 colours, which will all fit in the custom 256 entry palette!
|
||||||
display.set_palette_mode(PALETTE_USER)
|
|
||||||
|
|
||||||
display.set_backlight(1.0)
|
|
||||||
|
|
||||||
|
|
||||||
class Ball:
|
class Ball:
|
|
@ -1,12 +1,14 @@
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
import st7789
|
from picographics import PicoGraphics, DISPLAY_LCD_240X240, PEN_P8
|
||||||
|
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_DISPLAY, rotate=0)
|
display = PicoGraphics(display=DISPLAY_LCD_240X240, pen_type=PEN_P8)
|
||||||
|
display.set_backlight(1.0)
|
||||||
|
|
||||||
WIDTH, HEIGHT = display.get_bounds()
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
|
|
||||||
display.set_backlight(1.0)
|
# We're creating 100 balls with their own individual colour and 1 BG colour
|
||||||
|
# for a total of 101 colours, which will all fit in the custom 256 entry palette!
|
||||||
|
|
||||||
|
|
||||||
class Ball:
|
class Ball:
|
||||||
|
@ -34,8 +36,10 @@ for i in range(0, 100):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BG = display.create_pen(40, 40, 40)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
display.set_pen(40, 40, 40)
|
display.set_pen(BG)
|
||||||
display.clear()
|
display.clear()
|
||||||
|
|
||||||
for ball in balls:
|
for ball in balls:
|
|
@ -1,15 +1,15 @@
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
from st7789 import ST7789
|
from picographics import PicoGraphics, DISPLAY_ROUND_LCD_240X240
|
||||||
|
|
||||||
WIDTH, HEIGHT = 240, 240
|
|
||||||
|
|
||||||
display = ST7789(WIDTH, HEIGHT, round=True)
|
|
||||||
|
|
||||||
|
display = PicoGraphics(display=DISPLAY_ROUND_LCD_240X240)
|
||||||
display.set_backlight(1.0)
|
display.set_backlight(1.0)
|
||||||
|
|
||||||
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
RADIUS = WIDTH // 2
|
RADIUS = WIDTH // 2
|
||||||
|
|
||||||
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
def hsv_to_rgb(h, s, v):
|
def hsv_to_rgb(h, s, v):
|
||||||
if s == 0.0:
|
if s == 0.0:
|
||||||
|
@ -37,7 +37,7 @@ def hsv_to_rgb(h, s, v):
|
||||||
t = 0
|
t = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
display.set_pen(0, 0, 0)
|
display.set_pen(BLACK)
|
||||||
display.clear()
|
display.clear()
|
||||||
|
|
||||||
angle = t % (math.pi * 2)
|
angle = t % (math.pi * 2)
|
||||||
|
@ -60,7 +60,8 @@ while True:
|
||||||
y = RADIUS + int(distance * math.sin(angle))
|
y = RADIUS + int(distance * math.sin(angle))
|
||||||
|
|
||||||
radius = ((math.sin(t + angle) + 1) / 2.0) * 10
|
radius = ((math.sin(t + angle) + 1) / 2.0) * 10
|
||||||
display.set_pen(r, g, b)
|
dot_colour = display.create_pen(r, g, b)
|
||||||
|
display.set_pen(dot_colour)
|
||||||
display.circle(int(x), int(y), int(radius))
|
display.circle(int(x), int(y), int(radius))
|
||||||
|
|
||||||
prev_x = x
|
prev_x = x
|
||||||
|
|
|
@ -1,20 +1,25 @@
|
||||||
from breakout_roundlcd import BreakoutRoundLCD
|
from picographics import PicoGraphics, DISPLAY_ROUND_LCD_240X240
|
||||||
|
|
||||||
|
display = PicoGraphics(display=DISPLAY_ROUND_LCD_240X240)
|
||||||
|
display.set_backlight(1.0)
|
||||||
|
|
||||||
width = BreakoutRoundLCD.WIDTH
|
width, height = display.get_bounds()
|
||||||
height = BreakoutRoundLCD.HEIGHT
|
|
||||||
|
|
||||||
display_buffer = bytearray(width * height * 2) # 2-bytes per pixel (RGB565)
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
display = BreakoutRoundLCD(display_buffer)
|
RED = display.create_pen(255, 0, 0)
|
||||||
|
YELLOW = display.create_pen(255, 255, 0)
|
||||||
display.set_backlight(1)
|
GREEN = display.create_pen(0, 255, 0)
|
||||||
|
CYAN = display.create_pen(0, 255, 255)
|
||||||
|
WHITE = display.create_pen(255, 255, 255)
|
||||||
|
BLUE = display.create_pen(0, 0, 255)
|
||||||
|
MAGENTA = display.create_pen(255, 0, 255)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
display.set_pen(0, 0, 0)
|
display.set_pen(BLACK)
|
||||||
display.clear()
|
display.clear()
|
||||||
|
|
||||||
# circle
|
# circle
|
||||||
display.set_pen(255, 0, 0)
|
display.set_pen(RED)
|
||||||
display.circle(
|
display.circle(
|
||||||
width // 5, # center point x
|
width // 5, # center point x
|
||||||
height // 3, # center point y
|
height // 3, # center point y
|
||||||
|
@ -22,7 +27,7 @@ while True:
|
||||||
)
|
)
|
||||||
|
|
||||||
# rectangle
|
# rectangle
|
||||||
display.set_pen(255, 255, 0)
|
display.set_pen(YELLOW)
|
||||||
display.rectangle(
|
display.rectangle(
|
||||||
int((width * 2 / 5) - 16), # starting point x
|
int((width * 2 / 5) - 16), # starting point x
|
||||||
int(height // 3) - 8, # starting point y
|
int(height // 3) - 8, # starting point y
|
||||||
|
@ -31,7 +36,7 @@ while True:
|
||||||
)
|
)
|
||||||
|
|
||||||
# triangle
|
# triangle
|
||||||
display.set_pen(0, 255, 0)
|
display.set_pen(GREEN)
|
||||||
display.triangle(
|
display.triangle(
|
||||||
int(width * 3 / 5), int(height // 3) - 16, # point 1 x, y
|
int(width * 3 / 5), int(height // 3) - 16, # point 1 x, y
|
||||||
int(width * 3 / 5) - 16, int(height // 3) + 16, # point 2 x, y
|
int(width * 3 / 5) - 16, int(height // 3) + 16, # point 2 x, y
|
||||||
|
@ -39,7 +44,7 @@ while True:
|
||||||
)
|
)
|
||||||
|
|
||||||
# character
|
# character
|
||||||
display.set_pen(0, 255, 255)
|
display.set_pen(CYAN)
|
||||||
display.character(
|
display.character(
|
||||||
64, # int character code
|
64, # int character code
|
||||||
int(width * 4 / 5 - 16), # box starting point x
|
int(width * 4 / 5 - 16), # box starting point x
|
||||||
|
@ -48,7 +53,7 @@ while True:
|
||||||
)
|
)
|
||||||
|
|
||||||
# pixel span
|
# pixel span
|
||||||
display.set_pen(255, 255, 255)
|
display.set_pen(WHITE)
|
||||||
display.pixel_span(
|
display.pixel_span(
|
||||||
int(width * 1 / 5), # starting point x
|
int(width * 1 / 5), # starting point x
|
||||||
int(height * 2.5 / 5), # starting point y
|
int(height * 2.5 / 5), # starting point y
|
||||||
|
@ -56,7 +61,7 @@ while True:
|
||||||
)
|
)
|
||||||
|
|
||||||
# text
|
# text
|
||||||
display.set_pen(0, 0, 255)
|
display.set_pen(BLUE)
|
||||||
display.text(
|
display.text(
|
||||||
'test text', # text
|
'test text', # text
|
||||||
int(width // 5), # box starting point x
|
int(width // 5), # box starting point x
|
||||||
|
@ -66,7 +71,7 @@ while True:
|
||||||
)
|
)
|
||||||
|
|
||||||
# lines
|
# lines
|
||||||
display.set_pen(255, 0, 255)
|
display.set_pen(MAGENTA)
|
||||||
display.line(
|
display.line(
|
||||||
0, # staring point x
|
0, # staring point x
|
||||||
int(height / 2), # staring point y
|
int(height / 2), # staring point y
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
from breakout_colourlcd160x80 import BreakoutColourLCD160x80
|
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P8
|
||||||
|
|
||||||
width = BreakoutColourLCD160x80.WIDTH
|
|
||||||
height = BreakoutColourLCD160x80.HEIGHT
|
|
||||||
|
|
||||||
display_buffer = bytearray(width * height * 2) # 2-bytes per pixel (RGB565)
|
|
||||||
display = BreakoutColourLCD160x80(display_buffer)
|
|
||||||
|
|
||||||
|
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P8)
|
||||||
display.set_backlight(1.0)
|
display.set_backlight(1.0)
|
||||||
|
|
||||||
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
|
|
||||||
|
# We're creating 100 balls with their own individual colour and 1 BG colour
|
||||||
|
# for a total of 101 colours, which will all fit in the custom 256 entry palette!
|
||||||
|
|
||||||
|
|
||||||
class Ball:
|
class Ball:
|
||||||
def __init__(self, x, y, r, dx, dy, pen):
|
def __init__(self, x, y, r, dx, dy, pen):
|
||||||
|
@ -27,8 +27,8 @@ for i in range(0, 100):
|
||||||
r = random.randint(0, 10) + 3
|
r = random.randint(0, 10) + 3
|
||||||
balls.append(
|
balls.append(
|
||||||
Ball(
|
Ball(
|
||||||
random.randint(r, r + (width - 2 * r)),
|
random.randint(r, r + (WIDTH - 2 * r)),
|
||||||
random.randint(r, r + (height - 2 * r)),
|
random.randint(r, r + (HEIGHT - 2 * r)),
|
||||||
r,
|
r,
|
||||||
(14 - r) / 2,
|
(14 - r) / 2,
|
||||||
(14 - r) / 2,
|
(14 - r) / 2,
|
||||||
|
@ -36,17 +36,19 @@ for i in range(0, 100):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BG = display.create_pen(40, 40, 40)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
display.set_pen(40, 40, 40)
|
display.set_pen(BG)
|
||||||
display.clear()
|
display.clear()
|
||||||
|
|
||||||
for ball in balls:
|
for ball in balls:
|
||||||
ball.x += ball.dx
|
ball.x += ball.dx
|
||||||
ball.y += ball.dy
|
ball.y += ball.dy
|
||||||
|
|
||||||
xmax = width - ball.r
|
xmax = WIDTH - ball.r
|
||||||
xmin = ball.r
|
xmin = ball.r
|
||||||
ymax = height - ball.r
|
ymax = HEIGHT - ball.r
|
||||||
ymin = ball.r
|
ymin = ball.r
|
||||||
|
|
||||||
if ball.x < xmin or ball.x > xmax:
|
if ball.x < xmin or ball.x > xmax:
|
|
@ -1,12 +1,13 @@
|
||||||
import st7789
|
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY
|
||||||
import qrcode
|
import qrcode
|
||||||
|
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_DISPLAY, rotate=0)
|
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, rotate=0)
|
||||||
|
display.set_backlight(1.0)
|
||||||
|
|
||||||
WIDTH, HEIGHT = display.get_bounds()
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
|
|
||||||
BG = display.create_pen(0, 0, 0)
|
BG = display.create_pen(0, 0, 0)
|
||||||
FG = display.create_pen(128, 128, 128)
|
FG = display.create_pen(255, 255, 255)
|
||||||
|
|
||||||
|
|
||||||
def measure_qr_code(size, code):
|
def measure_qr_code(size, code):
|
||||||
|
|
|
@ -1,59 +1,69 @@
|
||||||
# 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.
|
# 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 st7789
|
import time
|
||||||
import utime
|
|
||||||
from pimoroni import Button
|
from pimoroni import Button
|
||||||
|
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P4
|
||||||
|
|
||||||
|
# We're only using a few colours so we can use a 4 bit/16 colour palette and save RAM!
|
||||||
|
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P4, rotate=0)
|
||||||
|
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_DISPLAY, rotate=0)
|
|
||||||
display.set_backlight(0.5)
|
display.set_backlight(0.5)
|
||||||
|
display.set_font("bitmap8")
|
||||||
WIDTH, HEIGHT = display.get_bounds()
|
|
||||||
|
|
||||||
button_a = Button(12)
|
button_a = Button(12)
|
||||||
button_b = Button(13)
|
button_b = Button(13)
|
||||||
button_x = Button(14)
|
button_x = Button(14)
|
||||||
button_y = Button(15)
|
button_y = Button(15)
|
||||||
|
|
||||||
|
WHITE = display.create_pen(255, 255, 255)
|
||||||
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
|
CYAN = display.create_pen(0, 255, 255)
|
||||||
|
MAGENTA = display.create_pen(255, 0, 255)
|
||||||
|
YELLOW = display.create_pen(255, 255, 0)
|
||||||
|
GREEN = display.create_pen(0, 255, 0)
|
||||||
|
|
||||||
|
|
||||||
# sets up a handy function we can call to clear the screen
|
# sets up a handy function we can call to clear the screen
|
||||||
def clear():
|
def clear():
|
||||||
display.set_pen(0, 0, 0)
|
display.set_pen(BLACK)
|
||||||
display.clear()
|
display.clear()
|
||||||
display.update()
|
display.update()
|
||||||
|
|
||||||
|
|
||||||
|
# set up
|
||||||
|
clear()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if button_a.read(): # if a button press is detected then...
|
if button_a.read(): # if a button press is detected then...
|
||||||
clear() # clear to black
|
clear() # clear to black
|
||||||
display.set_pen(255, 255, 255) # change the pen colour
|
display.set_pen(WHITE) # change the pen colour
|
||||||
display.text("Button A pressed", 10, 10, 240, 4) # display some text on the screen
|
display.text("Button A pressed", 10, 10, 240, 4) # display some text on the screen
|
||||||
display.update() # update the display
|
display.update() # update the display
|
||||||
utime.sleep(1) # pause for a sec
|
time.sleep(1) # pause for a sec
|
||||||
clear() # clear to black again
|
clear() # clear to black again
|
||||||
elif button_b.read():
|
elif button_b.read():
|
||||||
clear()
|
clear()
|
||||||
display.set_pen(0, 255, 255)
|
display.set_pen(CYAN)
|
||||||
display.text("Button B pressed", 10, 10, 240, 4)
|
display.text("Button B pressed", 10, 10, 240, 4)
|
||||||
display.update()
|
display.update()
|
||||||
utime.sleep(1)
|
time.sleep(1)
|
||||||
clear()
|
clear()
|
||||||
elif button_x.read():
|
elif button_x.read():
|
||||||
clear()
|
clear()
|
||||||
display.set_pen(255, 0, 255)
|
display.set_pen(MAGENTA)
|
||||||
display.text("Button X pressed", 10, 10, 240, 4)
|
display.text("Button X pressed", 10, 10, 240, 4)
|
||||||
display.update()
|
display.update()
|
||||||
utime.sleep(1)
|
time.sleep(1)
|
||||||
clear()
|
clear()
|
||||||
elif button_y.read():
|
elif button_y.read():
|
||||||
clear()
|
clear()
|
||||||
display.set_pen(255, 255, 0)
|
display.set_pen(YELLOW)
|
||||||
display.text("Button Y pressed", 10, 10, 240, 4)
|
display.text("Button Y pressed", 10, 10, 240, 4)
|
||||||
display.update()
|
display.update()
|
||||||
utime.sleep(1)
|
time.sleep(1)
|
||||||
clear()
|
clear()
|
||||||
else:
|
else:
|
||||||
display.set_pen(255, 0, 0)
|
display.set_pen(GREEN)
|
||||||
display.text("Press any button!", 10, 10, 240, 4)
|
display.text("Press any button!", 10, 10, 240, 4)
|
||||||
display.update()
|
display.update()
|
||||||
utime.sleep(0.1) # this number is how frequently the Pico checks for button presses
|
time.sleep(0.1) # this number is how frequently the Pico checks for button presses
|
|
@ -0,0 +1,48 @@
|
||||||
|
# A customisable Pride flag. (Look in the Tufty 2040 examples for a name badge version!)
|
||||||
|
|
||||||
|
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY
|
||||||
|
|
||||||
|
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, rotate=0)
|
||||||
|
|
||||||
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
|
|
||||||
|
# List of available pen colours, add more if necessary
|
||||||
|
RED = display.create_pen(209, 34, 41)
|
||||||
|
ORANGE = display.create_pen(246, 138, 30)
|
||||||
|
YELLOW = display.create_pen(255, 216, 0)
|
||||||
|
GREEN = display.create_pen(0, 121, 64)
|
||||||
|
INDIGO = display.create_pen(36, 64, 142)
|
||||||
|
VIOLET = display.create_pen(115, 41, 130)
|
||||||
|
WHITE = display.create_pen(255, 255, 255)
|
||||||
|
PINK = display.create_pen(255, 175, 200)
|
||||||
|
BLUE = display.create_pen(116, 215, 238)
|
||||||
|
BROWN = display.create_pen(97, 57, 21)
|
||||||
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
|
MAGENTA = display.create_pen(255, 33, 140)
|
||||||
|
CYAN = display.create_pen(33, 177, 255)
|
||||||
|
|
||||||
|
# Uncomment one of these to change flag
|
||||||
|
# If adding your own, colour order is left to right (or top to bottom)
|
||||||
|
COLOUR_ORDER = [RED, ORANGE, YELLOW, GREEN, INDIGO, VIOLET] # traditional pride flag
|
||||||
|
# COLOUR_ORDER = [BLACK, BROWN, RED, ORANGE, YELLOW, GREEN, INDIGO, VIOLET] # Philadelphia pride flag
|
||||||
|
# COLOUR_ORDER = [BLUE, PINK, WHITE, PINK, BLUE] # trans flag
|
||||||
|
# COLOUR_ORDER = [MAGENTA, YELLOW, CYAN] # pan flag
|
||||||
|
# COLOUR_ORDER = [MAGENTA, VIOLET, INDIGO] # bi flag
|
||||||
|
|
||||||
|
# Change this for vertical stripes
|
||||||
|
STRIPES_DIRECTION = "horizontal"
|
||||||
|
|
||||||
|
# Draw the flag
|
||||||
|
if STRIPES_DIRECTION == "horizontal":
|
||||||
|
stripe_width = round(HEIGHT / len(COLOUR_ORDER))
|
||||||
|
for x in range(len(COLOUR_ORDER)):
|
||||||
|
display.set_pen(COLOUR_ORDER[x])
|
||||||
|
display.rectangle(0, stripe_width * x, WIDTH, stripe_width)
|
||||||
|
|
||||||
|
if STRIPES_DIRECTION == "vertical":
|
||||||
|
stripe_width = round(WIDTH / len(COLOUR_ORDER))
|
||||||
|
for x in range(len(COLOUR_ORDER)):
|
||||||
|
display.set_pen(COLOUR_ORDER[x])
|
||||||
|
display.rectangle(stripe_width * x, 0, stripe_width, HEIGHT)
|
||||||
|
|
||||||
|
display.update()
|
|
@ -1,16 +1,18 @@
|
||||||
# This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Display's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
|
# This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Display's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
|
||||||
|
# We're using a RAM intensive 64K colour palette here to get a nice smooth colour transition.
|
||||||
|
|
||||||
import utime
|
import time
|
||||||
import st7789
|
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_RGB565
|
||||||
from pimoroni import RGBLED
|
from pimoroni import RGBLED
|
||||||
|
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_DISPLAY, rotate=0)
|
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB565, rotate=0)
|
||||||
display.set_backlight(0.8)
|
display.set_backlight(0.8)
|
||||||
display.set_palette_mode(st7789.PALETTE_USER)
|
|
||||||
|
led = RGBLED(6, 7, 8)
|
||||||
|
|
||||||
WIDTH, HEIGHT = display.get_bounds()
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
|
|
||||||
led = RGBLED(6, 7, 8)
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
# From CPython Lib/colorsys.py
|
# From CPython Lib/colorsys.py
|
||||||
|
@ -39,18 +41,14 @@ def hsv_to_rgb(h, s, v):
|
||||||
|
|
||||||
h = 0
|
h = 0
|
||||||
|
|
||||||
BLACK = display.create_pen(0, 0, 0)
|
|
||||||
RAINBOW = BLACK + 1 # Put RAINBOW right after BLACK in the palette
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
h += 1
|
h += 1
|
||||||
r, g, b = [int(255 * c) for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)] # rainbow magic
|
r, g, b = [int(255 * c) for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)] # rainbow magic
|
||||||
led.set_rgb(r, g, b) # Set LED to a converted HSV value
|
led.set_rgb(r, g, b) # Set LED to a converted HSV value
|
||||||
display.set_palette(RAINBOW, st7789.RGB565(r, g, b)) # Create pen with converted HSV value
|
RAINBOW = display.create_pen(r, g, b) # Create pen with converted HSV value
|
||||||
display.set_pen(RAINBOW) # Set pen
|
display.set_pen(RAINBOW) # Set pen
|
||||||
display.clear() # Fill the screen with the colour
|
display.clear() # Fill the screen with the colour
|
||||||
display.set_pen(BLACK) # Set pen to black
|
display.set_pen(BLACK) # Set pen to black
|
||||||
display.text("pico disco!", 10, 10, 240, 6) # Add some text
|
display.text("pico disco!", 10, 10, 240, 6) # Add some text
|
||||||
display.update() # Update the display
|
display.update() # Update the display
|
||||||
utime.sleep(1.0 / 60)
|
time.sleep(1.0 / 60)
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
import gc
|
||||||
|
import time
|
||||||
|
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_RGB332
|
||||||
|
|
||||||
|
# PEN_RGB332 is an 8 bit, fixed 256 colour palette which conserves your RAM.
|
||||||
|
# Try switching the pen_type to PEN_RGB565 (16 bit, 65K colour) and see the difference!
|
||||||
|
|
||||||
|
display = PicoGraphics(DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB332, rotate=0)
|
||||||
|
|
||||||
|
# set up constants for drawing
|
||||||
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
|
|
||||||
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def free(full=False):
|
||||||
|
# Calculates RAM usage
|
||||||
|
gc.collect()
|
||||||
|
F = gc.mem_free()
|
||||||
|
A = gc.mem_alloc()
|
||||||
|
T = F + A
|
||||||
|
P = '{0:.2f}%'.format(F / T * 100)
|
||||||
|
if not full:
|
||||||
|
return P
|
||||||
|
else:
|
||||||
|
return (f"Total RAM \n{T} KB \nUnused RAM \n{F} KB \n({P} free)")
|
||||||
|
|
||||||
|
|
||||||
|
def hsv_to_rgb(h, s, v):
|
||||||
|
# From CPython Lib/colorsys.py
|
||||||
|
if s == 0.0:
|
||||||
|
return v, v, v
|
||||||
|
i = int(h * 6.0)
|
||||||
|
f = (h * 6.0) - i
|
||||||
|
p = v * (1.0 - s)
|
||||||
|
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_pen(BLACK)
|
||||||
|
RAINBOW = display.create_pen(r, g, b) # Create pen with converted HSV value
|
||||||
|
display.set_pen(RAINBOW)
|
||||||
|
display.set_font("bitmap8")
|
||||||
|
display.text(free(full=True), 0, 0, WIDTH, 3)
|
||||||
|
display.update()
|
||||||
|
time.sleep(1.0 / 60)
|
|
@ -2,28 +2,26 @@
|
||||||
# It's based on the thermometer example in the "Getting Started with MicroPython on the Raspberry Pi Pico" book, which is a great read if you're a beginner!
|
# It's based on the thermometer example in the "Getting Started with MicroPython on the Raspberry Pi Pico" book, which is a great read if you're a beginner!
|
||||||
|
|
||||||
import machine
|
import machine
|
||||||
import utime
|
import time
|
||||||
|
|
||||||
import st7789
|
|
||||||
from pimoroni import RGBLED
|
from pimoroni import RGBLED
|
||||||
|
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY
|
||||||
|
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_DISPLAY, rotate=0)
|
# set up the hardware
|
||||||
display.set_palette_mode(st7789.PALETTE_USER)
|
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, rotate=0)
|
||||||
|
sensor_temp = machine.ADC(4)
|
||||||
|
led = RGBLED(6, 7, 8)
|
||||||
|
|
||||||
# Set the display backlight to 50%
|
# set the display backlight to 50%
|
||||||
display.set_backlight(0.5)
|
display.set_backlight(0.5)
|
||||||
|
|
||||||
|
# set up constants for drawing
|
||||||
WIDTH, HEIGHT = display.get_bounds()
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
|
|
||||||
BLACK = display.create_pen(0, 0, 0)
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
WHITE = display.create_pen(255, 255, 255)
|
WHITE = display.create_pen(255, 255, 255)
|
||||||
TEMPERATURE = WHITE + 1
|
|
||||||
|
|
||||||
led = RGBLED(6, 7, 8)
|
conversion_factor = 3.3 / (65535) # used for calculating a temperature from the raw sensor reading
|
||||||
|
|
||||||
# reads from Pico's temp sensor and converts it into a more manageable number
|
|
||||||
sensor_temp = machine.ADC(4)
|
|
||||||
conversion_factor = 3.3 / (65535)
|
|
||||||
temp_min = 10
|
temp_min = 10
|
||||||
temp_max = 30
|
temp_max = 30
|
||||||
bar_width = 5
|
bar_width = 5
|
||||||
|
@ -69,10 +67,11 @@ while True:
|
||||||
temperatures.pop(0)
|
temperatures.pop(0)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
for t in temperatures:
|
for t in temperatures:
|
||||||
# chooses a pen colour based on the temperature and update the palette entry
|
# chooses a pen colour based on the temperature
|
||||||
display.set_palette(TEMPERATURE, st7789.RGB565(*temperature_to_color(t)))
|
TEMPERATURE_COLOUR = display.create_pen(*temperature_to_color(t))
|
||||||
display.set_pen(TEMPERATURE)
|
display.set_pen(TEMPERATURE_COLOUR)
|
||||||
|
|
||||||
# draws the reading as a tall, thin rectangle
|
# draws the reading as a tall, thin rectangle
|
||||||
display.rectangle(i, HEIGHT - (round(t) * 4), bar_width, HEIGHT)
|
display.rectangle(i, HEIGHT - (round(t) * 4), bar_width, HEIGHT)
|
||||||
|
@ -96,4 +95,4 @@ while True:
|
||||||
display.update()
|
display.update()
|
||||||
|
|
||||||
# waits for 5 seconds
|
# waits for 5 seconds
|
||||||
utime.sleep(5)
|
time.sleep(5)
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
import st7789
|
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER, PEN_P8
|
||||||
|
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_EXPLORER, rotate=0)
|
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER, pen_type=PEN_P8)
|
||||||
display.set_backlight(1.0)
|
|
||||||
|
|
||||||
WIDTH, HEIGHT = display.get_bounds()
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
|
|
||||||
|
# We're creating 100 balls with their own individual colour and 1 BG colour
|
||||||
|
# for a total of 101 colours, which will all fit in the custom 256 entry palette!
|
||||||
|
|
||||||
|
|
||||||
class Ball:
|
class Ball:
|
||||||
def __init__(self, x, y, r, dx, dy, pen):
|
def __init__(self, x, y, r, dx, dy, pen):
|
||||||
|
@ -33,7 +35,7 @@ for i in range(0, 100):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
BG = display.create_pen(32, 32, 64)
|
BG = display.create_pen(40, 40, 40)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
display.set_pen(BG)
|
display.set_pen(BG)
|
||||||
|
@ -58,5 +60,4 @@ while True:
|
||||||
display.circle(int(ball.x), int(ball.y), int(ball.r))
|
display.circle(int(ball.x), int(ball.y), int(ball.r))
|
||||||
|
|
||||||
display.update()
|
display.update()
|
||||||
|
time.sleep(0.01)
|
||||||
time.sleep(0.01)
|
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
# This example shows you a simple, non-interrupt way of reading Pico Explorer's buttons with a loop that checks to see if buttons are pressed.
|
||||||
|
|
||||||
|
import time
|
||||||
|
from pimoroni import Button
|
||||||
|
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER, PEN_P4
|
||||||
|
import picoexplorer
|
||||||
|
|
||||||
|
# We're only using a few colours so we can use a 4 bit/16 colour palette and save RAM!
|
||||||
|
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER, pen_type=PEN_P4)
|
||||||
|
|
||||||
|
button_a = Button(picoexplorer.BUTTON_A)
|
||||||
|
button_b = Button(picoexplorer.BUTTON_B)
|
||||||
|
button_x = Button(picoexplorer.BUTTON_X)
|
||||||
|
button_y = Button(picoexplorer.BUTTON_Y)
|
||||||
|
|
||||||
|
# alternatively, you could set up the buttons using pin number if you prefer
|
||||||
|
# button_a = Button(12)
|
||||||
|
# button_b = Button(13)
|
||||||
|
# button_x = Button(14)
|
||||||
|
# button_y = Button(15)
|
||||||
|
|
||||||
|
WHITE = display.create_pen(255, 255, 255)
|
||||||
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
|
CYAN = display.create_pen(0, 255, 255)
|
||||||
|
MAGENTA = display.create_pen(255, 0, 255)
|
||||||
|
YELLOW = display.create_pen(255, 255, 0)
|
||||||
|
GREEN = display.create_pen(0, 255, 0)
|
||||||
|
|
||||||
|
|
||||||
|
# sets up a handy function we can call to clear the screen
|
||||||
|
def clear():
|
||||||
|
display.set_pen(BLACK)
|
||||||
|
display.clear()
|
||||||
|
display.update()
|
||||||
|
|
||||||
|
|
||||||
|
# set up
|
||||||
|
clear()
|
||||||
|
display.set_font("bitmap8")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if button_a.read(): # if a button press is detected then...
|
||||||
|
clear() # clear to black
|
||||||
|
display.set_pen(WHITE) # change the pen colour
|
||||||
|
display.text("Button A pressed", 10, 10, 240, 4) # display some text on the screen
|
||||||
|
display.update() # update the display
|
||||||
|
time.sleep(1) # pause for a sec
|
||||||
|
clear() # clear to black again
|
||||||
|
elif button_b.read():
|
||||||
|
clear()
|
||||||
|
display.set_pen(CYAN)
|
||||||
|
display.text("Button B pressed", 10, 10, 240, 4)
|
||||||
|
display.update()
|
||||||
|
time.sleep(1)
|
||||||
|
clear()
|
||||||
|
elif button_x.read():
|
||||||
|
clear()
|
||||||
|
display.set_pen(MAGENTA)
|
||||||
|
display.text("Button X pressed", 10, 10, 240, 4)
|
||||||
|
display.update()
|
||||||
|
time.sleep(1)
|
||||||
|
clear()
|
||||||
|
elif button_y.read():
|
||||||
|
clear()
|
||||||
|
display.set_pen(YELLOW)
|
||||||
|
display.text("Button Y pressed", 10, 10, 240, 4)
|
||||||
|
display.update()
|
||||||
|
time.sleep(1)
|
||||||
|
clear()
|
||||||
|
else:
|
||||||
|
display.set_pen(GREEN)
|
||||||
|
display.text("Press any button!", 10, 10, 240, 4)
|
||||||
|
display.update()
|
||||||
|
time.sleep(0.1) # this number is how frequently the Pico checks for button presses
|
|
@ -1,66 +0,0 @@
|
||||||
# This example shows you a simple, non-interrupt way of reading Pico Explorer's buttons with a loop that checks to see if buttons are pressed.
|
|
||||||
|
|
||||||
import utime
|
|
||||||
import st7789
|
|
||||||
import picoexplorer
|
|
||||||
from pimoroni import Button
|
|
||||||
|
|
||||||
|
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_EXPLORER, rotate=0)
|
|
||||||
display.set_palette_mode(st7789.PALETTE_USER)
|
|
||||||
display.set_backlight(1.0)
|
|
||||||
|
|
||||||
button_a = Button(picoexplorer.BUTTON_A)
|
|
||||||
button_b = Button(picoexplorer.BUTTON_B)
|
|
||||||
button_x = Button(picoexplorer.BUTTON_X)
|
|
||||||
button_y = Button(picoexplorer.BUTTON_Y)
|
|
||||||
|
|
||||||
WHITE = display.create_pen(255, 255, 255)
|
|
||||||
BLACK = display.create_pen(0, 0, 0)
|
|
||||||
TEAL = display.create_pen(0, 255, 255)
|
|
||||||
MAGENTA = display.create_pen(255, 0, 255)
|
|
||||||
YELLOW = display.create_pen(255, 255, 0)
|
|
||||||
RED = display.create_pen(255, 0, 0)
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
|
||||||
if button_a.is_pressed: # if a button press is detected then...
|
|
||||||
display.set_pen(BLACK) # set pen to black
|
|
||||||
display.clear() # clear display to the pen colour
|
|
||||||
display.set_pen(WHITE) # 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
|
|
||||||
|
|
||||||
elif button_b.is_pressed:
|
|
||||||
display.set_pen(BLACK)
|
|
||||||
display.clear()
|
|
||||||
display.set_pen(TEAL)
|
|
||||||
display.text("Button B pressed", 10, 10, 240, 4)
|
|
||||||
display.update()
|
|
||||||
utime.sleep(1)
|
|
||||||
|
|
||||||
elif button_x.is_pressed:
|
|
||||||
display.set_pen(BLACK)
|
|
||||||
display.clear()
|
|
||||||
display.set_pen(MAGENTA)
|
|
||||||
display.text("Button X pressed", 10, 10, 240, 4)
|
|
||||||
display.update()
|
|
||||||
utime.sleep(1)
|
|
||||||
|
|
||||||
elif button_y.is_pressed:
|
|
||||||
display.set_pen(BLACK)
|
|
||||||
display.clear()
|
|
||||||
display.set_pen(YELLOW)
|
|
||||||
display.text("Button Y pressed", 10, 10, 240, 4)
|
|
||||||
display.update()
|
|
||||||
utime.sleep(1)
|
|
||||||
|
|
||||||
else:
|
|
||||||
display.set_pen(BLACK)
|
|
||||||
display.clear()
|
|
||||||
display.set_pen(RED)
|
|
||||||
display.text("Press any button!", 10, 10, 240, 4)
|
|
||||||
display.update()
|
|
||||||
|
|
||||||
utime.sleep(0.1) # this number is how frequently the Pico checks for button presses
|
|
|
@ -1,13 +1,10 @@
|
||||||
import time
|
import time
|
||||||
import st7789
|
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER
|
||||||
from motor import Motor
|
from motor import Motor
|
||||||
import picoexplorer
|
import picoexplorer
|
||||||
from pimoroni import Button, Analog, Buzzer
|
from pimoroni import Button, Analog, Buzzer
|
||||||
|
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_EXPLORER, rotate=0)
|
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)
|
||||||
display.set_palette_mode(st7789.PALETTE_USER)
|
|
||||||
display.set_backlight(1.0)
|
|
||||||
|
|
||||||
|
|
||||||
adc0 = Analog(picoexplorer.ADC0)
|
adc0 = Analog(picoexplorer.ADC0)
|
||||||
adc1 = Analog(picoexplorer.ADC1)
|
adc1 = Analog(picoexplorer.ADC1)
|
||||||
|
@ -21,9 +18,9 @@ button_y = Button(picoexplorer.BUTTON_Y)
|
||||||
BG = display.create_pen(32, 32, 64)
|
BG = display.create_pen(32, 32, 64)
|
||||||
WHITE = display.create_pen(255, 255, 255)
|
WHITE = display.create_pen(255, 255, 255)
|
||||||
|
|
||||||
ADC0_PEN = display.reserve_palette()
|
ADC0_PEN = display.create_pen(255, 0, 0)
|
||||||
ADC1_PEN = display.reserve_palette()
|
ADC1_PEN = display.create_pen(0, 255, 0)
|
||||||
ADC2_PEN = display.reserve_palette()
|
ADC2_PEN = display.create_pen(0, 0, 255)
|
||||||
|
|
||||||
MOTOR1 = Motor(picoexplorer.MOTOR_1)
|
MOTOR1 = Motor(picoexplorer.MOTOR_1)
|
||||||
MOTOR2 = Motor(picoexplorer.MOTOR_2)
|
MOTOR2 = Motor(picoexplorer.MOTOR_2)
|
||||||
|
@ -41,11 +38,6 @@ while True:
|
||||||
adc1v = int(adc1.read_voltage() / 3.3 * 120)
|
adc1v = int(adc1.read_voltage() / 3.3 * 120)
|
||||||
adc2v = int(adc2.read_voltage() / 3.3 * 120)
|
adc2v = int(adc2.read_voltage() / 3.3 * 120)
|
||||||
|
|
||||||
# Update our ADC channel palette colours
|
|
||||||
display.set_palette(ADC0_PEN, st7789.RGB565(adc0v * 2, 10, 10))
|
|
||||||
display.set_palette(ADC1_PEN, st7789.RGB565(10, adc1v * 2, 10))
|
|
||||||
display.set_palette(ADC2_PEN, st7789.RGB565(10, 10, adc2v * 2))
|
|
||||||
|
|
||||||
# ADC labels
|
# ADC labels
|
||||||
display.set_pen(WHITE)
|
display.set_pen(WHITE)
|
||||||
display.text("ADC0:", 20, 20, 100)
|
display.text("ADC0:", 20, 20, 100)
|
||||||
|
|
|
@ -2,17 +2,14 @@
|
||||||
# It uses code written by Avram Piltch - check out his Tom's Hardware article! https://www.tomshardware.com/uk/how-to/buzzer-music-raspberry-pi-pico
|
# It uses code written by Avram Piltch - check out his Tom's Hardware article! https://www.tomshardware.com/uk/how-to/buzzer-music-raspberry-pi-pico
|
||||||
# You'll need to connect a jumper wire between GPO and AUDIO on the Explorer Base to hear noise.
|
# You'll need to connect a jumper wire between GPO and AUDIO on the Explorer Base to hear noise.
|
||||||
|
|
||||||
import utime
|
import time
|
||||||
import st7789
|
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER
|
||||||
from pimoroni import Buzzer
|
from pimoroni import Buzzer
|
||||||
|
|
||||||
|
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)
|
||||||
|
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_EXPLORER, rotate=0)
|
# Create a buzzer on pin 0
|
||||||
display.set_palette_mode(st7789.PALETTE_USER)
|
# Don't forget to wire GP0 to AUDIO!
|
||||||
display.set_backlight(1.0)
|
|
||||||
|
|
||||||
# tCreate a buzzer on pin 0
|
|
||||||
# Don't forget t write GP0 to AUDIO!
|
|
||||||
BUZZER = Buzzer(0)
|
BUZZER = Buzzer(0)
|
||||||
|
|
||||||
BLACK = display.create_pen(0, 0, 0)
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
|
@ -143,7 +140,7 @@ def playsong(song): # this function plays your song
|
||||||
clear()
|
clear()
|
||||||
a = 0
|
a = 0
|
||||||
display.update()
|
display.update()
|
||||||
utime.sleep(0.15) # change this number if you want to alter how long the notes play for
|
time.sleep(0.15) # change this number if you want to alter how long the notes play for
|
||||||
bequiet()
|
bequiet()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,14 @@
|
||||||
# This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Explorer's screen.
|
# This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Explorer's screen. If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
|
||||||
# If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
|
# We're using a RAM intensive 64K colour palette here to get a nice smooth colour transition.
|
||||||
|
|
||||||
import utime
|
import time
|
||||||
import st7789
|
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER, PEN_RGB565
|
||||||
|
|
||||||
|
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER, pen_type=PEN_RGB565)
|
||||||
|
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_EXPLORER, rotate=0)
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
display.set_palette_mode(st7789.PALETTE_USER)
|
|
||||||
display.set_backlight(1.0)
|
|
||||||
|
|
||||||
# Create a text colour
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
TEXT_COLOR = display.create_pen(0, 0, 0)
|
|
||||||
|
|
||||||
# Reserve a palette entry for our rainbow background colour
|
|
||||||
RAINBOW = display.reserve_palette()
|
|
||||||
|
|
||||||
|
|
||||||
# From CPython Lib/colorsys.py
|
# From CPython Lib/colorsys.py
|
||||||
|
@ -45,12 +40,12 @@ h = 0
|
||||||
while True:
|
while True:
|
||||||
h += 1
|
h += 1
|
||||||
r, g, b = [int(255 * c) for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)] # rainbow magic
|
r, g, b = [int(255 * c) for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)] # rainbow magic
|
||||||
display.set_palette(RAINBOW, st7789.RGB565(r, g, b)) # Set pen to a converted HSV value
|
RAINBOW = display.create_pen(r, g, b) # Create pen with converted HSV value
|
||||||
display.set_pen(RAINBOW)
|
display.set_pen(RAINBOW) # Set pen
|
||||||
display.clear() # Fill the screen with the colour
|
display.clear() # Fill the screen with the colour
|
||||||
display.set_pen(TEXT_COLOR)
|
display.set_pen(BLACK) # Set pen to black
|
||||||
display.text("pico disco!", 25, 20, 240, 6) # Add some text
|
display.text("pico disco!", 10, 10, 240, 6) # Add some text
|
||||||
display.text("\\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/", 25, 120, 240, 4) # and some more text
|
display.text("\\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/", 25, 120, 240, 4) # and some more text
|
||||||
display.text("oontz oontz oontz", 25, 220, 240, 2) # and a bit more tiny text
|
display.text("oontz oontz oontz", 25, 220, 240, 2) # and a bit more tiny text
|
||||||
display.update() # Update the display
|
display.update() # Update the display
|
||||||
utime.sleep(1.0 / 60)
|
time.sleep(1.0 / 60)
|
||||||
|
|
|
@ -1,63 +1,90 @@
|
||||||
# This example takes the temperature from the Pico's onboard temperature sensor, and displays it on Pico Explorer, along with a little pixelly graph.
|
# This example takes the temperature from the Pico's onboard temperature sensor, and displays it on Pico Explorer, along with a little pixelly graph.
|
||||||
# It's based on the thermometer example in the "Getting Started with MicroPython on the Raspberry Pi Pico" book, which is a great read if you're a beginner!
|
# It's based on the thermometer example in the "Getting Started with MicroPython on the Raspberry Pi Pico" book, which is a great read if you're a beginner!
|
||||||
|
|
||||||
import st7789
|
|
||||||
import machine
|
import machine
|
||||||
import utime
|
import time
|
||||||
|
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER
|
||||||
|
|
||||||
# Pico Explorer boilerplate
|
# set up the hardware
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_EXPLORER, rotate=0)
|
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)
|
||||||
display.set_palette_mode(st7789.PALETTE_USER)
|
|
||||||
display.set_backlight(1.0)
|
|
||||||
|
|
||||||
WIDTH, HEIGHT = display.get_bounds()
|
|
||||||
|
|
||||||
# reads from Pico's temp sensor and converts it into a more manageable number
|
|
||||||
sensor_temp = machine.ADC(4)
|
sensor_temp = machine.ADC(4)
|
||||||
conversion_factor = 3.3 / (65535)
|
|
||||||
|
# set up constants for drawing
|
||||||
|
WIDTH, HEIGHT = display.get_bounds()
|
||||||
|
|
||||||
BLACK = display.create_pen(0, 0, 0)
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
WHITE = display.create_pen(255, 255, 255)
|
WHITE = display.create_pen(255, 255, 255)
|
||||||
RED = display.create_pen(255, 0, 0)
|
|
||||||
GREEN = display.create_pen(0, 255, 0)
|
|
||||||
BLUE = display.create_pen(0, 0, 255)
|
|
||||||
|
|
||||||
i = 0
|
conversion_factor = 3.3 / (65535) # used for calculating a temperature from the raw sensor reading
|
||||||
|
|
||||||
|
temp_min = 10
|
||||||
|
temp_max = 30
|
||||||
|
bar_width = 5
|
||||||
|
|
||||||
|
temperatures = []
|
||||||
|
|
||||||
|
colors = [(0, 0, 255), (0, 255, 0), (255, 255, 0), (255, 0, 0)]
|
||||||
|
|
||||||
|
|
||||||
|
def temperature_to_color(temp):
|
||||||
|
temp = min(temp, temp_max)
|
||||||
|
temp = max(temp, temp_min)
|
||||||
|
|
||||||
|
f_index = float(temp - temp_min) / float(temp_max - temp_min)
|
||||||
|
f_index *= len(colors) - 1
|
||||||
|
index = int(f_index)
|
||||||
|
|
||||||
|
if index == len(colors) - 1:
|
||||||
|
return colors[index]
|
||||||
|
|
||||||
|
blend_b = f_index - index
|
||||||
|
blend_a = 1.0 - blend_b
|
||||||
|
|
||||||
|
a = colors[index]
|
||||||
|
b = colors[index + 1]
|
||||||
|
|
||||||
|
return [int((a[i] * blend_a) + (b[i] * blend_b)) for i in range(3)]
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
# fills the screen with black
|
||||||
|
display.set_pen(BLACK)
|
||||||
|
display.clear()
|
||||||
|
|
||||||
# the following two lines do some maths to convert the number from the temp sensor into celsius
|
# the following two lines do some maths to convert the number from the temp sensor into celsius
|
||||||
reading = sensor_temp.read_u16() * conversion_factor
|
reading = sensor_temp.read_u16() * conversion_factor
|
||||||
temperature = round(27 - (reading - 0.706) / 0.001721)
|
temperature = 27 - (reading - 0.706) / 0.001721
|
||||||
|
|
||||||
# this if statement clears the display once the graph reaches the right hand side of the display
|
temperatures.append(temperature)
|
||||||
if i >= WIDTH + 1:
|
|
||||||
i = 0
|
|
||||||
display.set_pen(BLACK)
|
|
||||||
display.clear()
|
|
||||||
|
|
||||||
# chooses a pen colour based on the temperature
|
# shifts the temperatures history to the left by one sample
|
||||||
display.set_pen(GREEN)
|
if len(temperatures) > WIDTH // bar_width:
|
||||||
if temperature > 20:
|
temperatures.pop(0)
|
||||||
display.set_pen(RED)
|
|
||||||
if temperature < 13:
|
|
||||||
display.set_pen(BLUE)
|
|
||||||
|
|
||||||
# draws the reading as a tall, thin rectangle
|
i = 0
|
||||||
display.rectangle(i, HEIGHT - (temperature * 6), 6, HEIGHT)
|
|
||||||
|
for t in temperatures:
|
||||||
|
# chooses a pen colour based on the temperature
|
||||||
|
TEMPERATURE_COLOUR = display.create_pen(*temperature_to_color(t))
|
||||||
|
display.set_pen(TEMPERATURE_COLOUR)
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
# draws a white background for the text
|
# draws a white background for the text
|
||||||
display.set_pen(WHITE)
|
display.set_pen(WHITE)
|
||||||
display.rectangle(1, 1, 65, 33)
|
display.rectangle(1, 1, 100, 25)
|
||||||
|
|
||||||
# writes the reading as text in the white rectangle
|
# writes the reading as text in the white rectangle
|
||||||
display.set_pen(BLACK)
|
display.set_pen(BLACK)
|
||||||
display.text("{:.0f}".format(temperature) + "c", 3, 3, 0, 4)
|
display.text("{:.2f}".format(temperature) + "c", 3, 3, 0, 3)
|
||||||
|
|
||||||
# time to update the display
|
# time to update the display
|
||||||
display.update()
|
display.update()
|
||||||
|
|
||||||
# waits for 5 seconds
|
# waits for 5 seconds
|
||||||
utime.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
# the next tall thin rectangle needs to be drawn 6 pixels to the right of the last one
|
|
||||||
i += 6
|
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
# This example lets you plug a BME280 breakout into your Pico Explorer and make a little indoor weather station, with barometer style descriptions.
|
# This example lets you plug a BME280 breakout into your Pico Explorer and make a little indoor weather station, with barometer style descriptions.
|
||||||
|
|
||||||
import utime
|
import time
|
||||||
|
|
||||||
from breakout_bme280 import BreakoutBME280
|
from breakout_bme280 import BreakoutBME280
|
||||||
from pimoroni_i2c import PimoroniI2C
|
from pimoroni_i2c import PimoroniI2C
|
||||||
from pimoroni import PICO_EXPLORER_I2C_PINS
|
from pimoroni import PICO_EXPLORER_I2C_PINS
|
||||||
|
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER
|
||||||
|
|
||||||
# Pico Explorer boilerplate
|
# set up the hardware
|
||||||
import st7789
|
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_EXPLORER, rotate=0)
|
|
||||||
display.set_palette_mode(st7789.PALETTE_USER)
|
|
||||||
display.set_backlight(1.0)
|
|
||||||
|
|
||||||
i2c = PimoroniI2C(**PICO_EXPLORER_I2C_PINS)
|
i2c = PimoroniI2C(**PICO_EXPLORER_I2C_PINS)
|
||||||
bme = BreakoutBME280(i2c)
|
bme = BreakoutBME280(i2c, address=0x76)
|
||||||
|
|
||||||
# lets set up some pen colours to make drawing easier
|
# lets set up some pen colours to make drawing easier
|
||||||
TEMPCOLOUR = display.reserve_palette() # this colour will get changed in a bit
|
TEMPCOLOUR = display.create_pen(0, 0, 0) # this colour will get changed in a bit
|
||||||
WHITE = display.create_pen(255, 255, 255)
|
WHITE = display.create_pen(255, 255, 255)
|
||||||
BLACK = display.create_pen(0, 0, 0)
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
RED = display.create_pen(255, 0, 0)
|
RED = display.create_pen(255, 0, 0)
|
||||||
|
@ -28,22 +24,22 @@ def describe_temperature(temperature):
|
||||||
global TEMPCOLOUR
|
global TEMPCOLOUR
|
||||||
if temperature < 10:
|
if temperature < 10:
|
||||||
description = "very cold"
|
description = "very cold"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 255, 255))
|
TEMPCOLOUR = display.create_pen(0, 255, 255)
|
||||||
elif 10 <= temperature < 20:
|
elif 10 <= temperature < 20:
|
||||||
description = "cold"
|
description = "cold"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 0, 255))
|
TEMPCOLOUR = display.create_pen(0, 0, 255)
|
||||||
elif 20 <= temperature < 25:
|
elif 20 <= temperature < 25:
|
||||||
description = "temperate"
|
description = "temperate"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 255, 0))
|
TEMPCOLOUR = display.create_pen(0, 255, 0)
|
||||||
elif 25 <= temperature < 30:
|
elif 25 <= temperature < 30:
|
||||||
description = "warm"
|
description = "warm"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(255, 255, 0))
|
TEMPCOLOUR = display.create_pen(255, 255, 0)
|
||||||
elif temperature >= 30:
|
elif temperature >= 30:
|
||||||
description = "very warm"
|
description = "very warm"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(255, 0, 0))
|
TEMPCOLOUR = display.create_pen(255, 0, 0)
|
||||||
else:
|
else:
|
||||||
description = ""
|
description = ""
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 0, 0))
|
TEMPCOLOUR = display.create_pen(0, 0, 0)
|
||||||
return description
|
return description
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,22 +49,22 @@ def describe_temperature(temperature):
|
||||||
global TEMPCOLOUR
|
global TEMPCOLOUR
|
||||||
if temperature < 10:
|
if temperature < 10:
|
||||||
description = "frozzed"
|
description = "frozzed"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 255, 255))
|
TEMPCOLOUR = display.create_pen(0, 255, 255)
|
||||||
elif 10 <= temperature < 20:
|
elif 10 <= temperature < 20:
|
||||||
description = "nithering"
|
description = "nithering"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 0, 255))
|
TEMPCOLOUR = display.create_pen(0, 0, 255)
|
||||||
elif 20 <= temperature < 25:
|
elif 20 <= temperature < 25:
|
||||||
description = "fair t' middlin"
|
description = "fair t' middlin"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 255, 0))
|
TEMPCOLOUR = display.create_pen(0, 255, 0)
|
||||||
elif 25 <= temperature < 30:
|
elif 25 <= temperature < 30:
|
||||||
description = "chuffing warm"
|
description = "chuffing warm"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(255, 255, 0))
|
TEMPCOLOUR = display.create_pen(255, 255, 0)
|
||||||
elif temperature >= 30:
|
elif temperature >= 30:
|
||||||
description = "crackin t' flags"
|
description = "crackin t' flags"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(255, 0, 0))
|
TEMPCOLOUR = display.create_pen(255, 0, 0)
|
||||||
else:
|
else:
|
||||||
description = ""
|
description = ""
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 0, 0))
|
TEMPCOLOUR = display.create_pen(0, 0, 0)
|
||||||
return description
|
return description
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -145,4 +141,4 @@ while True:
|
||||||
display.update()
|
display.update()
|
||||||
|
|
||||||
# waits for 1 second and clears to BLACK
|
# waits for 1 second and clears to BLACK
|
||||||
utime.sleep(1)
|
time.sleep(1)
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
# This example lets you plug a BME680 or BME688 breakout into your Pico Explorer to make a little indoor weather station, with barometer style descriptions.
|
# This example lets you plug a BME680 or BME688 breakout into your Pico Explorer to make a little indoor weather station, with barometer style descriptions.
|
||||||
|
|
||||||
import utime
|
import time
|
||||||
|
|
||||||
from breakout_bme68x import BreakoutBME68X
|
from breakout_bme68x import BreakoutBME68X
|
||||||
from pimoroni_i2c import PimoroniI2C
|
from pimoroni_i2c import PimoroniI2C
|
||||||
from pimoroni import PICO_EXPLORER_I2C_PINS
|
from pimoroni import PICO_EXPLORER_I2C_PINS
|
||||||
|
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER
|
||||||
|
|
||||||
# Pico Explorer boilerplate
|
# set up the hardware
|
||||||
import st7789
|
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)
|
||||||
display = st7789.ST7789(st7789.DISPLAY_PICO_EXPLORER, rotate=0)
|
|
||||||
display.set_palette_mode(st7789.PALETTE_USER)
|
|
||||||
display.set_backlight(1.0)
|
|
||||||
|
|
||||||
i2c = PimoroniI2C(**PICO_EXPLORER_I2C_PINS)
|
i2c = PimoroniI2C(**PICO_EXPLORER_I2C_PINS)
|
||||||
bme = BreakoutBME68X(i2c)
|
bme = BreakoutBME68X(i2c, address=0x76)
|
||||||
|
|
||||||
# lets set up some pen colours to make drawing easier
|
# lets set up some pen colours to make drawing easier
|
||||||
TEMPCOLOUR = display.reserve_palette() # this colour will get changed in a bit
|
TEMPCOLOUR = display.create_pen(0, 0, 0) # this colour will get changed in a bit
|
||||||
WHITE = display.create_pen(255, 255, 255)
|
WHITE = display.create_pen(255, 255, 255)
|
||||||
BLACK = display.create_pen(0, 0, 0)
|
BLACK = display.create_pen(0, 0, 0)
|
||||||
RED = display.create_pen(255, 0, 0)
|
RED = display.create_pen(255, 0, 0)
|
||||||
|
@ -28,22 +24,22 @@ def describe_temperature(temperature):
|
||||||
global TEMPCOLOUR
|
global TEMPCOLOUR
|
||||||
if temperature < 10:
|
if temperature < 10:
|
||||||
description = "very cold"
|
description = "very cold"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 255, 255))
|
TEMPCOLOUR = display.create_pen(0, 255, 255)
|
||||||
elif 10 <= temperature < 20:
|
elif 10 <= temperature < 20:
|
||||||
description = "cold"
|
description = "cold"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 0, 255))
|
TEMPCOLOUR = display.create_pen(0, 0, 255)
|
||||||
elif 20 <= temperature < 25:
|
elif 20 <= temperature < 25:
|
||||||
description = "temperate"
|
description = "temperate"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 255, 0))
|
TEMPCOLOUR = display.create_pen(0, 255, 0)
|
||||||
elif 25 <= temperature < 30:
|
elif 25 <= temperature < 30:
|
||||||
description = "warm"
|
description = "warm"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(255, 255, 0))
|
TEMPCOLOUR = display.create_pen(255, 255, 0)
|
||||||
elif temperature >= 30:
|
elif temperature >= 30:
|
||||||
description = "very warm"
|
description = "very warm"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(255, 0, 0))
|
TEMPCOLOUR = display.create_pen(255, 0, 0)
|
||||||
else:
|
else:
|
||||||
description = ""
|
description = ""
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 0, 0))
|
TEMPCOLOUR = display.create_pen(0, 0, 0)
|
||||||
return description
|
return description
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,22 +49,22 @@ def describe_temperature(temperature):
|
||||||
global TEMPCOLOUR
|
global TEMPCOLOUR
|
||||||
if temperature < 10:
|
if temperature < 10:
|
||||||
description = "frozzed"
|
description = "frozzed"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 255, 255))
|
TEMPCOLOUR = display.create_pen(0, 255, 255)
|
||||||
elif 10 <= temperature < 20:
|
elif 10 <= temperature < 20:
|
||||||
description = "nithering"
|
description = "nithering"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 0, 255))
|
TEMPCOLOUR = display.create_pen(0, 0, 255)
|
||||||
elif 20 <= temperature < 25:
|
elif 20 <= temperature < 25:
|
||||||
description = "fair t' middlin"
|
description = "fair t' middlin"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 255, 0))
|
TEMPCOLOUR = display.create_pen(0, 255, 0)
|
||||||
elif 25 <= temperature < 30:
|
elif 25 <= temperature < 30:
|
||||||
description = "chuffing warm"
|
description = "chuffing warm"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(255, 255, 0))
|
TEMPCOLOUR = display.create_pen(255, 255, 0)
|
||||||
elif temperature >= 30:
|
elif temperature >= 30:
|
||||||
description = "crackin t' flags"
|
description = "crackin t' flags"
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(255, 0, 0))
|
TEMPCOLOUR = display.create_pen(255, 0, 0)
|
||||||
else:
|
else:
|
||||||
description = ""
|
description = ""
|
||||||
display.set_palette(TEMPCOLOUR, st7789.RGB565(0, 0, 0))
|
TEMPCOLOUR = display.create_pen(0, 0, 0)
|
||||||
return description
|
return description
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -146,4 +142,4 @@ while True:
|
||||||
display.update()
|
display.update()
|
||||||
|
|
||||||
# waits for 1 second and clears to BLACK
|
# waits for 1 second and clears to BLACK
|
||||||
utime.sleep(1)
|
time.sleep(1)
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
# This example shows you a simple, non-interrupt way of reading Pico Inky Pack's buttons with a loop that checks to see if buttons are pressed.
|
||||||
|
|
||||||
|
import time
|
||||||
|
from pimoroni import Button
|
||||||
|
from picographics import PicoGraphics, DISPLAY_INKY_PACK
|
||||||
|
|
||||||
|
display = PicoGraphics(display=DISPLAY_INKY_PACK)
|
||||||
|
|
||||||
|
# you can change the update speed here!
|
||||||
|
# it goes from 0 (slowest) to 3 (fastest)
|
||||||
|
display.set_update_speed(2)
|
||||||
|
|
||||||
|
display.set_font("bitmap8")
|
||||||
|
|
||||||
|
button_a = Button(12)
|
||||||
|
button_b = Button(13)
|
||||||
|
button_c = Button(14)
|
||||||
|
|
||||||
|
|
||||||
|
# a handy function we can call to clear the screen
|
||||||
|
# display.set_pen(15) is white and display.set_pen(0) is black
|
||||||
|
def clear():
|
||||||
|
display.set_pen(15)
|
||||||
|
display.clear()
|
||||||
|
|
||||||
|
|
||||||
|
# set up
|
||||||
|
clear()
|
||||||
|
display.set_pen(0)
|
||||||
|
display.text("Press any button!", 10, 10, 240, 3)
|
||||||
|
display.update()
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if button_a.read(): # if a button press is detected then...
|
||||||
|
clear() # clear to white
|
||||||
|
display.set_pen(0) # change the pen colour
|
||||||
|
display.text("Button A pressed", 10, 10, 240, 3) # display some text on the screen
|
||||||
|
display.update() # update the display
|
||||||
|
time.sleep(0.5)
|
||||||
|
elif button_b.read():
|
||||||
|
clear()
|
||||||
|
display.set_pen(0)
|
||||||
|
display.text("Button B pressed", 10, 50, 240, 3)
|
||||||
|
display.update()
|
||||||
|
time.sleep(0.5)
|
||||||
|
elif button_c.read():
|
||||||
|
clear()
|
||||||
|
display.set_pen(0)
|
||||||
|
display.text("Button C pressed", 10, 90, 240, 3)
|
||||||
|
display.update()
|
||||||
|
time.sleep(0.5)
|
||||||
|
time.sleep(0.1) # this number is how frequently the Pico checks for button presses
|
|
@ -19,11 +19,14 @@ RED = display.create_pen(200, 0, 0)
|
||||||
# Read name from file
|
# Read name from file
|
||||||
try:
|
try:
|
||||||
file = open("badge.txt", "r")
|
file = open("badge.txt", "r")
|
||||||
name = file.readline()
|
|
||||||
file.close()
|
|
||||||
except OSError:
|
except OSError:
|
||||||
name = "open name.txt in thonny to edit badge :)"
|
with open("badge.txt", "w") as f:
|
||||||
|
f.write("open badge.txt in thonny to edit badge :)")
|
||||||
|
f.flush()
|
||||||
|
file = open("badge.txt", "r")
|
||||||
|
|
||||||
|
name = file.readline()
|
||||||
|
file.close()
|
||||||
|
|
||||||
text_size = 12
|
text_size = 12
|
||||||
text_x = 0
|
text_x = 0
|
||||||
|
|
Ładowanie…
Reference in New Issue