# NeoPixels Rainbow on MicroPython
# Wokwi Example https://wokwi.com/arduino/projects/305569065545499202
from machine import Pin
from neopixel import NeoPixel
from time import sleep
import time
rainbow = [
(126 , 1 , 0),(114 , 13 , 0),(102 , 25 , 0),(90 , 37 , 0),(78 , 49 , 0),(66 , 61 , 0),(54 , 73 , 0),(42 , 85 , 0),
(30 , 97 , 0),(18 , 109 , 0),(6 , 121 , 0),(0 , 122 , 5),(0 , 110 , 17),(0 , 98 , 29),(0 , 86 , 41),(0 , 74 , 53),
(0 , 62 , 65),(0 , 50 , 77),(0 , 38 , 89),(0 , 26 , 101),(0 , 14 , 113),(0 , 2 , 125),(9 , 0 , 118),(21 , 0 , 106),
(33 , 0 , 94),(45 , 0 , 82),(57 , 0 , 70),(69 , 0 , 58),(81 , 0 , 46),(93 , 0 , 34),(105 , 0 , 22),(117 , 0 , 10)]
status_button = False
start_push = 0
pixels = NeoPixel(Pin(15), 16)
'''while True:
rainbow = rainbow[-1:] + rainbow[:-1]
for i in range(16):
pixels[i] = rainbow[i]
pixels.write()
sleep(0.1)
'''
sw = Pin(4,Pin.IN,Pin.PULL_UP)
led = Pin(2,Pin.OUT)
def sw_check(button):
global start_push
global status_button
select_mode=False
interval_push=0
if button.value()==False:
if status_button != button.value() and start_push == 0:
start_push=time.time()
# print(start_push)
status_button=True
else:
if status_button != button.value() and start_push >0:
interval_push=time.time() - start_push
start_push=0
if interval_push > 2:
print("Select MODE")
interval_push =0
select_mode =True
status_button=False
#print(f'start time={start_push},time={time.time()},status push={status_button},interval push={interval_push}')
return select_mode
while True:
sw_check(sw)
'''if sw.value() :
print(sw.value())
led.on()
print("Push button TRUE")
sleep(1)
else:
print(sw.value())
led.off()
print("Push buton FALSE")
sleep(1)
'''