Библиотеки ардуино
Содержание:
- Supported platforms
- Supported chipsets
- My FastLED Animation Philosophy
- Introducing notamesh and notasound
- Available Methods
- Introduction
- F_manyPorts
- Demos
- This repo now contains experimental support for parallel data output on ESP32; currently (08/16/17) hardcoded for 8 outputs on pins 12-19
- FastLED 3.1
- Arduino-esp32
- Timing and speed
- Use notes
- Licensing
- Step 3: Setting Up LED Strip:
- Making the Arduino WS2812 connection
- Supported LED chipsets
- Features
- NeoPixel Tutorial
- Supported LED chipsets
- Documentation
- Usage
- Examples
Supported platforms
Right now the library is supported on a variety of arduino compatable platforms. If it’s ARM or AVR and uses the arduino software (or a modified version of it to build) then it is likely supported. Note that we have a long list of upcoming platforms to support, so if you don’t see what you’re looking for here, ask, it may be on the roadmap (or may already be supported). N.B. at the moment we are only supporting the stock compilers that ship with the arduino software. Support for upgraded compilers, as well as using AVR studio and skipping the arduino entirely, should be coming in a near future release.
- Arduino & compatibles — straight up arduino devices, uno, duo, leonardo, mega, nano, etc…
- Arduino Yún
- Adafruit Trinket & Gemma — Trinket Pro may be supported, but haven’t tested to confirm yet
- Teensy 2, Teensy++ 2, Teensy 3.0, Teensy 3.1/3.2, Teensy LC, Teensy 3.5, Teensy 3.6, and Teensy 4.0 — arduino compataible from pjrc.com with some extra goodies (note the teensy 3, 3.1, and LC are ARM, not AVR!)
- Arduino Due and the digistump DigiX
- RFDuino
- SparkCore
- Arduino Zero
- ESP32 based boards
What types of platforms are we thinking about supporting in the future? Here’s a short list: ChipKit32, Maple, Beagleboard
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)
Check forks for other architectures not listed here!
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. (Exception for first item in wishlist below.)
Things I’d Like To Do But There’s No Official Timeline So Please Don’t Count On Any Of This Ever Being Canonical:
- 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!
- Really the only reason I’ve never incorporated an HSV color function is that I haven’t settled on a type and range for the hue element (mathematically an integer from 0 to 1529 yields a «most correct» approach but it’s weird to use and would probably annoy people).
- Add a fill function with the arguments: (color, first, count). Count, if unspecified, fills to end of strip. First, if unspecified, is zero. Color, if unspecified, is zero (effectively a strip clear operation). Do NOT then implement fifty billion minor variations (such as first, last). No. This argument sequence was very specifically chosen because reasons, and equivalents to such variations are trivially made in one’s call. Just one fill function, please.
- At such time that the prior two items are settled, revisit the DotStar library (and maybe even LPD8806 or anything else we’ve got) and add the same functions and behaviors so there’s a good degree of sketch compatibility across different pixel types.
- I wouldn’t mind paring down strandtest a bit. More diagnostic, less Amiga demo.
- 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 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.)
My FastLED Animation Philosophy
- Do NOT use delay statements in the loop as that breaks input routines (i.e. button).
- Do not use nested loops (for performance reasons).
- Use millis() as a real time counter unless a fixed counter is required.
- Spend a bit more time using high school math (ie trigonometry), rather than just count pixels.
- Keep the display routines as short as possible.
- Data typing as strict as possible i.e. why define an int when a uint8_t is all that is required. Oh, and floats are not used at all.
- Localize variables to each routine as much as possible.
- Break out the display routines into separate .h files for increased readability and modularity.
- Be generous with comments.
Introducing notamesh and notasound
Introducing two new display demos for Arduino and FastLED.
notamesh – Introduces the ability to synchronize and delay display sequences across multiple Arduino microcontrollers via IR control.
Q. What is this ‘mesh’ all about?
You can configure multiple Arduino microcontrollers with the same display sequence, but with a short delay, thus giving the effect of synchronization.
Scenario:
You have 5 IR controlled Arduino based displays, all within eyesight of each other, and all running notamesh. At compile time, each will be configured for the type of LED’s in use as well as a unique ID for each and with demo mode enabled.
Upon first time power-up, each strand will be configured with the length of the strand, as well as a delay. For instance, each Arduino has 40 LED’s connected to it.
- Arduino A1 – 0ms delay
- Arduino A2 – 100ms delay
- Arduino A3 – 200ms delay
- and so on . . . .
Once they’re all programmed and running, you would then press the ‘Reset’ button on the IR controller in order to synchronize millis() and the Arduinos would begin displaying the demo mode, with each Arduino slightly out of sync with the others.
These sketches:
- Run on an Arduino UNO/Nano, etc.
- Use the FastLED display library.
- Use Nico Hood’s IR library.
- Include a LOT of display routines.
Basic IR Functionality
- Adjust overall brightness.
- Adjust overall speed.
- Reset (to sync multiple controllers).
- Enable/disable demo mode.
- Increase/decrease speed of animation.
- Adjust overall brightness.
- Change direction of some routines.
- Enable/disable glitter.
- Select previous/next display routine.
- Enable/disable palette rotation.
- Select previous/next palette.
- A ‘lamp’ mode.
- Select hue/saturation.
- Select a single hue based palette
EEPROM Functionality
- Select specific Arduino for EEPROM configuration.
- Adjust strand length.
- Adjust mesh delay.
- Change startup display mode.
- Program/select 2 favourite display modes.
- Added a bunch of other things as documented in notamesh and notasound.
Sound functionality
- Continuous sampling of sounds via ADMP401 microphone.
- Averaging of last 32 samples.
- Quick averaging of last 4 samples.
- Crude peak detection.
- Integration of sound with various display routines.
- IR control of sound squelch.
- No FFT or MSGEQ7 required.
Available Methods
void drawPixel(int16_t x, int16_t y, CRGB color) void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color) void drawFastVLine(int16_t x, int16_t y, int16_t h, CRGB color) void drawFastHLine(int16_t x, int16_t y, int16_t w, CRGB color) void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, CRGB color) void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, CRGB color) void fillScreen(CRGB color) void invertDisplay(boolean i) void drawCircle(int16_t x0, int16_t y0, int16_t r, CRGB color) void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, CRGB color) void fillCircle(int16_t x0, int16_t y0, int16_t r, CRGB color) void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, CRGB color) void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, CRGB color) void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, CRGB color) void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, CRGB color) void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, CRGB color) void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, CRGB color) void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, CRGB color, CRGB bg) void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, CRGB color) void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, CRGB color, CRGB bg) void drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, CRGB color) void drawChar(int16_t x, int16_t y, unsigned char c, CRGB color, CRGB bg, uint8_t size) void setCursor(int16_t x, int16_t y) void setTextColor(CRGB c) void setTextColor(CRGB c, CRGB bg) void setTextSize(uint8_t s) void setTextWrap(boolean w) void setRotation(uint8_t r) void cp437(boolean x=true) void setFont(const GFXfont *f = NULL) void getTextBounds(char *string, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) void getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) size_t write(uint8_t) int16_t height(void) const int16_t width(void) const uint8_t getRotation(void) const int16_t getCursorX(void) const int16_t getCursorY(void) const
Introduction
Here are several display sequences for FastLED for a single strand of addressable RGB LED’s, such as NeoPixels/WS2812, WS2801 or DotStars/APA102. Each should compile and run separately and all have been tested on an Arduino Nano with appropriate inputs as required.
Almost all of these sequences are designed to be loop/non-blocking delay friendly. They perform some simple calculations, update the LED array, return back to the loop to SHOW the LED’s and then continue on to the next iteration.
In addition to several standalone demos, I have included comprehensive demos called notamesh and notasound (NOT for beginners), which supports multiple display sequences, multiple Arduino’s, has a demo mode, EEPROM IR remote and sound reactive support. There are also a couple of separate button controlled demos with EEPROM support.
In addition, I have included a few other sound reactive sequences, most notably fht_log_ripple, which uses the ADMP401 MEMS microphone and the FHT (Fast Hartley Transform) library to respond to sound in the frequency domain. Tricky to get going, but very cool.
F_manyPorts
This example demonstrates how to update LED strips connected to multiple port pins.
- by writing to each strip separately
- by writting to two strips in parallel using ws2812bs (split), each strip getting 1/2 the array
- by writting to two strips in parallel using ws2812bi (interleave), one strip getting the odd and the other the even pixels.
- by writting a custom function to send the same pixels to all the ports
- by writting a custom function to send interleaved each pixels to each strip. On Arduino this does not work until all but one LED strip update is commented out.
The LEDs are lit by a RGB checkerboard. The test is designed to shimmer the pixels at a frequency that indicates how fast the LEDs are being refreshed to see how fast is each method.
Since not all port are updated by ws2812bs/ws2812bi, in between sequences 2 white pixels are drawn.
Demos
Here you will find examples of uses of the FAB_LED library that are not shipped with the library. These can be personal projects, extensions and features not implemented yet.
This repo now contains experimental support for parallel data output on ESP32; currently (08/16/17) hardcoded for 8 outputs on pins 12-19
IMPORTANT NOTE: For AVR based systems, avr-gcc 4.8.x is supported and tested. This means Arduino 1.6.5 and later.
FastLED 3.1
This is a library for easily & efficiently controlling a wide variety of LED chipsets, like the ones
sold by adafruit (Neopixel, DotStar, LPD8806), Sparkfun (WS2801), and aliexpress. In addition to writing to the
leds, this library also includes a number of functions for high-performing 8bit math for manipulating
your RGB values, as well as low level classes for abstracting out access to pins and SPI hardware, while
still keeping things as fast as possible. Tested with Arduino up to 1.6.5 from arduino.cc.
Quick note for people installing from GitHub repo zips, rename the folder FastLED before copying it to your Arduino/libraries folder. Github likes putting -branchname into the name of the folder, which unfortunately, makes Arduino cranky!
We have multiple goals with this library:
- Quick start for new developers — hook up your leds and go, no need to think about specifics of the led chipsets being used
- Zero pain switching LED chipsets — you get some new leds that the library supports, just change the definition of LEDs you’re using, et. voila! Your code is running with the new leds.
- High performance — with features like zero cost global brightness scaling, high performance 8-bit math for RGB manipulation, and some of the fastest bit-bang’d SPI support around, FastLED wants to keep as many CPU cycles available for your led patterns as possible
Arduino-esp32
You need a few of the HAL files. Please update these in the subdirectory hal. Don’t forget to close
the pod bay doors.
Timing and speed
On an ESP32 running at 240Mhz, I was able to time 40 pixels at 1.2 milliseconds. I timed showLeds()
at 3.0 milliseconds at 100 LEDs.
However, if you use more than one controller ( see the THREADING document ),
three different controllers each will do 100 LEDs in 3 milliseconds. I have tested
this with 1, 3, and 6 controllers. They all take the same amount of time.
If 30 milliseconds makes 30fps, then you should be able to do 1000 pixels on one of the two cores,
and still, potentially, have the ability to do some extra work, because you’ve got the other CPU.
I have not determined if this is using the RMT interface, which would mean we could
use an async internal interface. The timing, however, is very solid.
Use notes
What I like about using FreeRTOS and a more interesting development environment is
you should be able to use more of the CPU for other things. Essentially, you should
be able to have the RMT system feeding itself, which then allows the main CPU
to be updating the arrays of colors, and multiple channels to be doing the right
thing all at the same time.
However, really being multi-core would mean having a locking semantic around the color
array, or double buffering. FastLED doesn’t seem to really think that way,
rightfully so.
Licensing
FastLED is MIT license.
I intend my portions to be MIT license. AKA the don’t sue me license.
However, the Espressif HAL code is LGPL. Mostly, these are used as headers,
not as code itself. There’s very little of value there. If LGPL bothers
you, I would propose a quick rewrite of those files, and submit a pull request
that would be under MIT license.
I am honestly not sure what happens to LGPL in this case. It’s a component in an
embedded system, which is morally a library, but it is clearly very statically
linked.
I don’t intend to make any money off this, don’t charge people, and do not intend
the use for commercial art projects, so the use is safe for me. But don’t say
I didn’t warn you.
Step 3: Setting Up LED Strip:
Connect the LED Strip to your power supply. Data pin of the LED Strip goes into the any digital pin you selected in the code. Make sure that the ground of the LED strop and the arduino must be connected together.
You can use neopixel led strip or you can buy cheap led strip from market and what you need to do that remove the first led section of the led strip which having master controller. From next series of LEDs you can use as the neopixel strip. But in chinese led strip one ic controls three led in series that means each pixel is equal to the 3 led pixel. If you write data on the first ic the three leds connected with that ic will lit up. So I’m using this type of cheap led strip which having 7 ic in series which controll 21 led as a bunch of 3 leds.
Connections:
Arduino: digital pin 6 —> Din pin of LED Strip
gnd —> Gnd of LED strip
Power Supply: positive terminal —> +vcc of LED Strip
gnd —> gnd of LED Strip
Making the Arduino WS2812 connection
Now that we have a WS2812 strip, time to hook it up to our Arduino (I used an Arduino UNO for this).
Power
Caution
A strip of LED’s will pull way too much power for your Arduino to handle, so always consider an additional 5V power supply.
Rule of thumb is : each RGB LED unit pulls about 60 mA (3x 20 mA, for Red, Green and Blue).
LED’s, even though they’re called power efficient, do need juice … and for each WS2812 we need up to 60 mA when the 3 LEDs inside are at maximum brightness at 5V.
Power Supply
You can use an external power supply for this purpose and even though my 1 meter strip theoretically needs 3.6 A at max brightness, my little 2A power supply managed to handle it – your milage may vary! (1 meter with 60 LEDs/meter = 60 * 60 mA = 3600 mA = 3.6 A max.)
A switching power supply is often ideal and pretty cheap – you might even have one or the other laying around from your old cellphone, just make sure it’s actually giving you 5 – 6V and not weird voltages like 12V or 16V or even more. Verification with a Voltage meter is recommended.
Batteries
You can consider using batteries, although I’m not a big fan of using them. With batteries please pay attention to the voltage sum.
Consider:
– 3 x Alkaline AA batteries (4.5 V) or
– 4 x NiMH AA rechargeable batteries (4.8 V)
About Amps and such
Like I mentioned before, each LED module takes a max of 60 mA, so you can calculate how many Amps your power source has to provide. Keep in mind that 1000 mA = 1 A.
Your power supply can have overcapacity when it comes to Amps, so if your project needs 3.6 A, and you only have a 10 A power supply, then this will work great.
Keep in mind though that the Voltage must be close to the 5V value. Higher voltages may damage your LEDs.
Connecting Arduino and WS2812 strip
The basic layout of power can be done in 2 ways – with computer or without …
Arduino Connected to your Computer
Commonly, during testing, your Arduino is connected to your computer via a USB cable where the USB cable does not only program the microcontroller but will also provide power for the Arduino.
The DIN (data input) pin of the LED strip goes to Arduino PIN 6 with an optional 470Ω resistor in between.+5V of the LED strip goes to the +5V of extra power supply.GND of the LED strip goes to GND of the extra power supply and to the GND of the Arduino.The USB of the Arduino is connected to your computer.
Arduino & WS2812 – USB and External Power
Arduino Not connected to your computer
Once you’ve completed your prototyping, you could still keep using your Arduino for controlling the LED strip.
In that case you’d typically have the Arduino in a very different location, and thus not connected to your computer. In that case the extra power supply for the LEDs could be used to feed the Arduino as well.
The DIN (data input) pin of the LED strip goes to PIN 6 of the Arduino with an optional 470Ω resistor in between.+5V of the LED strip goes to the +5V of extra power supply and the +5V on your Arduino (or Vin).GND of the LED strip goes to GND of the extra power supply and to the GND of the Arduino.
Power connected to +5V or Vin?
In the drawing below, you’ll notice that I have used +5V pin for the powersupply.
This works well when you’re using a proper and well regulated powersupply, which I do.
For all correctness, and when using less regulated powersupplies, the Vin pin is recommended.
Arduino & WS2812 – Only running on external power supply
Supported LED chipsets
Here’s a list of all the LED chipsets are supported. More details on the led chipsets are included TODO: Link to wiki page
- Adafruit’s DotStars — AKA the APA102
- Adafruit’s Neopixel — aka the WS2812B (also WS2811/WS2812/WS2813, also supported in lo-speed mode) — a 3 wire addressable led chipset
- TM1809/4 — 3 wire chipset, cheaply available on aliexpress.com
- TM1803 — 3 wire chipset, sold by radio shack
- UCS1903 — another 3 wire led chipset, cheap
- GW6205 — another 3 wire led chipset
- LPD8806 — SPI based chpiset, very high speed
- WS2801 — SPI based chipset, cheap and widely available
- SM16716 — SPI based chipset
- APA102 — SPI based chipset
- P9813 — aka Cool Neon’s Total Control Lighting
- DMX — send rgb data out over DMX using arduino DMX libraries
- SmartMatrix panels — needs the SmartMatrix library — https://github.com/pixelmatix/SmartMatrix
- LPD6803 — SPI based chpiset, chip CMODE pin must be set to 1 (inside oscillator mode)
HL1606, and «595»-style shift registers are no longer supported by the library. The older Version 1 of the library («FastSPI_LED») has support for these, but is missing many of the advanced features of current versions and is no longer being maintained.
Features
-
Controlling NeoPixels “from scratch” is quite a challenge, so we provide a library letting you focus on the fun and interesting bits.
-
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)
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.
NeoPixel Tutorial
written by Scott Kildall
A series of Arduino Sketches to progressively show programming techniques using the NeoPixels.
Overview
NeoPixels are RGB pixels that chainable from one to the next so you can power and program a long line of NeoPixels together to form an long string of individually addressable LEDs. One advantage is that they have one data line, so the wiring is very easy.
For the sake of these tutorials, the data pin of the NeoPixel is always on pin 6.
Because of the ease-of-use, the NeoPixels are perfect for showing basic Arduino programming techniques.
Installation
Place the «NeoPixel Samples» folder in your Arduino folder, which should be located in your documents folder.
You can load each one under the File->Sketchbook->Neopixel Samples
Also, you will want to make sure that you have the NeoPixel library from AdaFruit installed, here:
Sketches
Each sketch progressively builds on the previous one, so I’d suggest moving through them in order.
(1) neopixel_basic: this will light up your strand of NeoPixels as one color (default is blue).
Changes: try changing the red, green and blue variables to change to color of your NeoPixel strips
(2) neopixel_basic_button: this adds a button to turn the NeoPixel strip on and off. The switch is connected to pin 4.
Changes: try altering the code so that pressing the button down turns the NeoPixel strip on and the default state is off.
(3) neopixel_basic_func: this encapsulates the code into two separate fucntions.
Changes: try changing the function names.
(4) neopixel_bright: this will adjust the brightness levels of the NeoPixels, showing how we use math functions to control timing. Also, we introduce the concept of the preprocessor macro and the serial monitor output.
Try: going to Tools->Serial Monitor to see the output of the brightness levels
Also the button down will still turn off the entire strip
Changes: try changing the delay value or the brightDirection variable
(5) neopixel_3color: this will produce 3 bands of color on the NeoPixel
Changes: try changing the 3 color values. why is this code «crude» in its form. is there a better way to accomplish this?
(6) neopixel_moving1: this will cycle through the 3 colors
Try: pressing the button, notice how there is a slow response — this is because we are getting locked into the delay loop
Changes: try changing the delay time for a faster effect
(7) neopixel_moving2: this will cycle through the 3 colors as above, but uses the millis() button instead of delay() to control timing, so that your button response is immediate.
(8) neopixel_moving3: uses the random funciton, while cycling through the colors to change the RGB color values in response to the button presses.
(9) neopixel_gradient1: uses math to make a gradient from white to pink
Changes: try changing RGB color values
(10) neopixel_gradient2: shows an animated gradient using math to adjust the gradient levels for each pixel.
Changes: try changing RGB color values
(11) neopixel_gradient3: shows an animated gradient using math to adjust the gradient levels for each pixel and uses a poteniometer to adjust the speed of the animation.
Changes: try changing the delay time for a faster or slower animation effect
(12) neopixel_sequencer This sketch will shows 5 different sequences and effects. A potentiometer at pin A5 will adjust the
speed of each animation.
Changes: play with it, have fun!
Supported LED chipsets
Here’s a list of all the LED chipsets are supported. More details on the led chipsets are included TODO: Link to wiki page
- Adafruit’s DotStars — AKA the APA102
- Adafruit’s Neopixel — aka the WS2812B (also WS2811/WS2812/WS2813, also supported in lo-speed mode) — a 3 wire addressable led chipset
- TM1809/4 — 3 wire chipset, cheaply available on aliexpress.com
- TM1803 — 3 wire chipset, sold by radio shack
- UCS1903 — another 3 wire led chipset, cheap
- GW6205 — another 3 wire led chipset
- LPD8806 — SPI based chpiset, very high speed
- WS2801 — SPI based chipset, cheap and widely available
- SM16716 — SPI based chipset
- APA102 — SPI based chipset
- P9813 — aka Cool Neon’s Total Control Lighting
- DMX — send rgb data out over DMX using arduino DMX libraries
- SmartMatrix panels — needs the SmartMatrix library — https://github.com/pixelmatix/SmartMatrix
LPD6803, HL1606, and «595»-style shift registers are no longer supported by the library. The older Version 1 of the library («FastSPI_LED») has support for these, but is missing many of the advanced features of current versions and is no longer being maintained.
Documentation
Creates an object to interact wth a NeoPixel strip.
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!
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.
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.
Sets up the pin used for the NeoPixel strip.
Set the color of LED number (0 to ). ,
, , are between 0 and 255. White is only used for
RGBW type pixels. is a color returned from .
The brightness set with will modify the color before it
is applied to the LED.
Displays the colors on the NeoPixel strip that were set with 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.
Set all LED color to off. Will take effect on next .
Make the LED less bright. 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.
Get the current brightness.
Set the color of LED number and scale that color non-linearly according to the parameter (0 to 255).
Set the color of LED number and dim that color linearly according to the parameter (0 to 255). In this case 128 should look half as bright as 255.
Make a color from component colors. Useful if you want to store colors in a variable or pass them as function arguments.
Get the current color of an LED in the same format as .
Change the pin used for the NeoPixel strip.
Change the number of LEDs in the NeoPixel strip.
Get the raw color data for the LEDs.
Get the number of LEDs in the NeoPixel strip. is an alias for .
Usage
If you’re using the FT232H cable make sure to use the 5 volt version (although in my testing the 3.3 volt cable seems to be work—your mileage may vary). Hook the yellow serial out wire to the NeoPixel signal input and the black ground wire to NeoPixel power ground. Don’t try to power the NeoPixels from the cable, they pull too much power!
The library interface is almost exactly the same as the Arduino library interface, but with the following changes:
-
The Adafruit_NeoPixel object constructor takes an optional MPSSE object reference (from the libmpsse library) instead of a pin id. If this is not set the library will automatically search for the first attached FTDI device with MPSSE support it can find. The setPin function has been changed to setMPSSE and similarly takes a reference to an MPSSE object. In practice you don’t need to worry about setting this paramter unless you have multiple MPSSE devices and need to choose an explicit one (see the library code for how it creates one).
-
Bit flags in the constructor have been replaced with explicit boolean keyword arguments ‘neo_rgb’ and ‘neo_khz400’. If not specified the default is a 800khz GRB NeoPixels like in the Arduino library.
-
Added close function to shut down the connection to the MPSSE device. It’s not strictly necessary to call this unless you want to close the connection for some reason.
-
Added setPixelColorRGB function which replaces the overloaded setPixelColor function that takes RGB triples (python doesn’t support method overloading).
-
Modified setBrightness to take a float value 0 to 1.0 instead of byte value 0 to 255. A value of 0 is completely dark pixels and a value of 1.0 is normal brightness. Note that at low brightness (below 0.25) I’ve noticed flickering and odd pixel behavior.
See the strandtest example port in strandtest.py for an example of using the library.
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=; i<NUMPIXELS; i++) { pixels.setPixelColor(i, pixels.Color(, 150, )); pixels.show(); delay(DELAYVAL); } }