KRITSADA icon

Simple NeoPixel

KRITSADA | PRO | 10/28/19 09:37:41 AM UTC | 0 ⭐ | 831 👁️ | Never ⏰ | []
Python |

1.3 KB

|

None

|

0 👍

/

0 👎

from microbit import *
import neopixel
 
np = neopixel.NeoPixel(pin0, 8)
 
red = (255, 0, 0)
orange = (219, 104, 24)
yellow = (241, 212, 36)
green = (0, 255, 0)
blue = (0, 0, 255)
navy = (0, 0, 139)
purple = (76, 39, 55)
white = (255, 255, 255)
 
while True:
    light = display.read_light_level()
    np.clear()
    
    if light<=35:
        np[0] = red
    elif light<=70:
        np[0] = red
        np[1] = orange
    elif light<=105:
        np[0] = red
        np[1] = orange
        np[2] = yellow
    elif light<=140:
        np[0] = red
        np[1] = orange
        np[2] = yellow
        np[3] = green
    elif light<=175:
        np[0] = red
        np[1] = orange
        np[2] = yellow
        np[3] = green
        np[4] = blue
    elif light<=210:
        np[0] = red
        np[1] = orange
        np[2] = yellow
        np[3] = green
        np[4] = blue
        np[5] = navy
    elif light<=245:
        np[0] = red
        np[1] = orange
        np[2] = yellow
        np[3] = green
        np[4] = blue
        np[5] = navy
        np[6] = purple
    else:
        np[0] = red
        np[1] = orange
        np[2] = yellow
        np[3] = green
        np[4] = blue
        np[5] = navy
        np[6] = purple
        np[-1] = white
    
    sleep(500)

Comments