mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
add neopixel example
This commit is contained in:
66
lib/NeoPattern/NeoPattern_api_modes.cpp
Normal file
66
lib/NeoPattern/NeoPattern_api_modes.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef __NEOPATTERN_API_MODES__
|
||||
#define __NEOPATTERN_API_MODES__
|
||||
|
||||
#include "NeoPattern.cpp"
|
||||
|
||||
enum PIXEL_MODE { PIXELS_OFF = 0, COLOR_WHEEL_MODE = 1, COLOR_MODE = 2, PATTERN_MODE = 3};
|
||||
typedef void (*PIXEL_FP)(NeoPattern*, const char *);
|
||||
|
||||
/*
|
||||
Array of function pointers to be used as lookup table using the int values of PIXEL_MODE.
|
||||
TODO header file + separate functions instead of lambdas
|
||||
*/
|
||||
const PIXEL_FP PIXEL_FNCS[] = {
|
||||
/*
|
||||
PIXESL_OFF
|
||||
Sets all pixels to black.
|
||||
*/
|
||||
[](NeoPattern* pixels, const char *color){
|
||||
pixels->clear();
|
||||
pixels->ColorSet(0);
|
||||
},
|
||||
/*
|
||||
COLOR_WHEEL_MODE
|
||||
Input: integer color from 0 to 155
|
||||
Uses the color wheel to set a color.
|
||||
If given integer is <= 1, set the color to black.
|
||||
By using this function, Color1 and Color2 is set on the pixels;
|
||||
Color1 = new color, Color2 = last color.
|
||||
*/
|
||||
[](NeoPattern* pixels, const char *color){
|
||||
int c1 = atoi(color);
|
||||
int c2 = pixels->Color1;
|
||||
pixels->Color1 = c1;
|
||||
pixels->Color2 = c2;
|
||||
pixels->ActivePattern = NONE;
|
||||
if(c1 <= 1) {
|
||||
pixels->ColorSet(0);
|
||||
return;
|
||||
}
|
||||
pixels->ColorSet(pixels->Wheel(c1));
|
||||
},
|
||||
/*
|
||||
COLOR_MODE
|
||||
Input: rgb hex color without #
|
||||
parses the hex string to r,g,b and sets all pixels accordingly
|
||||
*/
|
||||
[](NeoPattern* pixels, const char *color){
|
||||
int r, g, b;
|
||||
sscanf(color, "%02x%02x%02x", &r, &g, &b);
|
||||
pixels->ColorSet(pixels->Color(r,g,b));
|
||||
},
|
||||
/*
|
||||
PATTERN_MODE
|
||||
Input: id of the pattern
|
||||
Sets the active pattern on the strip.
|
||||
As every pattern has another API, all fields need to be set before, for example by using COLOR_WHEEL_MODE.
|
||||
*/
|
||||
[](NeoPattern* pixels, const char *id){
|
||||
pattern p = (pattern)atoi(id);
|
||||
pixels->Interval = 50;
|
||||
pixels->TotalSteps = pixels->numPixels();
|
||||
pixels->ActivePattern = p;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user