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()
violet = (138, 43, 226) # mostly pink 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)
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))
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)
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)
import machine, neopixel from utime import sleep from neopixel import Neopixel NEOPIXEL_PIN = 16 NUMBER_PIXELS = 10 strip = Neopixel(NUMBER_PIXELS, 0, NEOPIXEL_PIN, "GRB") strip.brightness(100) 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(NUMBER_PIXELS): rc_index = (i * 256 // NUMBER_PIXELS) + j pixels[i] = wheel(rc_index & 255) pixels.write()
from utime import sleep # We are using https://github.com/blaz-r/pi_pico_neopixel from neopixel import Neopixel NUMBER_PIXELS = 12 STATE_MACHINE = 0 LED_PIN = 0 # The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB 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)
# Sensor Code 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)
# press buttons to change the color of the NeoPixels import utime from machine import Pin from neopixel import Neopixel NUMBER_PIXELS = 2 STATE_MACHINE = 0 LED_PIN = 18 BUTTON_A_PIN = 20 BUTTON_B_PIN = 21 # Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler # The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") # Color RGB values red = (255, 0, 0) orange = (125, 60, 0) # Gamma corrected from G=128 to be less like yellow yellow = (255, 150, 0) green = (0, 255, 0) blue = (0, 0, 255) cyan = (0, 255, 255) indigo = (75, 0, 130) # purple? violet = (138, 43, 226) # mostly pink white = (255, 255, 255) color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'cyan', 'indigo', 'violet', 'white') num_colors = len(color_names) colors = (red, orange, yellow, green, blue, cyan, indigo, violet, white) # color index into colors list neopixel_a = 0
from neopixel import Neopixel from machine import Pin from random import choice from time import sleep np = Neopixel(Pin(4), 8) def val_gen(): yield choice(range(255)) def color_gen(): yield tuple(next(val_gen()) for i in range(3)) while True: np[choice(range(8))] = next(color_gen()) sleep(0.5)
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)
from utime import sleep # We are using https://github.com/blaz-r/pi_pico_neopixel from neopixel import Neopixel NUMBER_PIXELS = 27 STATE_MACHINE = 0 LED_PIN = 0 # The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") # Color RGB values red = (255, 0, 0) red_med = (32, 0, 0) red_light = (8, 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) delay = .1 color_index = 0
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()
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()
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)