示例#1
0
cyan = (0, 255, 255)
lightgreen = (100, 255, 100)
white = (128, 128, 128)  # not too bright
pink = (255, 128, 128)
color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet',
               'cyan', 'lightgreen', 'white')
num_colors = len(color_names)
colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen,
          white, pink)

NUMBER_PIXELS = 2
STATE_MACHINE = 0
NEOPIXEL_PIN = 18
# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB")
strip.brightness(100)


def turn_motor_on(pwm, motor_power):
    pwm.duty_u16(motor_power)


def turn_motor_off(pwm):
    pwm.duty_u16(0)


def forward(motor_power):
    turn_motor_on(right_forward, motor_power)
    turn_motor_on(left_forward, motor_power)
    turn_motor_off(right_reverse)
    turn_motor_off(left_reverse)
示例#2
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)
            
示例#3
0
sda = machine.Pin(16)
scl = machine.Pin(17)
i2c = machine.I2C(0, sda=sda, scl=scl)

# Create a VL53L0X object
tof = VL53L0X.VL53L0X(i2c)
tof.start()  # startup the sensor

# used to blink the onboard LED
led_onboard = machine.Pin(25, machine.Pin.OUT)

# LED Code
numpix = 72
strip = Neopixel(numpix, 0, 0, "GRB")
# we turn the brightness way down to not oversaturate the brightness in the video
strip.brightness(20)

# driving parameters
POWER_LEVEL = 30000  # use a value from 20000 to 65025
TURN_THRESHOLD = 400  # 25 cm
TURN_TIME = .25  # seconds of turning
BACKUP_TIME = .75  # seconds of backing up if obstacle detected

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)
示例#4
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)
import machine, neopixel
from utime import sleep
from neopixel import Neopixel

NEOPIXEL_PIN = 0
NUMBER_PIXELS = 72
strip = Neopixel(NUMBER_PIXELS, 0, NEOPIXEL_PIN, "GRB")
left = 0
max_index = NUMBER_PIXELS - 1
step = 3

delay = .001
while True:
    print('red to green')
    for i in range(0, 255, step):
        strip.brightness(i)
        strip.set_pixel_line_gradient(0, max_index, (255, 0, 0), (0, 255, 0))
        strip.show()
        sleep(delay)
    for i in range(255, 0, -step):
        strip.brightness(i)
        strip.set_pixel_line_gradient(0, max_index, (255, 0, 0), (0, 255, 0))
        strip.show()
        sleep(delay)

    print('green to blue')
    for i in range(0, 255, step):
        strip.brightness(i)
        strip.set_pixel_line_gradient(0, max_index, (0, 255, 0), (0, 0, 255))
        strip.show()
        sleep(delay)
示例#6
0
import time
from neopixel import Neopixel

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


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, 0, 0))
        strip.show()
        time.sleep(9)
        off()