# Example showing how functions, that accept tuples of rgb values,
# simplify working with gradients

import time
from neopixel import Neopixel
from class_fsm import CFsm
from class_led import CLed
from class_button import CButton

numpix = 16
strip = Neopixel(numpix, 0, 18, "GRB")
# strip = Neopixel(numpsix, 0, 0, "GRBW")

mom_bp_couleur = CButton( 17, "BP_COU" )
mom_bp_multicouleur = CButton( 16, "BP_MCOU" )
mom_bp_vitesse= CButton( 16, "BP_VIT" )

red = (255, 0, 0)
orange = (255, 50, 0)
yellow = (255, 100, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
indigo = (100, 0, 90)
violet = (200, 0, 100)
colors_rgb = [red, orange, yellow, green, blue, indigo, violet]

# same colors as normaln rgb, just 0 added at the end
colors_rgbw = [color+tuple([0]) for color in colors_rgb]
colors_rgbw.append((0, 0, 0, 255))

# uncomment colors_rgbw if you have RGBW strip
colors = colors_rgb
# colors = colors_rgbw


step = round(numpix / len(colors))
current_pixel = 0
strip.brightness(100)

for color1, color2 in zip(colors, colors[1:]):
    strip.set_pixel_line_gradient(current_pixel, current_pixel + step, color1, color2)
    current_pixel += step

strip.set_pixel_line_gradient(current_pixel, numpix - 1, violet, red)
# Machine d'état

#--------------------------------------------------
# fonctions de transition

def fsm_tr_couleur ():
    strip.rotate_right(1)
    time.sleep(0.05)
    strip.show()

def fsm_tr_multicouleur():
    strip.rotate_right(1)
    time.sleep(0.5)
    strip.show()

def fsm_tr_vitesse():
    strip.rotate_right(1)
    time.sleep(1.5)
    strip.show()

# Définition du dictionnaire

template_fsm_dict = {
    "COULEUR": ({"event":"BP_COU_PRESS","fct":fsm_tr_couleur,"n_state":"COULEUR"},
                ),
    "MULTICOULEUR": ({"event":"BP_MCOU_PRESS","fct":fsm_tr_multicouleur,"n_state":"MULTICOULEUR"},
                ),
    "VITESSE": ({"event":"BP_VIT_PRESS","fct":fsm_tr_vitesse,"n_state":"VITESSE"},
                )
    }

# initialise les composants

ma_fsm = CFsm(template_fsm_dict,"COULEUR")

#--------------------------------------------------
#--------------------------------------------------
# initialise les états par défaut
#pixels.brightness(100)
#colors_rgb =(green)
    strip.rotate_right(1)
    time.sleep(0.5)
    strip.show()

#--------------------------------------------------
#--------------------------------------------------
# boucle principale
while True:
    
    # appel les tâches des différents composants
    # ces composants peuvent retourner un evènement
    # entrée
    ma_fsm.put( mom_bp_couleur.task() )
    ma_fsm.put( mom_bp_multicouleur.task() )
    ma_fsm.put( mom_bp_vitesse.task() )
    
    # timer
    
    #sortie
    #ma_fsm.put( ma_led_jaune.task() )
    #ma_fsm.put( ma_led_rouge.task() )
    
    # fsm
    ma_fsm.task()
    

$abcdeabcde151015202530fghijfghij
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT