Convert Figma logo to code with AI

adafruit logoAdafruit_NeoPixel

Arduino library for controlling single-wire LED pixels (NeoPixel, WS2812, etc.)

3,078
1,267
3,078
116

Top Related Projects

6,405

The FastLED library for colored LED animation on Arduino. Please direct questions/requests for help to the FastLED Reddit community: http://fastled.io/r We'd like to use github "issues" just for tracking library bugs / enhancements.

WS2812 FX Library for Arduino and ESP8266

An Arduino NeoPixel support library supporting a large variety of individually addressable LEDs. Please refer to the Wiki for more details. Please use the GitHub Discussions to ask questions as the GitHub Issues feature is used for bug tracking.

Quick Overview

Adafruit_NeoPixel is an Arduino library for controlling NeoPixel RGB LEDs. It provides a simple interface for driving various types of addressable RGB and RGBW LED strips and pixels, including WS2812, WS2811, and SK6812 LEDs.

Pros

  • Easy to use with a straightforward API
  • Supports a wide range of NeoPixel products and compatible LEDs
  • Optimized for performance on various Arduino boards
  • Includes helpful examples and documentation

Cons

  • Limited to Arduino-compatible platforms
  • May require careful timing considerations for some applications
  • Does not support advanced features like parallel output on all platforms
  • Can be memory-intensive for large numbers of LEDs

Code Examples

  1. Basic setup and color setting:
#include <Adafruit_NeoPixel.h>

#define PIN        6
#define NUMPIXELS 16

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
}

void loop() {
  pixels.clear();
  pixels.setPixelColor(0, pixels.Color(255, 0, 0));
  pixels.show();
  delay(1000);
}
  1. Creating a rainbow effect:
void rainbow(int wait) {
  for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
    for(int i=0; i<pixels.numPixels(); i++) {
      int pixelHue = firstPixelHue + (i * 65536L / pixels.numPixels());
      pixels.setPixelColor(i, pixels.gamma32(pixels.ColorHSV(pixelHue)));
    }
    pixels.show();
    delay(wait);
  }
}
  1. Brightness control:
void setup() {
  pixels.begin();
  pixels.setBrightness(50);  // Set brightness to 50 (range: 0-255)
}

void loop() {
  pixels.fill(pixels.Color(255, 255, 255));
  pixels.show();
}

Getting Started

  1. Install the Adafruit_NeoPixel library through the Arduino Library Manager.
  2. Connect your NeoPixel strip to your Arduino board (typically to a digital pin).
  3. Create an Adafruit_NeoPixel object in your sketch:
    #include <Adafruit_NeoPixel.h>
    #define PIN 6
    #define NUMPIXELS 16
    Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
    
  4. In setup(), initialize the NeoPixels:
    void setup() {
      pixels.begin();
    }
    
  5. Use pixels.setPixelColor() to set LED colors and pixels.show() to update the strip.

Competitor Comparisons

6,405

The FastLED library for colored LED animation on Arduino. Please direct questions/requests for help to the FastLED Reddit community: http://fastled.io/r We'd like to use github "issues" just for tracking library bugs / enhancements.

Pros of FastLED

  • Supports a wider range of LED types and chipsets
  • Offers more advanced color manipulation and effects
  • Provides better performance and optimization for complex animations

Cons of FastLED

  • Steeper learning curve for beginners
  • Less straightforward setup process compared to Adafruit_NeoPixel
  • May require more memory and processing power for some applications

Code Comparison

Adafruit_NeoPixel:

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
strip.begin();
strip.setPixelColor(i, strip.Color(red, green, blue));
strip.show();

FastLED:

#include <FastLED.h>
CRGB leds[NUM_LEDS];
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
leds[i] = CRGB(red, green, blue);
FastLED.show();

Both libraries provide similar basic functionality for controlling LED strips, but FastLED offers more advanced features and flexibility. Adafruit_NeoPixel is generally easier for beginners to use, while FastLED provides more power and control for complex projects. The choice between the two depends on the specific requirements of your project and your level of expertise.

