GithubHelp home page GithubHelp logo

vtt-info / ws2812-spi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nickovs/ws2812-spi

0.0 0.0 0.0 8 KB

An efficient micropython WS2812 (NeoPixel) driver

License: Apache License 2.0

Python 100.00%

ws2812-spi's Introduction

ws2812-SPI

An efficient micropython WS2812 (NeoPixel) driver

This library allows for easy access to a set of WS2812 RGB LEDs attached to a microcontroller running MicroPython using an SPI port. This (at least in theory) allows for more efficient and reliable delivery of the data compared to using "bit banging" of a regular IO line.

The NeoPixel object can be treated as a 2D array, pixel_count long and 3 wide. Pixels can be accessed as a 3-tuple or through their individual Green, Blue and Red components (in that order). It can also be accessed with 1D slice operations to read or write a list of 3-tuples and a single 3-tuple can be written to a whole slice to set a row of pixels to the same value.

sp = machine.SPI(1)
sp.init(baudrate=3200000)
np = NeoPixel(sp, 100)

# Blank the whole set
np[:] = (0,0,0)
# Set the first 10 pixels to dark blue
np[0:10] = (0,0,40)
# Set the second pixel to green
np[1] = (128,0,0)
# Set the third pixel's red value to full brightness
np[2,2] = 255
# Copy the 2nd pixel to the 5th
np[4] = np[1]
# Copy the first 16 pixels to the last 16 pixels
np[-16:] = np[:16]
# Send the data out to the pixels
np.write()

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.