I want to have three horizontal bar graphs which change length as potentiometers are twisted. I thought I would be able to set up the rectangles to change width on a variable in the same manner as I change the text in a label but all I got were ‘not allowed’ type errors.
Is there a way to do this?
I managed to get what I wanted by popping and appending the changing rectangle. I could do this with 3 rectangles but this might make the screen jitter.
Is there a way to hold the screen updates while such a multi stage process takes place?
Here is my ‘experimental code’.
Code: Select all
"""
Example of CircuitPython/Raspberry Pi Pico
to display on 320x240 ili9341 SPI display
"""
import board
import displayio
import time
import terminalio
import busio
from adafruit_display_text import label
import adafruit_ili9341
from adafruit_display_shapes.rect import Rect
# Release any resources currently in use for the displays
displayio.release_displays()
# Setup ili9341 320x240 TFT display
TFT_WIDTH = 320
TFT_HEIGHT = 240
tft_spi_clk = board.GP6
tft_spi_mosi = board.GP7
tft_cs = board.GP13
tft_dc = board.GP15
tft_res = board.GP14
tft_spi = busio.SPI(tft_spi_clk, MOSI=tft_spi_mosi)
display_bus = displayio.FourWire(
tft_spi, command=tft_dc, chip_select=tft_cs, reset=tft_res)
display = adafruit_ili9341.ILI9341(display_bus,
width=TFT_WIDTH, height=TFT_HEIGHT)
display.rotation = 0
# Make the display context
splash = displayio.Group(max_size=20)
display.show(splash)
# Make a background color fill
color_bitmap = displayio.Bitmap(320, 240, 1) # Full screen background WHITE
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF # WHITE
bg_sprite = displayio.TileGrid(color_bitmap, x=0, y=0, pixel_shader=color_palette)
splash.append(bg_sprite)
##########################################################################
text = "HELLO WORLD"
font = terminalio.FONT
color = 0x0000FF
# Create the text label
text_area = label.Label(font, text=text, color=color)
# Set the location
text_area.x = 10
text_area.y = 60
# Show it
splash.append(text_area)
time.sleep(2)
rect_bar = Rect(30, 50, 0, 20, fill=0x0)
splash.append(rect_bar)
v = [10,0,20,30,40,50,20,70,85,100,50,1,0,33,100,27]
for x in v:
text_area.text = str(x)
splash.pop()
rect_bar = Rect(30, 50, x, 20, fill=0x0)
splash.append(rect_bar)
time.sleep(0.6)
print("Done")
time.sleep(3)