WS2812 FX Library for Arduino and ESP8266

Pros of WS2812FX

  • Offers a wide range of built-in effects and animations
  • Provides easy-to-use functions for creating custom effects
  • Supports multiple LED strips with independent effects

Cons of WS2812FX

  • Larger memory footprint due to additional features
  • May have a steeper learning curve for beginners
  • Less frequently updated compared to Adafruit_NeoPixel

Code Comparison

WS2812FX:

#include <WS2812FX.h>
#define LED_COUNT 30
#define LED_PIN 5
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
ws2812fx.setMode(FX_MODE_RAINBOW_CYCLE);
ws2812fx.start();

Adafruit_NeoPixel:

#include <Adafruit_NeoPixel.h>
#define LED_COUNT 30
#define LED_PIN 5
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
strip.begin();
strip.show();

The WS2812FX library provides a higher-level abstraction with built-in effects, while Adafruit_NeoPixel offers more low-level control. WS2812FX is ideal for quickly implementing complex animations, whereas Adafruit_NeoPixel is better suited for custom, fine-grained control over individual LEDs.

An Arduino NeoPixel support library supporting a large variety of individually addressable LEDs. Please refer to the Wiki for more details. Please use the GitHub Discussions to ask questions as the GitHub Issues feature is used for bug tracking.

Pros of NeoPixelBus

  • More efficient memory usage and faster execution
  • Support for various color spaces (RGB, HSL, HSB)
  • Better handling of different LED chipsets and configurations

Cons of NeoPixelBus

  • Steeper learning curve due to more complex API
  • Less extensive documentation compared to Adafruit_NeoPixel

Code Comparison

Adafruit_NeoPixel:

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip(60, PIN, NEO_GRB + NEO_KHZ800);
strip.begin();
strip.setPixelColor(i, strip.Color(red, green, blue));
strip.show();

NeoPixelBus:

#include <NeoPixelBus.h>
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(60, PIN);
strip.Begin();
strip.SetPixelColor(i, RgbColor(red, green, blue));
strip.Show();

The code comparison shows that NeoPixelBus offers more flexibility in color representation and LED configuration, while Adafruit_NeoPixel provides a simpler API. NeoPixelBus allows for more precise control over the LED strip's behavior and supports a wider range of use cases, but may require more setup and understanding of its features.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Adafruit NeoPixel Library Build StatusDocumentation

Arduino library for controlling single-wire-based LED pixels and strip such as the Adafruit 60 LED/meter Digital LED strip, the Adafruit FLORA RGB Smart Pixel, the Adafruit Breadboard-friendly RGB Smart Pixel, the Adafruit NeoPixel Stick, and the Adafruit NeoPixel Shield.

After downloading, rename folder to 'Adafruit_NeoPixel' and install in Arduino Libraries folder. Restart Arduino IDE, then open File->Sketchbook->Library->Adafruit_NeoPixel->strandtest sketch.

Compatibility notes: Port A is not supported on any AVR processors at this time


Installation

First Method

image

  1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries
  2. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation.
  3. Then search for Neopixel strip using the search bar.
  4. Click on the text area and then select the specific version and install it.

Second Method

  1. Navigate to the Releases page.
  2. Download the latest release.
  3. Extract the zip file
  4. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library

