示例#1
0
import machine, neopixel, time
# Set the pin number and number of pixels
from neopixel import Neopixel

NEOPIXEL_PIN = 0
NUMBER_PIXELS = 144
strip = Neopixel(NUMBER_PIXELS, 0, 0, "GRB")

# blink the first pixel red

while True:
    # set pixel 0 to be red
    strip.set_pixel(0,(255,0,0))
    strip.show()
    time.sleep(0.5)
    # turn pixel 0 off
    strip.set_pixel(0, (0,0,0))  
    
    # set pixel 1 to be green
    strip.set_pixel(1,(0,255,0))
    strip.show()
    time.sleep(0.5)
    # turn pixel 0 off
    strip.set_pixel(1, (0,0,0))
     
    # set pixel 2 to be blue
    strip.set_pixel(2,(0,0,255))
    strip.show()
    time.sleep(0.5)
    # turn pixel 0 off
    strip.set_pixel(2, (0,0,0))
示例#2
0
from neopixel import Neopixel
from time import sleep

NUMBER_PIXELS = 2
STATE_MACHINE = 0
LED_PIN = 11

strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB")

while True:

    # blink red
    for i in range(0, NUMBER_PIXELS):
        strip.set_pixel(i, (255, 0, 0))
    strip.show()
    sleep(.5)

    # blink green
    for i in range(0, NUMBER_PIXELS):
        strip.set_pixel(i, (0, 255, 0))
    strip.show()
    sleep(.5)

    # blink blue
    for i in range(0, NUMBER_PIXELS):
        strip.set_pixel(i, (0, 0, 255))
    strip.show()
    sleep(.5)
    for i in range(0, NUMBER_PIXELS):
        strip.set_pixel(i, (0, 0, 0))
    strip.show()
from utime import sleep
# We are using https://github.com/blaz-r/pi_pico_neopixel
from neopixel import Neopixel

NUMBER_PIXELS = 2
STATE_MACHINE = 0
LED_PIN = 18

# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB")

while True:
    # turn on first red for 1/2 second
    strip.set_pixel(0, (255, 0, 0))
    strip.show()
    sleep(.5)
    strip.set_pixel(0, (0, 0, 0))  # all first off
    strip.show()
    sleep(.5)
示例#4
0
import time

from neopixel import Neopixel
# https://github.com/blaz-r/pi_pico_neopixel

numpix = 12
strip = Neopixel(numpix, 0, 0, "GRB")
# strip.brightness(50)

