esp32+micropython环境如何实现按键切换效果

esp32+micropython环境

请问如何实现按键切换灯串效果啊?
一个gpio引脚做按键 一个gpio引脚做灯
几个效果的方法已经写好了
效果:按一下按键,响应一个效果,再按一下切换下一个效果如此循环。

effectIndex = 0
effectTotal = 5
def keyPressed():
    global effectIndex
    effectIndex = (effectIndex + 1) % effectTotal
    ledPlayEffect(effectIndex)

ledPlayEffect(effectIndex)

我的建议是不要使用time.sleep实现动画。你可以参考
GitHub - adafruit/Adafruit_CircuitPython_LED_Animation: CircuitPython helper library for LED colors and animations CircuitPython helper library for LED colors and animations - GitHub - adafruit/Adafruit_CircuitPython_LED_Animation: CircuitPython helper library for LED colors and animations https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation