Adafruit DotStar Arduino Library
|
Class that stores state and functions for interacting with Adafruit DotStars and compatible devices. More...
#include <Adafruit_DotStar.h>
Public Member Functions | |
Adafruit_DotStar (uint16_t n, uint8_t o=DOTSTAR_BRG, SPIClass *spi=&SPI) | |
DotStar constructor for hardware SPI. Must be connected to MOSI, SCK pins. More... | |
Adafruit_DotStar (uint16_t n, uint8_t d, uint8_t c, uint8_t o=DOTSTAR_BRG) | |
DotStar constructor for 'soft' (bitbang) SPI. Any two pins can be used. More... | |
~Adafruit_DotStar (void) | |
Deallocate Adafruit_DotStar object, set data and clock pins back to INPUT. | |
void | begin (void) |
Initialize Adafruit_DotStar object – sets data and clock pins to outputs and initializes hardware SPI if necessary. | |
void | show (void) |
Transmit pixel data in RAM to DotStars. | |
void | setPixelColor (uint16_t n, uint32_t c) |
Set a pixel's color using a 32-bit 'packed' RGB value. More... | |
void | setPixelColor (uint16_t n, uint8_t r, uint8_t g, uint8_t b) |
Set a pixel's color using separate red, green and blue components. More... | |
void | fill (uint32_t c=0, uint16_t first=0, uint16_t count=0) |
Fill all or part of the DotStar strip with a color. More... | |
void | setBrightness (uint8_t) |
Adjust output brightness. Does not immediately affect what's currently displayed on the LEDs. The next call to show() will refresh the LEDs at this level. More... | |
void | clear () |
Fill the whole DotStar strip with 0 / black / off. | |
void | updateLength (uint16_t n) |
Change the length of a previously-declared Adafruit_DotStar strip object. Old data is deallocated and new data is cleared. Pin numbers and pixel format are unchanged. More... | |
void | updatePins (void) |
Switch over to hardware SPI. DotStars must be connected to MOSI, SCK pins. Data in pixel buffer is unaffected and can continue to be used. | |
void | updatePins (uint8_t d, uint8_t c) |
Switch over to 'soft' (bitbang) SPI. DotStars can be connected to any two pins. Data in pixel buffer is unaffected and can continue to be used. More... | |
uint8_t * | getPixels (void) const |
Get a pointer directly to the DotStar data buffer in RAM. Pixel data is stored in a device-native format (a la the DOTSTAR_* constants) and is not translated here. Applications that access this buffer will need to be aware of the specific data format and handle colors appropriately. More... | |
uint8_t | getBrightness (void) const |
Retrieve the last-set brightness value for the strip. More... | |
uint16_t | numPixels (void) const |
Return the number of pixels in an Adafruit_DotStar strip object. More... | |
uint32_t | getPixelColor (uint16_t n) const |
Query the color of a previously-set pixel. More... | |
void | rainbow (uint16_t first_hue=0, int8_t reps=1, uint8_t saturation=255, uint8_t brightness=255, boolean gammify=true) |
Fill DotStar strip with one or more cycles of hues. Everyone loves the rainbow swirl so much, now it's canon! More... | |
Static Public Member Functions | |
static uint8_t | sine8 (uint8_t x) |
An 8-bit integer sine wave function, not directly compatible with standard trigonometric units like radians or degrees. More... | |
static uint8_t | gamma8 (uint8_t x) |
An 8-bit gamma-correction function for basic pixel brightness adjustment. Makes color transitions appear more perceptially correct. More... | |
static uint32_t | Color (uint8_t r, uint8_t g, uint8_t b) |
Convert separate red, green and blue values into a single "packed" 32-bit RGB color. More... | |
static uint32_t | ColorHSV (uint16_t hue, uint8_t sat=255, uint8_t val=255) |
Convert hue, saturation and value into a packed 32-bit RGB color that can be passed to setPixelColor() or other RGB-compatible functions. More... | |
static uint32_t | gamma32 (uint32_t x) |
A gamma-correction function for 32-bit packed RGB colors. Makes color transitions appear more perceptially correct. More... | |
Class that stores state and functions for interacting with Adafruit DotStars and compatible devices.
Adafruit_DotStar::Adafruit_DotStar | ( | uint16_t | n, |
uint8_t | o = DOTSTAR_BRG , |
||
SPIClass * | spi = &SPI |
||
) |
DotStar constructor for hardware SPI. Must be connected to MOSI, SCK pins.
n | Number of DotStars in strand. |
o | Pixel type – one of the DOTSTAR_* constants defined in Adafruit_DotStar.h, for example DOTSTAR_BRG for DotStars expecting color bytes expressed in blue, red, green order per pixel. Default if unspecified is DOTSTAR_BRG. |
spi | Pointer to hardware SPIClass object (default is primary SPI device 'SPI' if defined, else MUST pass in device). |
Adafruit_DotStar::Adafruit_DotStar | ( | uint16_t | n, |
uint8_t | data, | ||
uint8_t | clock, | ||
uint8_t | o = DOTSTAR_BRG |
||
) |
DotStar constructor for 'soft' (bitbang) SPI. Any two pins can be used.
n | Number of DotStars in strand. |
data | Arduino pin number for data out. |
clock | Arduino pin number for clock out. |
o | Pixel type – one of the DOTSTAR_* constants defined in Adafruit_DotStar.h, for example DOTSTAR_BRG for DotStars expecting color bytes expressed in blue, red, green order per pixel. Default if unspecified is DOTSTAR_BRG. |
void Adafruit_DotStar::setPixelColor | ( | uint16_t | n, |
uint32_t | c | ||
) |
Set a pixel's color using a 32-bit 'packed' RGB value.
n | Pixel index, starting from 0. |
c | 32-bit color value. Most significant byte is 0, second is red, then green, and least significant byte is blue. e.g. 0x00RRGGBB |
void Adafruit_DotStar::setPixelColor | ( | uint16_t | n, |
uint8_t | r, | ||
uint8_t | g, | ||
uint8_t | b | ||
) |
Set a pixel's color using separate red, green and blue components.
n | Pixel index, starting from 0. |
r | Red brightness, 0 = minimum (off), 255 = maximum. |
g | Green brightness, 0 = minimum (off), 255 = maximum. |
b | Blue brightness, 0 = minimum (off), 255 = maximum. |
void Adafruit_DotStar::fill | ( | uint32_t | c = 0 , |
uint16_t | first = 0 , |
||
uint16_t | count = 0 |
||
) |
Fill all or part of the DotStar strip with a color.
c | 32-bit color value. Most significant byte is 0, second is red, then green, and least significant byte is blue. e.g. 0x00RRGGBB. If all arguments are unspecified, this will be 0 (off). |
first | Index of first pixel to fill, starting from 0. Must be in-bounds, no clipping is performed. 0 if unspecified. |
count | Number of pixels to fill, as a positive value. Passing 0 or leaving unspecified will fill to end of strip. |
void Adafruit_DotStar::setBrightness | ( | uint8_t | b | ) |
Adjust output brightness. Does not immediately affect what's currently displayed on the LEDs. The next call to show() will refresh the LEDs at this level.
b | Brightness setting, 0=minimum (off), 255=brightest. |
void Adafruit_DotStar::updateLength | ( | uint16_t | n | ) |
Change the length of a previously-declared Adafruit_DotStar strip object. Old data is deallocated and new data is cleared. Pin numbers and pixel format are unchanged.
n | New length of strip, in pixels. |
void Adafruit_DotStar::updatePins | ( | uint8_t | data, |
uint8_t | clock | ||
) |
Switch over to 'soft' (bitbang) SPI. DotStars can be connected to any two pins. Data in pixel buffer is unaffected and can continue to be used.
data | Arduino pin number for data out. |
clock | Arduino pin number for clock out. |
|
inline |
Get a pointer directly to the DotStar data buffer in RAM. Pixel data is stored in a device-native format (a la the DOTSTAR_* constants) and is not translated here. Applications that access this buffer will need to be aware of the specific data format and handle colors appropriately.
uint8_t Adafruit_DotStar::getBrightness | ( | void | ) | const |
Retrieve the last-set brightness value for the strip.
|
inline |
Return the number of pixels in an Adafruit_DotStar strip object.
uint32_t Adafruit_DotStar::getPixelColor | ( | uint16_t | n | ) | const |
Query the color of a previously-set pixel.
n | Index of pixel to read (0 = first). |
|
inlinestatic |
An 8-bit integer sine wave function, not directly compatible with standard trigonometric units like radians or degrees.
x | Input angle, 0-255; 256 would loop back to zero, completing the circle (equivalent to 360 degrees or 2 pi radians). One can therefore use an unsigned 8-bit variable and simply add or subtract, allowing it to overflow/underflow and it still does the expected contiguous thing. |
|
inlinestatic |
An 8-bit gamma-correction function for basic pixel brightness adjustment. Makes color transitions appear more perceptially correct.
x | Input brightness, 0 (minimum or off/black) to 255 (maximum). |
|
inlinestatic |
Convert separate red, green and blue values into a single "packed" 32-bit RGB color.
r | Red brightness, 0 to 255. |
g | Green brightness, 0 to 255. |
b | Blue brightness, 0 to 255. |
|
static |
Convert hue, saturation and value into a packed 32-bit RGB color that can be passed to setPixelColor() or other RGB-compatible functions.
hue | An unsigned 16-bit value, 0 to 65535, representing one full loop of the color wheel, which allows 16-bit hues to "roll over" while still doing the expected thing (and allowing more precision than the wheel() function that was common to prior DotStar and NeoPixel examples). |
sat | Saturation, 8-bit value, 0 (min or pure grayscale) to 255 (max or pure hue). Default of 255 if unspecified. |
val | Value (brightness), 8-bit value, 0 (min / black / off) to 255 (max or full brightness). Default of 255 if unspecified. |
|
static |
A gamma-correction function for 32-bit packed RGB colors. Makes color transitions appear more perceptially correct.
x | 32-bit packed RGB color. |
void Adafruit_DotStar::rainbow | ( | uint16_t | first_hue = 0 , |
int8_t | reps = 1 , |
||
uint8_t | saturation = 255 , |
||
uint8_t | brightness = 255 , |
||
boolean | gammify = true |
||
) |
Fill DotStar strip with one or more cycles of hues. Everyone loves the rainbow swirl so much, now it's canon!
first_hue | Hue of first pixel, 0-65535, representing one full cycle of the color wheel. Each subsequent pixel will be offset to complete one or more cycles over the length of the strip. |
reps | Number of cycles of the color wheel over the length of the strip. Default is 1. Negative values can be used to reverse the hue order. |
saturation | Saturation (optional), 0-255 = gray to pure hue, default = 255. |
brightness | Brightness/value (optional), 0-255 = off to max, default = 255. This is distinct and in combination with any configured global strip brightness. |
gammify | If true (default), apply gamma correction to colors for better appearance. |