Features

  • Simple to use

    Controlling NeoPixels “from scratch” is quite a challenge, so we provide a library letting you focus on the fun and interesting bits.

  • Give back

    The library is free; you don’t have to pay for anything. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

  • Supported Chipsets

    We have included code for the following chips - sometimes these break for exciting reasons that we can't control in which case please open an issue!

    • AVR ATmega and ATtiny (any 8-bit) - 8 MHz, 12 MHz and 16 MHz
    • Teensy 3.x and LC
    • Arduino Due
    • Arduino 101
    • ATSAMD21 (Arduino Zero/M0 and other SAMD21 boards) @ 48 MHz
    • ATSAMD51 @ 120 MHz
    • Adafruit STM32 Feather @ 120 MHz
    • ESP8266 any speed
    • ESP32 any speed
    • Nordic nRF52 (Adafruit Feather nRF52), nRF51 (micro:bit)
    • Infineon XMC1100 BootKit @ 32 MHz
    • Infineon XMC1100 2Go @ 32 MHz
    • Infineon XMC1300 BootKit @ 32 MHz
    • Infineon XMC4700 RelaxKit, XMC4800 RelaxKit, XMC4800 IoT Amazon FreeRTOS Kit @ 144 MHz

    Check forks for other architectures not listed here!

  • GNU Lesser General Public License

    Adafruit_NeoPixel is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Functions

  • begin()
  • updateLength()
  • updateType()
  • show()
  • delay_ns()
  • setPin()
  • setPixelColor()
  • fill()
  • ColorHSV()
  • getPixelColor()
  • setBrightness()
  • getBrightness()
  • clear()
  • gamma32()

Examples

There are many examples implemented in this library. One of the examples is below. You can find other examples here

Simple

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
#define PIN        6
#define NUMPIXELS 16

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500

void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif

  pixels.begin();
}

void loop() {
  pixels.clear();

  for(int i=0; i<NUMPIXELS; i++) {

    pixels.setPixelColor(i, pixels.Color(0, 150, 0));
    pixels.show();
    delay(DELAYVAL);
  }
}

Contributing

If you want to contribute to this project:

  • Report bugs and errors
  • Ask for enhancements
  • Create issues and pull requests
  • Tell others about this library
  • Contribute new protocols

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Roadmap

The PRIME DIRECTIVE is to maintain backward compatibility with existing Arduino sketches -- many are hosted elsewhere and don't track changes here, some are in print and can never be changed!

Please don't reformat code for the sake of reformatting code. The resulting large "visual diff" makes it impossible to untangle actual bug fixes from merely rearranged lines. Also, don't bother with PRs for timing adjustments "to better match the datasheet," because the datasheet isn't really true to begin with.

Things I'd Like To Do But There's No Official Timeline So Please Don't Count On Any Of This Ever Being Canonical:

  • 400 KHz support can be removed, turns out it was never actually necessary; even the earliest NeoPixels can ingest 800 KHz data. Of course the #defines should remain so old sketches still compile, but both can be set to 0 and would have no effect on anything.
  • For the show() function (with all the delicate pixel timing stuff), break out each architecture into separate source files rather than the current unmaintainable tangle of #ifdef statements!
  • Please don't use updateLength() or updateType() in new code. They should not have been implemented this way (use the C++ 'new' operator with the regular constructor instead) and are only sticking around because of the Prime Directive. setPin() is OK for now though, it's a trick we can use to 'recycle' pixel memory across multiple strips.
  • In the M0 and M4 code, use the hardware systick counter for bit timing rather than hand-tweaked NOPs (a temporary kludge at the time because I wasn't reading systick correctly). (As of 1.4.2, systick is used on M4 devices and it appears to be overclock-compatible. Not for M0 yet, which is why this item is still here.)
  • As currently written, brightness scaling is still a "destructive" operation -- pixel values are altered in RAM and the original value as set can't be accurately read back, only approximated, which has been confusing and frustrating to users. It was done this way at the time because NeoPixel timing is strict, AVR microcontrollers (all we had at the time) are limited, and assembly language is hard. All the 32-bit architectures should have no problem handling nondestructive brightness scaling -- calculating each byte immediately before it's sent out the wire, maintaining the original set value in RAM -- the work just hasn't been done. There's a fair chance even the AVR code could manage it with some intense focus. (The DotStar library achieves nondestructive brightness scaling because it doesn't have to manage data timing so carefully...every architecture, even ATtiny, just takes whatever cycles it needs for the multiply/shift operations.)

Credits

This library is written by Phil "Paint Your Dragon" Burgess for Adafruit Industries, with contributions by PJRC, Michael Miller and other members of the open source community.

License

Adafruit_NeoPixel is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Adafruit_NeoPixel is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see this