🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    m5stickC plus2 cycle through images

    M5 Stick/StickC
    2
    2
    220
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tdvds
      last edited by

      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?

      ajb2k3A 1 Reply Last reply Reply Quote 0
      • ajb2k3A
        ajb2k3 @tdvds
        last edited by

        @tdvds Are the images formatted correctly?

        UIFlow, so easy an adult can learn it!
        If I don't know it, be patient!
        I've ether not learned it or am too drunk to remember it!
        Author of the WIP UIFlow Handbook!
        M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

        1 Reply Last reply Reply Quote 0
        • First post
          Last post