• Stars
    star
    192
  • Rank 202,019 (Top 4 %)
  • Language
    C++
  • License
    Other
  • Created almost 11 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Implementation of Adafruit's NeoPixel Library for Particle devices: Core, Photon, P1, Electron, Argon, Boron, Xenon and RedBear Duo.

Particle-NeoPixel

A library for manipulating NeoPixel RGB LEDs for the:

Particle Core, Photon, P1, Electron, Argon, Boron, Xenon and RedBear Duo

Implementation based on Adafruit's NeoPixel Library.

Supported Pixel Types

  • 800 KHz WS2812, WS2812B, WS2813 and 400kHz bitstream and WS2811
  • 800 KHz bitstream SK6812RGBW (NeoPixel RGBW pixel strips) (use 'SK6812RGBW' as PIXEL_TYPE)

The most common kinds are WS2812/WS2813 (6-pin part), WS2812B (4-pin part) and SK6812RGBW (3 colors + white).

Also supports these less common pixels

  • Radio Shack Tri-Color LED Strip with TM1803 controller 400kHz bitstream.
  • TM1829 pixels, many details here.
  • Some functions from the MessageTorch library have been added.
  • SK6812MINI "NeoPixel Mini" (use 'WS2812B' as PIXEL_TYPE)

Usage

Set up the hardware:

  • A NeoPixel digital RGB LED (get at adafruit.com)
  • or a Radio Shack Tri-Color LED Strip (get at radioshack.com)
  • A power supply or breakout board to supply NeoPixel's with 5V

Flash the rainbow example. With the Particle CLI do particle flash <my_device> examples/a-rainbow

Adapt it to your needs while keeping this general structure:

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void setup() {
  strip.begin();
  strip.show();
}
void loop() {
  // change your pixel colors and call strip.show() again
}

Documentation

Adafruit_NeoPixel

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_COUNT 10
#define PIXEL_PIN D2
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

Creates an object to interact wth a NeoPixel strip.

PIXEL_COUNT is the number of pixels in strip.

Note: for some stripes like those with the TM1829, you need to count the number of segments, i.e. the number of controllers in your stripe, not the number of individual LEDs!

PIXEL_PIN is the pin number where your NeoPixel are connected (A0-A7, D0-D7, etc). If omitted, D2 is used.

On Photon, Electron, P1, Core and Duo, any pin can be used for Neopixel.

On the Argon, Boron and Xenon, only these pins can be used for Neopixel:

  • D2, D3, A4, A5
  • D4, D6, D7, D8
  • A0, A1, A2, A3

In addition on the Argon/Boron/Xenon, only one pin per group can be used at a time. So it's OK to have one Adafruit_NeoPixel instance on pin D2 and another one on pin A2, but it's not possible to have one on pin A0 and another one on pin A1.

PIXEL_TYPE is the type of LED, one of WS2811, WS2812, WS2812B, WS2812B2, WS2813, TM1803, TM1829, SK6812RGBW. If omitted, WS2812B is used.

Note: For legacy 50us reset pulse timing on WS2812/WS2812B or WS2812B2, select WS2812B_FAST or WS2812B2_FAST respectively. Otherwise, 300us timing will be used.

Note: RGB order is automatically applied to WS2811, WS2812/WS2812B/WS2812B2/WS2813/TM1803 is GRB order.

begin

strip.begin();

Sets up the pin used for the NeoPixel strip.

setPixelColor

setColor

strip.setPixelColor(num, red, green, blue);
strip.setPixelColor(num, red, green, blue, white);
strip.setPixelColor(num, color);
strip.setColor(num, red, green, blue);
strip.setColor(num, red, green, blue, white);

Set the color of LED number num (0 to PIXEL_COUNT-1). red, green, blue, white are between 0 and 255. White is only used for RGBW type pixels. color is a color returned from Color.

The brightness set with setBrightness will modify the color before it is applied to the LED.

show

strip.show();

Displays the colors on the NeoPixel strip that were set with setPixelColor and other calls that change the color of LEDs.

This function takes some time to run (more time the more LEDs you have) and disables interrupts while running.

clear

strip.clear();

Set all LED color to off. Will take effect on next show().

setBrightness

strip.setBrightness(brightness);

Make the LED less bright. brightness is from 0 (off) to 255 (max brightness) and defaults to 255.

This factor is not linear: 128 is not visibly half as bright as 255 but almost as bright.

getBrightness

uint8_t brightness = strip.getBrightness();

Get the current brightness.

setColorScaled

strip.setColorScaled(num, red, green, blue, scaling);
strip.setColorScaled(num, red, green, blue, white, scaling);

Set the color of LED number num and scale that color non-linearly according to the scaling parameter (0 to 255).

setColorDimmed

strip.setColorDimmed(num, red, green, blue, brightness);
strip.setColorDimmed(num, red, green, blue, white, brightness);

Set the color of LED number num and dim that color linearly according to the brightness parameter (0 to 255). In this case 128 should look half as bright as 255.

Color

uint32_t color = strip.Color(red, green, blue);
uint32_t color = strip.Color(red, green, blue, white);

Make a color from component colors. Useful if you want to store colors in a variable or pass them as function arguments.

getPixelColor

uint32_t color = strip.getPixelColor();

Get the current color of an LED in the same format as Color.

setPin

strip.setPin(pinNumber);

Change the pin used for the NeoPixel strip.

updateLength

strip.updateLength(n);

Change the number of LEDs in the NeoPixel strip.

getPixels

uint8_t *pixels = strip.getPixels();

Get the raw color data for the LEDs.

getNumLeds

numPixels

uint16_t n = strip.getNumLeds();
uint16_t n = strip.numPixels();

