Okay, I got it compiled and more or less working.
If I can bother you for one more review to get this proof of concept working, this is a variation of your test code. I expect to have three tiles, different colors, and to switch between them.
The background on the screen is yellow, but I do see a flash of a blue screen when it loads… so I am suspecting I just have something slightly off. Can you take a peek?
Thank you for your work on this! It’s very cool!
import lvgl as lv
import time
import machine
from ili9XXX import st7735, COLOR_MODE_BGR
# Initialize LVGL
lv.init()
# Initialize the display driver
disp = st7735(
mhz=3, mosi=14, clk=2, cs=5, dc=26, rst=27, power=-1, backlight=15, backlight_on=1,
width=80, height=160, start_x=26, start_y=1, rot=0,
color_format=lv.COLOR_FORMAT.RGB565, colormode=COLOR_MODE_BGR,
invert=True
)
lv.screen_active().set_style_bg_color(lv.color_make(255,255,0),0)
#Create tileview:
tileview = lv.tileview(lv.screen_active())
tileview.remove_style_all()
tileview.set_pos(0, 0)
tileview.set_size(80, 160)
#tileview.add_event_cb(tileview_slide_cb, lv.EVENT.VALUE_CHANGED, None)
#Variables to store tiles count, and active tile index
tiles_count = 0
tile_index = 0
# Add tiles with different colors
def add_tile(color):
global tiles_count
tile = tileview.add_tile(0, tiles_count, lv.DIR.BOTTOM)
tile.set_style_bg_color(color, 0)
tiles_count += 1
return tile
# Functions to slide up/down the tileview
def slide_up():
global tile_index
tile_index = max(0, tile_index - 1)
tileview.set_tile_by_index(0, tile_index, lv.ANIM.ON)
def slide_down():
global tile_index
tile_index = min(tiles_count - 1, tile_index + 1)
tileview.set_tile_by_index(0, tile_index, lv.ANIM.ON)
# Debounce time in milliseconds
debounce_ms = 200
last_press_time = time.ticks_ms()
# Button press event handlers
def handle_SMU(pin):
global last_press_time
print("SMU")
if time.ticks_diff(time.ticks_ms(), last_press_time) > debounce_ms:
last_press_time = time.ticks_ms()
slide_up()
def handle_SMD(pin):
print("SMD")
global last_press_time
if time.ticks_diff(time.ticks_ms(), last_press_time) > debounce_ms:
last_press_time = time.ticks_ms()
slide_down()
# Setup button interrupts
SMU = machine.Pin(36, machine.Pin.IN, machine.Pin.PULL_UP)
SMD = machine.Pin(34, machine.Pin.IN, machine.Pin.PULL_UP)
SMU.irq(trigger=machine.Pin.IRQ_FALLING, handler=handle_SMU)
SMD.irq(trigger=machine.Pin.IRQ_FALLING, handler=handle_SMD)
# Add three tiles
add_tile(lv.color_make(255, 0, 0)) # Red tile
add_tile(lv.color_make(0, 255, 0)) # Green tile
add_tile(lv.color_make(0, 0, 255)) # Blue tile
while True:
lv.task_handler()