OmbresColorees
Ateliers Ombres colorées
réalisé à la bibliothèque de la cité le 2/11/2022
https://twitter.com/TinkeringStudio/status/1587885160606814208
Baton lumineux montés avec un micro-bit et une bande de 30 leds
programme en micro-python https://python.microbit.org/v/3/project
from microbit import *
import neopixel
from random import randint
- Setup the Neopixel strip on pin0 with a length of 30 pixels
np = neopixel.NeoPixel(pin0, 30)
couleur_set=[(60,0,0),(0,60,0),(60,60,0),(0,0,100),(30,30,30),(0,0,0)]
compte=0
taille=1
maxled=8
def wheel(pos):
#Input a value 0 to 255 to get a color value.
#The colours are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
return (0, 0, 0)
if pos < 85:
return (255 - pos * 3, pos * 3, 0)
if pos < 170:
pos -= 85
return (0, 255 - pos * 3, pos * 3)
pos -= 170
return (pos * 3, 0, 255 - pos * 3)
def rainbow_cycle(wait):
for j in range(255):
for i in range(n):
rc_index = (i * 256 // n) + j
np[i] = wheel(rc_index & 255)
np.write()
time.sleep_ms(wait)
while True:
#Iterate over each LED in the strip
if button_a.is_pressed() and button_b.is_pressed():
rainbow_cycle(5)
break
elif button_a.is_pressed():
compte=(compte+1)%len(couleur_set)
elif button_b.is_pressed():
taille=(taille+1)%maxled
for pixel_id in range(0, len(np)):
# Assign the current LED a random red, green and blue value between 0 and 60
np[pixel_id] = couleur_set[compte]
np[pixel_id-taille] = (0, 0, 0)
# Display the current pixel data on the Neopixel strip
np.show()
sleep(50)