Get the number of LEDs in the NeoPixel strip. numPixels is an alias for getNumLeds.

Nuances

  • Make sure get the # of pixels, pin number, type of pixels correct
  • NeoPixels require 5V logic level inputs and the Spark Core and Photon only have 3.3V logic level digital outputs. Level shifting from 3.3V to 5V is necessary, the Particle Shield Shield has the TXB0108PWR 3.3V to 5V level shifter built in (but has been known to oscillate at 50MHz with wire length longer than 6"), alternatively you can wire up your own with a SN74HCT245N, or SN74HCT125N. These are rock solid.
  • To reduce NeoPixel burnout risk, add 1000 uF capacitor across pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input and minimize distance between device and first pixel. Avoid connecting on a live circuit. If you must, connect GND first.
  • Don't use getPixelColor() to move pixel data around when you are also using setBrightness(). When the brightness is set, all setPixelColor() calls will end up scaling colors to dim them before they are stored in memory. When using getPixelColor() the stored dimmed color is rescaled back up to the original color. However, due to some loss of precision with the math, it is not possible to recreate this color data perfectly. This is especially true with low brightness values. If you get and set color data repeatedly with a dimmed pixel, it will eventually continue to decrease in value until it is equal to zero.
  • When changing the brightness, always call setPixelColor() first with fresh un-dimmed color data, then call setBrightness(), and finally show().

References

License

Copyright 2014-2018 Technobly, Julien Vanier, Cullen Shane, Phil Burgess

Released under the LGPL license

More Repositories

1

SparkCore-Photon-Fritzing

A Fritzing Library of parts and examples for the Spark Core.
81
star
2

NeoPixel-KnightRider

A highly configurable Knight Rider (larson display) routine for your AdaFruit NeoPixel (WS2812 RGB LED) using the Arduino.
Arduino
69
star
3

SparkCore-WebApp

An amazing web based interface for your Spark Core. It uses the power of Node.js, Express, Jade, Stylus for the backend, jQuery and AngularJS for the frontend, and the Spark API to let you remote control your own Spark Core. Simply log into your device, and take control... from anywhere in the world! Fork us and make your own!
CSS
35
star
4

Remote-Particle

A Remote Starter example that's a customize-able simple Particle device web app controller with feedback through Variables.
HTML
26
star
5

SparkCore-RF24

ManiacBug's RF24 Library for the Spark Core.
C++
23
star
6

MonokaiArduinoTheme

22
star
7

SparkCore-SD

An Implementation of the Arduino/Sparkfun SD Card Library for the Spark Core
C++
16
star
8

SparkCore-PN532_NFC

A PN532 NFC library for the Spark Core.
C++
16
star
9

vectrex-cartridge

Vectrex Cartridge PCB reference design
HTML
15
star
10

SparkCore-LiquidCrystal

A version of the LiquidCrystal library for the Spark Core.
C++
14
star
11

rtttl

A RTTTL (RingTone Text Transfer Language) song player for Particle devices
C++
12
star
12

Simple-Spark-Core-Controller

C++
11
star
13

SparkAPI-NodeJS

Spark API Wrapper in Node.js
JavaScript
10
star
14

SparkCore-LiquidCrystalSPI

A Hardware and Software SPI version of the LiquidCrystal library for the Spark Core.
C++
9
star
15

Particle-DotStar

An Implementation of Adafruit's DotStar Library for the Spark Core
C++
8
star
16

Auto-Awexomer

A Turntable.fm bookmarklet that automatically awexomes every song for you, and looks good doing it.
JavaScript
6
star
17

SparkCore-MotorShield-V1

Adafruit Motor Shield V1 Library for Spark Core (Currently only AF_DCMotor class is tested and working)
C++
6
star
18

vectrex-stereo-ay

A simple PCB to turn your Vectrex AY-3-8912 3 channel mono sound into stereo line out! The speaker will still work as well if you have the volume up.
4
star
19

electron-maintain-capacity

Particle Electron - Maintain a Minimum Battery Capacity App
C++
4
star
20

SparkCore-FacebookLikesAlert

Spark Maker Kit - Facebook Likes Alert for the Spark Core
C++
4
star
21

vectrex-vectorlink

Vectorlink: The Ultimate Vectrex Controller System
3
star
22

SparkCore-PumpkinPush

Motion Activated Pumpkin Push Notifications with the Spark Core and Pushover
C++
3
star
23

vectrex-sao

Vectrex SAO for Hackaday Supercon.6 2022
C
2
star
24

SparkCore-MAX31855

Adafruit MAX31885 Library ported to Spark Core
C++
2
star
25

rpmgauge

A Car Heads-up RPM Gauge built with Carloop, Particle Photon and Neopixel sticks.
C++
2
star
26

rtttl-floppy

A RTTTL (RingTone Text Transfer Language) player for floppy drive music
C++
1
star
27

SparkCore-DotStar-NYE

Spark Core Adafruit DotStar 60-LED Strip New Year's Eve Countdown!
C++
1
star
28

particle-gen2-jtag-adapter

1
star
29

Spark-Stepper

Arduino Stepper library for the Spark Core
C++
1
star
30

Particle-Pokeball

Code for your Particle Photon powered Pokeball
C++
1
star
31

MonStar

A NodeJS Process Monitor designed specifically from the ground up for Turntable.fm bots. If your bot crashes, this will declare it offline after 20 seconds and restart it after 40 seconds (both are programmable).
1
star
32

vectrex-vectorblade

Malban's Vectorblade PCB design, optimized with single gate SMT IC's (AND & NOT), 8 color RGB LED, and some gorgeous artwork applied.
1
star