red = (255, 0, 0)
orange = (255, 165, 0)
yellow = (255, 255, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
indigo = (75, 0, 130)
violet = (138, 43, 226)
colors = (red, orange, yellow, green, blue, indigo, violet)

strip.brightness(255)

while True:
    for color in colors:
        for i in range(numpix):
            strip.set_pixel(i, color)
            strip.show()
            time.sleep(0.1)
            
示例#5
0
    # 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(NUMBER_PIXELS):
            rc_index = (i * 256 // NUMBER_PIXELS) + j
            pixels[i] = wheel(rc_index & 255)
        pixels.write()


counter = 0
while True:
    for i in range(0, NUMBER_PIXELS):
        # print(wheel(counter))
        strip.set_pixel(i, wheel(counter))
    strip.show()
    counter += 1
    counter = counter % 255
    sleep(.01)
strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB")

# Color RGB values
red = (255, 0, 0)
off = (0, 0, 0)
orange = (255, 60, 0)  # Gamma corrected from G=128 to be less like yellow
yellow = (255, 150, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
indigo = (75, 0, 130)  # purple?
violet = (138, 43, 226)  # mostly pink
color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet')
num_colors = len(color_names)
colors = (red, orange, yellow, green, blue, indigo, violet)

# set to be 1 to 100 for percent brightness
strip.brightness(100)

color_index = 0
while True:
    for i in range(0, NUMBER_PIXELS - 1):
        strip.set_pixel(i, red)
        strip.show()
        sleep(.1)
        strip.set_pixel(i, off)
    for i in range(NUMBER_PIXELS - 1, 0, -1):
        strip.set_pixel(i, red)
        strip.show()
        sleep(.1)
        strip.set_pixel(i, off)
from utime import sleep
# We are using https://github.com/blaz-r/pi_pico_neopixel
from neopixel import Neopixel

NUMBER_PIXELS = 2
STATE_MACHINE = 0
LED_PIN = 18

# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB")

while True:
    # turn on first pixel red for 1/2 second
    strip.set_pixel(0, (255, 0, 0))
    strip.show()
    sleep(.5)
    strip.set_pixel(0, (0, 0, 0))  # turn all colors off
    strip.show()
    sleep(.5)
                neopixel_a = 0
        else:
            neopixel_b += 1
            if neopixel_b > num_colors - 1:
                neopixel_b = 0
        last_time = new_time


# now we register the handler function when the button is pressed
button_a.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler)
button_b.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler)

# This is for only printing when a new button press count value happens
old_presses = 0
print('Running NeoPixel Button Lab')
strip.set_pixel(0, (4, 5, 5))
strip.set_pixel(1, (4, 5, 5))
strip.show()


def main():
    global button_presses, old_presses, colors, neopixel_a, neopixel_b
    while True:
        # only print on change in the button_presses value
        if button_presses != old_presses:
            print(button_presses)
            print('NeoPixel A:', color_names[neopixel_a], 'index:', neopixel_a)
            print('NeoPixel B:', color_names[neopixel_b], 'index:', neopixel_b)
            strip.set_pixel(0, colors[neopixel_a])
            strip.set_pixel(1, colors[neopixel_b])
            strip.show()
示例#9
0
# Grove Connector 1
sda = machine.Pin(0)  # white Grove wire
scl = machine.Pin(1)  # yellow Grove wire
i2c = machine.I2C(0, sda=sda, scl=scl, freq=400000)

tof = VL53L0X.VL53L0X(i2c)


# Takes an input number vale and a range between high-and-low and returns it scaled to the new range
# This is similar to the Arduino map() function
def valmap(value, istart, istop, ostart, ostop):
    return int(ostart + (ostop - ostart) * ((value - istart) /
                                            (istop - istart)))


MIN_DIST = 50
max_dist = 0
tof.start()
while True:
    dist = tof.read()
    if dist < 8000:  # values over 8000 are no signal
        if dist > max_dist:
            max_dist = dist
        index = valmap(dist, 50, max_dist, 0, 19)
        print(dist, index)
        strip.set_pixel(index, (255, 0, 0))
        strip.show()
        sleep(.05)  # below this we get a flicker
        strip.set_pixel(index, (0, 0, 0))
        strip.show()
示例#10
0
green = (0, 255, 0)
blue = (0, 0, 255)
indigo = (75, 0, 130)  # purple?
violet = (138, 43, 226)  # mostly pink
color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet')
num_colors = len(color_names)
colors = (red, orange, yellow, green, blue, indigo, violet)

# set to be 1 to 100 for percent brightness
strip.brightness(100)

delay = .1
color_index = 0
while True:
    for i in range(2, NUMBER_PIXELS - 2):
        strip.set_pixel(i - 2, red_light)
        strip.set_pixel(i - 1, red_med)
        strip.set_pixel(i, red)
        strip.set_pixel(i + 1, red_med)
        strip.set_pixel(i + 2, red_light)
        if i > 0: strip.set_pixel(i - 3, (0, 0, 0))
        strip.show()
        sleep(delay)
        strip.set_pixel(i, off)
    for i in range(NUMBER_PIXELS - 4, 1, -1):
        if i < NUMBER_PIXELS - 2: strip.set_pixel(i + 3, (0, 0, 0))
        strip.set_pixel(i - 2, red_light)
        strip.set_pixel(i - 1, red_med)
        strip.set_pixel(i, red)
        strip.set_pixel(i + 1, red_med)
        strip.set_pixel(i + 2, red_light)
import machine
from neopixel import Neopixel
from utime import sleep

NEOPIXEL_PIN = 0
NUMBER_PIXELS = 72
strip = Neopixel(NUMBER_PIXELS, 0, 0, "GRB")

delay = .01
# blink the first pixel red

while True:
    for i in range(0, 5):
        strip.set_pixel(NUMBER_PIXELS - 1, (255, 0, 0))
        strip.show()
        sleep(0.1)
        strip.set_pixel(NUMBER_PIXELS - 1, (0, 0, 0))
        strip.show()
        sleep(0.1)

    for i in range(0, NUMBER_PIXELS - 1):
        # set pixel 0 to be red
        strip.set_pixel(i, (255, 0, 0))
        strip.show()
        sleep(delay)
        # turn pixel 0 off
        strip.set_pixel(i, (0, 0, 0))
    for i in range(NUMBER_PIXELS - 1, 0, -1):
        # set pixel 0 to be red
        strip.set_pixel(i, (255, 0, 0))
        strip.show()
示例#12
0
import time
from neopixel import Neopixel

NUMBER_PIXELS = 144
PIXELS_IN_TEST = 20
strip = Neopixel(NUMBER_PIXELS, 0, 0, "GRB")
strip.brightness(10)


def off():
    global NUMBER_PIXELS
    for i in range(0, NUMBER_PIXELS - 1):
        strip.set_pixel(i, (0, 0, 0))
    strip.show()


while True:
    # turn everything off for a second
    off()
    time.sleep(1)
    for power_level in range(50, 0, -1):
        print('Power Level:', power_level)
        print('Current in milliamps:',
              power_level * 2)  # estimate at 2ma on 10% brightness
        for i in range(0, power_level - 1):
            strip.set_pixel(i, (255, 255, 255))
        strip.show()
        time.sleep(5)
        off()
示例#13
0
import time
from neopixel import Neopixel

numpix = 58
pixels = Neopixel(numpix, 0, 1, "RGB")

yellow = (255, 100, 0)
orange = (255, 50, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
red = (255, 0, 0)
color0 = red

pixels.brightness(50)
pixels.fill(orange)
pixels.set_pixel_line_gradient(3, 13, green, blue)
pixels.set_pixel_line(14, 16, red)
pixels.set_pixel(20, (255, 255, 255))

while True:
    if color0 == red:
        color0 = yellow
        color1 = red
    else:
        color0 = red
        color1 = yellow
    pixels.set_pixel(0, color0)
    pixels.set_pixel(1, color1)
    pixels.show()
    time.sleep(0.1)