示例#1
0
# https://github.com/benevpi/pico_python_ws2812b/tree/main/examples
import time
from ws2812b import ws2812b

num_leds = 60
pixels = ws2812b(num_leds, 0, 0, delay=0)

pixels.fill(10, 10, 10)
pixels.show()

while True:
    for i in range(num_leds):
        for j in range(num_leds):
            pixels.set_pixel(j,
                             abs(i + j) % 10,
                             abs(i - (j + 3)) % 10,
                             abs(i - (j + 6)) % 10)
        pixels.show()
        time.sleep(0.05)
示例#2
0
'''
实验名称:Neopixel RGB灯带
版本:v1.0
日期:2021.3
作者:01Studio、benevpi (https://github.com/benevpi/pico_python_ws2812b)
说明:通过编程实现灯带循环显示红色(RED)、绿色(GREEN)和蓝色(BLUE)。
'''

import time
from ws2812b import ws2812b

#灯珠数量30, 控制引脚Pin27
np = ws2812b(num_leds=30, 27)

while True:

    #红色
    pixels.fill(255, 0, 0)
    pixels.show()
    time.sleep(1)

    #绿色
    pixels.fill(0, 255, 0)
    pixels.show()
    time.sleep(1)

    #蓝色
    pixels.fill(0, 0, 255)
    pixels.show()
    time.sleep(1)
import machine
import time
from ws2812b import ws2812b

num_leds = 30

pixels = ws2812b(num_leds, 0, 27)

sensor_temp = machine.ADC(0)
conversion_factor = 3.3 / 65535

min_temp = 0
max_temp = 30

while True:
    reading = sensor_temp.read_u16() * conversion_factor
    temperature = 27 - (reading - 0.706) / 0.001721
    temp_int = int(temperature)
    for i in range(num_leds):
        if i < temp_int:
            pixels.set_pixel(i, 10, 0, 0)
        else:
            pixels.set_pixel(i, 0, 0, 0)
    pixels.show()
    time.sleep(2)
示例#4
0
# Example showing how functions, that accept tuples of rgb values,
# simplify working with gradients

import time
import ws2812b

numpix = 60
strip = ws2812b.ws2812b(numpix, 0, 0)

red = (255, 0, 0)
orange = (255, 50, 0)
yellow = (255, 100, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
indigo = (100, 0, 90)
violet = (200, 0, 100)
colors = [red, orange, yellow, green, blue, indigo, violet]

step = round(numpix / len(colors))
current_pixel = 0
strip.brightness(20)

for color1, color2 in zip(colors, colors[1:]):
    strip.set_pixel_line_gradient(current_pixel, current_pixel + step, color1,
                                  color2)
    current_pixel += step

strip.set_pixel_line_gradient(current_pixel, numpix - 1, violet, red)

while True:
    strip.rotate_right(1)
import json, sys
from machine import Pin
from utime import sleep
from ws2812b import ws2812b

### SETUP ###

#load rgb
with open("RGB.json", "r") as f:
    rgb = json.loads(f.read())

#create onboard led and neopixel device
led = Pin(25, Pin.OUT)
neo = ws2812b(16, 0, 0)

#change debug to false if device should not interact with anything
#used only for debugging and maintenance
activated = True

pins = []  #button objects will be stored here

#buttons the pins are connected to
pinout = [2, 3, 4, 18, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 16]

#neopixel stripe is not mathcing the button in terms of index, so rows 2 and 4 sre inverted
remap = [0, 1, 2, 3, 7, 6, 5, 4, 8, 9, 10, 11, 15, 14, 13, 12]

#define text for startup
logo = [[1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0],
        [1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0],
        [1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1],
# Pi_Pico_TrafficLight.py
# Controlling Neopixel by PIO to simulate a traffic light
# using ws2812b library by benevpi
# https://github.com/benevpi/pico_python_ws2812b

import time
import ws2812b

NUM_PIX = 3  # this is for M5Stack RGB LED
PIN_NUM = 16
light = ws2812b.ws2812b(NUM_PIX, 0, PIN_NUM)

RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
COLORS = (RED, YELLOW, GREEN, BLACK)

def lights(L0, L1, L2, t):
    color = L0
    light.set_pixel(0, color[0], color[1], color[2])
    color = L1
    light.set_pixel(1, color[0], color[1], color[2])
    color = L2
    light.set_pixel(2, color[0], color[1], color[2])
    light.show()
    time.sleep(t)

while True:
    lights(RED, BLACK, BLACK, 2)
    lights(RED, YELLOW, BLACK, 1)
示例#7
0
import ws2812b

LED_NUM = 144  # Number of NeoPixels
DIN_GPIO = 0  # Pin where NeoPixels are connected
REVERSE = True  # If True, LED block will fall off from the end of the LED strip

BLOCK = 8  # Length of LED block
BRIGHT = 60  # LED brightness
GRAVITY = 20  # Gravitational acceleration

# Bounce coefficient = R1/R2
R1 = 3  # Bounce coefficient 1
R2 = 5  # Bounce coefficient 2
REFMINV = -80  # Minimum bounce speed (Adjust when the bounce does not end)

strip = ws2812b.ws2812b(LED_NUM, 0, DIN_GPIO)


def set_block(pos, c):
    # Set a LED block
    # pos: The beginning position of the LED block
    # c: Color 0=off, 1=red ... 8=green ... 16=blue ... 24=red
    if c == 0:
        r = 0
        g = 0
        b = 0
    elif c <= 8:
        r = (8 - c) * BRIGHT >> 3
        g = c * BRIGHT >> 3
        b = 0
    elif c <= 16:
示例#8
0
lit = 0.2  # brightness of a hightlighted pixels
dim = 0.05  # brightness of drawn pixel
blink = 0  # used for blinking of active Pixel when in delete (black) mode
thrBlink = 10  # on and off for 10 delay-units
dirBlink = 1  # counts back and forth (via this direction variable dirBlink)
rows = 8  # 8 rows and 8 columns lead to 64 LEDs (pixels)
columns = 8
pixels = rows * columns

# Connect the joystick to pins
xAxis = ADC(Pin(27))
yAxis = ADC(Pin(26))
button = Pin(16, Pin.IN, Pin.PULL_UP)

# The LED-matrix is connected to SPI-0 on GP-5 (Pin-7), a delay is set after each show()
matrix = ws2812b.ws2812b(pixels, 0, 5, delay)

# 7 colors (could be any number - as long as the last is black - for deleting)
cols = [
    [255, 255, 255],
    [255, 0, 0],
    [128, 128, 0],
    [0, 255, 0],
    [0, 128, 128],
    [0, 0, 255],
    [128, 0, 128],
    [0, 0, 0],
]

# First Pixel is set at the starting position
matrix.set_pixel(cPix, cols[cCol][0] * dim, cols[cCol][1] * dim,