ST7789/PicoGraphics: Update some examples.

driver/sh1107
Phil Howard 2022-05-28 01:19:58 +01:00
rodzic a483b2aad4
commit 844a5af384
6 zmienionych plików z 46 dodań i 44 usunięć

Wyświetl plik

@ -1,10 +1,10 @@
import time
import random
from st7789 import ST7789, PALETTE_USER
from st7789 import ST7789, PALETTE_USER, DISPLAY_LCD_240X240
WIDTH, HEIGHT = 240, 240
display = ST7789(DISPLAY_LCD_240X240, rotate=0)
display = ST7789(WIDTH, HEIGHT, round=False)
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 256 entry palette!
@ -37,7 +37,7 @@ for i in range(0, 100):
display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
)
)
BG = display.create_pen(40, 40, 40)
while True:
@ -64,4 +64,3 @@ while True:
display.update()
time.sleep(0.01)

Wyświetl plik

@ -1,12 +1,12 @@
import st7789
import qrcode
# Set the display resolution
# in most cases you can swap WIDTH weith HEIGHT for portrait mode
WIDTH, HEIGHT = 240, 135 # Pico Display
# WIDTH, HEIGHT = 320, 240 # Pico Display 2.0
display = st7789.ST7789(st7789.DISPLAY_PICO_DISPLAY, rotate=0)
display = st7789.ST7789(WIDTH, HEIGHT, rotate180=False)
WIDTH, HEIGHT = display.get_bounds()
BG = display.create_pen(0, 0, 0)
FG = display.create_pen(128, 128, 128)
def measure_qr_code(size, code):
@ -17,9 +17,9 @@ def measure_qr_code(size, code):
def draw_qr_code(ox, oy, size, code):
size, module_size = measure_qr_code(size, code)
display.set_pen(128, 128, 128)
display.set_pen(FG)
display.rectangle(ox, oy, size, size)
display.set_pen(0, 0, 0)
display.set_pen(BG)
for x in range(size):
for y in range(size):
if code.get_module(x, y):
@ -29,14 +29,16 @@ def draw_qr_code(ox, oy, size, code):
code = qrcode.QRCode()
code.set_text("shop.pimoroni.com")
display.set_pen(128, 128, 128)
display.set_pen(FG)
display.clear()
display.set_pen(0, 0, 0)
display.set_pen(BG)
size, module_size = measure_qr_code(HEIGHT, code)
max_size = min(WIDTH, HEIGHT)
size, module_size = measure_qr_code(max_size, code)
left = int((WIDTH // 2) - (size // 2))
top = int((HEIGHT // 2) - (size // 2))
draw_qr_code(left, top, HEIGHT, code)
draw_qr_code(left, top, max_size, code)
display.update()

Wyświetl plik

@ -4,14 +4,11 @@ import st7789
import utime
from pimoroni import Button
# Set the display resolution
# in most cases you can swap WIDTH weith HEIGHT for portrait mode
WIDTH, HEIGHT = 240, 135 # Pico Display
# WIDTH, HEIGHT = 320, 240 # Pico Display 2.0
display = st7789.ST7789(WIDTH, HEIGHT, rotate180=False)
display = st7789.ST7789(st7789.DISPLAY_PICO_DISPLAY, rotate=0)
display.set_backlight(0.5)
WIDTH, HEIGHT = display.get_bounds()
button_a = Button(12)
button_b = Button(13)

Wyświetl plik

@ -2,11 +2,9 @@ import time
import random
import st7789
# Set the display resolution, in most cases you can flip these for portrait mode
WIDTH, HEIGHT = 240, 135 # Pico Display
# WIDTH, HEIGHT = 320, 240 # Pico Display 2.0
display = st7789.ST7789(st7789.DISPLAY_PICO_DISPLAY, rotate=0)
display = st7789.ST7789(WIDTH, HEIGHT, rotate180=False)
WIDTH, HEIGHT = display.get_bounds()
display.set_backlight(1.0)

Wyświetl plik

@ -4,13 +4,11 @@ import utime
import st7789
from pimoroni import RGBLED
# Set the display resolution
# in most cases you can swap WIDTH weith HEIGHT for portrait mode
WIDTH, HEIGHT = 240, 135 # Pico Display
# WIDTH, HEIGHT = 320, 240 # Pico Display 2.0
display = st7789.ST7789(WIDTH, HEIGHT, rotate180=False)
display = st7789.ST7789(st7789.DISPLAY_PICO_DISPLAY, rotate=0)
display.set_backlight(0.8)
display.set_palette_mode(st7789.PALETTE_USER)
WIDTH, HEIGHT = display.get_bounds()
led = RGBLED(6, 7, 8)
@ -41,13 +39,18 @@ def hsv_to_rgb(h, s, v):
h = 0
BLACK = display.create_pen(0, 0, 0)
RAINBOW = BLACK + 1 # Put RAINBOW right after BLACK in the palette
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
led.set_rgb(r, g, b) # Set LED to a converted HSV value
display.set_pen(r, g, b) # Set pen to a converted HSV value
display.set_palette(RAINBOW, st7789.RGB565(r, g, b)) # Create pen with converted HSV value
display.set_pen(RAINBOW) # Set pen
display.clear() # Fill the screen with the colour
display.set_pen(0, 0, 0) # Set pen to black
display.set_pen(BLACK) # 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)

Wyświetl plik

@ -7,16 +7,18 @@ import utime
import st7789
from pimoroni import RGBLED
# Set the display resolution
# in most cases you can swap WIDTH weith HEIGHT for portrait mode
WIDTH, HEIGHT = 135, 240 # Pico Display
# WIDTH, HEIGHT = 320, 240 # Pico Display 2.0
display = st7789.ST7789(WIDTH, HEIGHT, rotate180=False)
display = st7789.ST7789(st7789.DISPLAY_PICO_DISPLAY, rotate=0)
display.set_palette_mode(st7789.PALETTE_USER)
# Set the display backlight to 50%
display.set_backlight(0.5)
WIDTH, HEIGHT = display.get_bounds()
BLACK = display.create_pen(0, 0, 0)
WHITE = display.create_pen(255, 255, 255)
TEMPERATURE = WHITE + 1
led = RGBLED(6, 7, 8)
# reads from Pico's temp sensor and converts it into a more manageable number
@ -53,7 +55,7 @@ def temperature_to_color(temp):
while True:
# fills the screen with black
display.set_pen(0, 0, 0)
display.set_pen(BLACK)
display.clear()
# the following two lines do some maths to convert the number from the temp sensor into celsius
@ -68,8 +70,9 @@ while True:
i = 0
for t in temperatures:
# chooses a pen colour based on the temperature
display.set_pen(*temperature_to_color(t))
# chooses a pen colour based on the temperature and update the palette entry
display.set_palette(TEMPERATURE, st7789.RGB565(*temperature_to_color(t)))
display.set_pen(TEMPERATURE)
# draws the reading as a tall, thin rectangle
display.rectangle(i, HEIGHT - (round(t) * 4), bar_width, HEIGHT)
@ -82,11 +85,11 @@ while True:
led.set_rgb(*temperature_to_color(temperature))
# draws a white background for the text
display.set_pen(255, 255, 255)
display.set_pen(WHITE)
display.rectangle(1, 1, 100, 25)
# writes the reading as text in the white rectangle
display.set_pen(0, 0, 0)
display.set_pen(BLACK)
display.text("{:.2f}".format(temperature) + "c", 3, 3, 0, 3)
# time to update the display