<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[m5stickC plus2 cycle through images]]></title><description><![CDATA[<p dir="auto">i want to cycle through some images stored on the device<br />
and ive come to this</p>
<pre><code>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
</code></pre>
<p dir="auto">yet it doesnt work<br />
ive tried reading the docs but to no avail yet<br />
anyone might know the answer?</p>
]]></description><link>https://community.m5stack.com/topic/7014/m5stickc-plus2-cycle-through-images</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Mar 2026 03:36:58 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/7014.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 24 Nov 2024 13:46:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to m5stickC plus2 cycle through images on Mon, 25 Nov 2024 05:39:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/189374">@tdvds</a> Are the images formatted correctly?</p>
]]></description><link>https://community.m5stack.com/post/27148</link><guid isPermaLink="true">https://community.m5stack.com/post/27148</guid><dc:creator><![CDATA[ajb2k3]]></dc:creator><pubDate>Mon, 25 Nov 2024 05:39:50 GMT</pubDate></item></channel></rss>