Giter Club home page Giter Club logo

pico_python_ws2812b's Introduction

pico_ws2812b

a library for using WS2812b leds (aka neopixels) with Raspberry Pi Pico

neopixels in action

For updated version, which also supports RGBW, check out my other library: https://github.com/blaz-r/pi_pico_neopixel.

You'll first need to save the ws2812b.py file to your device (for example, open it in Thonny and go file > save as and select MicroPython device. Give it the same name). Once it's there, you can import it into your code.

Mind that library works with GRB order of bits. If you have RGBW or want other color/bit orders (RGB, BRG, GRBW.. ) check out my upgraded version https://github.com/blaz-r/pi_pico_neopixel .

You create an object with the parameters number of LEDs, state machine ID and GPIO number in that order. so, to create a strip of 10 leds on state machine 0 and GPIO 0, you use:

pixels = ws2812b.ws2812b(10,0,0)

This class has many methods, two main ones being show() which sends the data to the strip, and set_pixel which sets the colour values for a particular LED. The parameters are LED number, red, green, blue or a tuple of form (red, green blue) with the colours taking values between 0 and 255.

At the moment, this isn't working with the interpreter, so you have to run it from a file. Looks like it's running just too slow to keep up with the PIO buffer from the interpreter. The key methods are set_pixel(r,g,b), set_pixel_line(p1, p2, r, g, b) which sets a row of pixels from pixel p1 to pixel p2 (inclusive), and fill(r,g,b) which fills all the pixels with the colour r,g,b. Every method also works with tuple containing rgb values: set_pixel(num, (r,g,b)) and set_pixel_line_gradient(p1, p2, rgb1, rgb2) where rgb1 and rgb2 are of form (r,g,b). This enables writing simpler code for certain usecases, one of such is in examples folder: "colorwave.py"

pixels.set_pixel(5,10,0,0)
pixels.set_pixel_line(5,7,0,10,0)
pixels.fill(20,5,0)

rgb1 = (0, 0, 50)
rgb2 = (50, 0, 0)
pixels.set_pixel(42, (0, 50, 0))
pixels.set_pixel_line(5, 7, rgb1)
pixels.set_pixel_line_gradient(0, 13, rgb1, rgb2)

For new settings to take effect you write:

pixels.show()

Library is forked from https://github.com/benevpi/pico_python_ws2812b

pico_python_ws2812b's People

Contributors

benevpi avatar blaz-r avatar oliverdew avatar the-spirit avatar timmillwood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.