Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Displayio palette
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Displayio palette

by parsko on Fri Apr 30, 2021 6:30 pm

Hi,

I have the following code...

I'm trying to figure out how to use the 2nd palette, yellow, palette[1] as my background. It's only white. I can't figure out that missing line of code.

I'm using a PiTFT wired to a Metro M4.

Any thoughts?

Thanks,

-Parsko

Code: Select all | TOGGLE FULL SIZE
import board
import digitalio
import terminalio
import time
import displayio
from adafruit_hx8357 import HX8357

displayio.release_displays()
spi = board.SPI()
tft_cs = board.A2
tft_dc = board.A3
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = HX8357(display_bus, width=480, height=320,auto_refresh=True)

main_screen = displayio.Group(max_size=1)

data_area = displayio.Group(max_size=30, x=0, y=0)

data_area_bitmap = displayio.Bitmap(480,320,2)

palette = displayio.Palette(2)
palette[0] = 0xffffff #white
palette[1] = 0xffff00 #yellow
''''''
data_area_sprite = displayio.TileGrid(data_area_bitmap,
                                pixel_shader=palette,
                                width=2, height=4,
                                tile_width = 240, tile_height=80,
                                x=0,y=0)

data_area_group = displayio.Group(max_size=1)
data_area_group.append(data_area_sprite)

data_area.append(data_area_group)

main_screen.append(data_area)

display.show(main_screen)

while True:
    time.sleep(1)

parsko
 
Posts: 24
Joined: Sat Mar 24, 2018 11:11 am

Re: Displayio palette

by kmatch on Tue May 11, 2021 7:10 pm

You can use the bitmap’s .fill function:

Code: Select all | TOGGLE FULL SIZE

data_area_bitmap.fill(1)



When you create the bitmap, it initialized all pixels to palette index 0. You can use the .fill command to change the full bitmap to a different index. The code above changes all pixels to palette index 1, the yellow color.

Here are the docs for the bitmap.fill function: https://circuitpython.readthedocs.io/en/latest/shared-bindings/displayio/#displayio.Bitmap.fill

Alternately you can redefine your palette index 0 to be the yellow color.

kmatch
 
Posts: 16
Joined: Sun Sep 03, 2017 12:17 am

Please be positive and constructive with your questions and comments.