correct layout on pico display 1 & 2

This commit is contained in:
thirdr 2024-04-24 12:13:03 +01:00
parent 14877b1793
commit eb841fbe53
1 changed files with 17 additions and 5 deletions

View File

@ -1,8 +1,11 @@
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P8
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_P8
import pngdec
# Create a PicoGraphics instance
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P8, rotate=270)
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, pen_type=PEN_P8, rotate=270)
# Get the display width/height so we can position the PNGs
width, height = display.get_bounds()
# Set the backlight so we can see it!
display.set_backlight(1.0)
@ -33,15 +36,24 @@ for i in range(3):
display.set_pen(BG)
display.clear()
try:
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
# You can use Thonny to transfer PNG Images to your Pico.
png.open_file("pencil_gray.png")
# Horizontally/vertically center the three PNG Images.
png_w = png.get_width()
png_h = png.get_height()
offset_x = (width - png_w * 2) // 2
height_y = (height // 3)
offset_y = (height_y - png_h * 2) // 2
# Decode our PNG file and set the X and Y
png.decode(35, 10, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
png.decode(35, 90, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
png.decode(35, 170, scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
png.decode(offset_x, offset_y, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
png.decode(offset_x, offset_y + height_y, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
png.decode(offset_x, offset_y + (height_y * 2), scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
# Handle the error if the image doesn't exist on the flash.
except OSError: