i want to cycle through some images stored on the device
and ive come to this
from m5stack import *
from m5ui import *
from uiflow import *
import time
# Initialize screen
setScreenColor(0x000000)
# Declare the image file paths relative to where they are stored
Key = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg']
i = 0 # Current index for the image
# Display the initial image
image1 = M5Img(18, 46, "res/" + Key[i], True)
# Function to update the displayed image
def update_image():
# Use setSrc to change the image being displayed
image1.setSrc("res/" + Key[i], True) # This method changes the image source
image1.show() # Ensure the image is visible
# Callback function for button B (previous image)
def buttonB_wasReleased():
global i
i = (i - 1) % len(Key) # Decrement index and handle wrap-around using modulus
update_image()
# Callback function for button A (next image)
def buttonA_wasReleased():
global i
i = (i + 1) % len(Key) # Increment index and handle wrap-around using modulus
update_image()
# Set up button event handlers
btnB.wasReleased(buttonB_wasReleased)
btnA.wasReleased(buttonA_wasReleased)
# Main loop to keep the program running
while True:
wait_ms(100) # This keeps the script active
yet it doesnt work
ive tried reading the docs but to no avail yet
anyone might know the answer?