migrate code to AS7, including fucked up arduino import
arduino as a library will not build with -flto. I can't figure it out. so we waste some space compared to what platformio was building. oh well. there's still over 1K of space left for programs.
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
# tinyNeoPixel_Static License
|
||||
The tinyNeoPixel_Static library is derived from tinyNeoPixel, which is in turn derived from adafruitNeoPixel, which is released under the terms of the LGPL 3, unlike the rest of the core which is released under LGPL 2.1.
|
||||
The license was previously in a file named "COPYING". It has been renamed for consistency and prefaced for clarity.
|
||||
|
||||
## GNU Lesser General Public License, Version 3
|
||||
```legalese
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
```
|
||||
@@ -0,0 +1,15 @@
|
||||
# tinyNeoPixel documentation is elsewhere
|
||||
tinyNeoPixel is a tweaked version of adafruitNeoPixel, supporting more clock speeds and correcting some improperly specified constraints, but should be code compatible excepting the change to the class name. This core also includes tinyNeoPixel_Static, which has been modified further to reduce the flash footprint. It is recommended to read the first one first, as it gives brief summaries of the API, before and discusses supported parts and particularly common issues relating to addressable LEDs, both specific to these parts and in general (including specific hazards that they can expose the user to if used improperly.
|
||||
* [Summary and changes specific to tinyNeoPixel_Static](https://github.com/SpenceKonde/DxCore/blob/master/megaavr/extras/tinyNeoPixel.md) - both normal and static versions use the same documentation.
|
||||
* [Full class reference from Adafruit](https://adafruit.github.io/Adafruit_NeoPixel/html/class_adafruit___neo_pixel.html)
|
||||
|
||||
In the event that a function listed in that class reference is not defined in tinyNeoPixel, or in the event of differences in behavior between adafruitNeoPixel and tinyNeoPixel (except as noted in the first documentation link above), that is a bug, and is likely unknown to the maintainer of megaTinyCore - please report it via github issue (preferred) or by emailing SpenceKonde@gmail.com
|
||||
|
||||
## Licensing
|
||||
**tinyNeoPixel is LGPL 3 not LGPL 2.1**
|
||||
It is derived from Adafruit's adafruitNeoPixel library, which is licenced under LGPL 3.
|
||||
See [LICENSE.md for the library](LICENSE.md)
|
||||
|
||||
The rest of this core (except where noted) is LGPL 2.1.
|
||||
|
||||
This distinction is rarely relevant, but consult with a legal professional if in doubt.
|
||||
@@ -0,0 +1,186 @@
|
||||
// This is a demonstration on how to use an input device to trigger changes on your neo pixels.
|
||||
// You should wire a momentary push button to connect from ground to a digital IO pin. When you
|
||||
// press the button it will change to a new pixel animation. Note that you need to press the
|
||||
// button once to start the first animation!
|
||||
|
||||
#include <tinyNeoPixel_Static.h>
|
||||
|
||||
#define BUTTON_PIN PIN_PA2 // Digital IO pin connected to the button. This will be
|
||||
// driven with a pull-up resistor so the switch should
|
||||
// pull the pin to ground momentarily. On a high -> low
|
||||
// transition the button press logic will execute.
|
||||
// These pins were chosen because they are present on all parts; this sketch is used for automated testing.
|
||||
// Since 8-pin parts with UPDI enabled have only 5 available IO pins (PA1, 2, 3, 6, and 7), and PA3 is the
|
||||
// external clock pin (we detect and give an error when using external clock source if you try to use the
|
||||
// clock pin for anything else, since that doesn't work). Serial in turn is on either PA6/7 or PA1/2 (alt) so unless we
|
||||
// want to make life hard on people modifying the sketch and maybe adding serial debug logging, PA1 and PA2 are the best
|
||||
// choices for the pin in this sketch as an example and automated testing sketch.
|
||||
|
||||
|
||||
#define PIXEL_PIN PIN_PA1 // Digital IO pin connected to the NeoPixels
|
||||
|
||||
#define PIXEL_COUNT 16
|
||||
|
||||
|
||||
// Since this is for the static version of the library, we need to supply the pixel array
|
||||
// This saves space by eliminating use of malloc() and free(), and makes the RAM used for
|
||||
// the frame buffer show up when the sketch is compiled.
|
||||
|
||||
byte pixels[PIXEL_COUNT * 3];
|
||||
// It is strongly recommended to have one variable or #define for the number of pixels, and then
|
||||
// multiply that by 3 (for RGB) or 4 (for RGBW) when declaring the pixel array, as is done here
|
||||
// to avoid the need for double-entry bookkeeping.
|
||||
|
||||
|
||||
// Parameter 1 = number of pixels in strip,
|
||||
// Parameter 2 = pin number (most are valid)
|
||||
// Parameter 3 = color order (NEO_RGB, NEO_GRB, etc).
|
||||
// Parameter 4 = pixel buffer declared above
|
||||
// Unlike the Adafruit library there's no 400 kHz option. I don't think I have ever seen 400 kHz pixels, and they may no longer be made.
|
||||
// Because the optimizer's hands are tied when working with classes it would impose undue burdens on all users to support it, plus it would
|
||||
// need the asm routines adapted to every supported clock speed... all for the sake of a part that seems extinct in the wild.
|
||||
|
||||
tinyNeoPixel strip = tinyNeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB, pixels);
|
||||
|
||||
bool oldState = HIGH;
|
||||
int showType = 0;
|
||||
|
||||
void setup() {
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
pinMode(PIXEL_PIN, OUTPUT);
|
||||
// strip.begin();
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Get current button state.
|
||||
bool newState = digitalRead(BUTTON_PIN);
|
||||
|
||||
// Check if state changed from high to low (button press).
|
||||
if (newState == LOW && oldState == HIGH) {
|
||||
// Short delay to debounce button.
|
||||
delay(20);
|
||||
// Check if button is still low after debounce.
|
||||
newState = digitalRead(BUTTON_PIN);
|
||||
if (newState == LOW) {
|
||||
showType++;
|
||||
if (showType > 9) {
|
||||
showType = 0;
|
||||
}
|
||||
startShow(showType);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the last button state to the old state.
|
||||
oldState = newState;
|
||||
}
|
||||
|
||||
void startShow(int i) {
|
||||
switch (i) {
|
||||
case 0: colorWipe(strip.Color(0, 0, 0), 50); // Black/off
|
||||
break;
|
||||
case 1: colorWipe(strip.Color(255, 0, 0), 50); // Red
|
||||
break;
|
||||
case 2: colorWipe(strip.Color(0, 255, 0), 50); // Green
|
||||
break;
|
||||
case 3: colorWipe(strip.Color(0, 0, 255), 50); // Blue
|
||||
break;
|
||||
case 4: theaterChase(strip.Color(127, 127, 127), 50); // White
|
||||
break;
|
||||
case 5: theaterChase(strip.Color(127, 0, 0), 50); // Red
|
||||
break;
|
||||
case 6: theaterChase(strip.Color(0, 0, 127), 50); // Blue
|
||||
break;
|
||||
case 7: rainbow(20);
|
||||
break;
|
||||
case 8: rainbowCycle(20);
|
||||
break;
|
||||
case 9: theaterChaseRainbow(50);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Fill the dots one after the other with a color
|
||||
void colorWipe(uint32_t c, uint8_t wait) {
|
||||
for (uint16_t i = 0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, c);
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
}
|
||||
|
||||
void rainbow(uint8_t wait) {
|
||||
uint16_t i, j;
|
||||
|
||||
for (j = 0; j < 256; j++) {
|
||||
for (i = 0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, Wheel((i + j) & 255));
|
||||
}
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
}
|
||||
|
||||
// Slightly different, this makes the rainbow equally distributed throughout
|
||||
void rainbowCycle(uint8_t wait) {
|
||||
uint16_t i, j;
|
||||
|
||||
for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
|
||||
for (i = 0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
|
||||
}
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
}
|
||||
|
||||
// Theatre-style crawling lights.
|
||||
void theaterChase(uint32_t c, uint8_t wait) {
|
||||
for (int j = 0; j < 10; j++) { // do 10 cycles of chasing
|
||||
for (int q = 0; q < 3; q++) {
|
||||
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
|
||||
strip.setPixelColor(i + q, c); // turn every third pixel on
|
||||
}
|
||||
strip.show();
|
||||
|
||||
delay(wait);
|
||||
|
||||
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
|
||||
strip.setPixelColor(i + q, 0); // turn every third pixel off
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Theatre-style crawling lights with rainbow effect
|
||||
void theaterChaseRainbow(uint8_t wait) {
|
||||
for (int j = 0; j < 256; j++) { // cycle all 256 colors in the wheel
|
||||
for (int q = 0; q < 3; q++) {
|
||||
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
|
||||
strip.setPixelColor(i + q, Wheel((i + j) % 255)); // turn every third pixel on
|
||||
}
|
||||
strip.show();
|
||||
|
||||
delay(wait);
|
||||
|
||||
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
|
||||
strip.setPixelColor(i + q, 0); // turn every third pixel off
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Input a value 0 to 255 to get a color value.
|
||||
// The colours are a transition r - g - b - back to r.
|
||||
uint32_t Wheel(byte WheelPos) {
|
||||
WheelPos = 255 - WheelPos;
|
||||
if (WheelPos < 85) {
|
||||
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||
}
|
||||
if (WheelPos < 170) {
|
||||
WheelPos -= 85;
|
||||
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||
}
|
||||
WheelPos -= 170;
|
||||
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// NeoPixel simple sketch (c) 2013 Shae Erisson, adapted to tinyNeoPixel library by Spence Konde 2019.
|
||||
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
|
||||
|
||||
#include <tinyNeoPixel_Static.h>
|
||||
|
||||
|
||||
// Which pin on the Arduino is connected to the NeoPixels?
|
||||
#define PIN 3
|
||||
|
||||
// How many NeoPixels are attached to the Arduino?
|
||||
#define NUMPIXELS 16
|
||||
|
||||
// Since this is for the static version of the library, we need to supply the pixel array
|
||||
// This saves space by eliminating use of malloc() and free(), and makes the RAM used for
|
||||
// the frame buffer show up when the sketch is compiled.
|
||||
|
||||
byte pixels[NUMPIXELS * 3];
|
||||
|
||||
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
|
||||
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
|
||||
// example for more information on possible values.
|
||||
|
||||
tinyNeoPixel leds = tinyNeoPixel(NUMPIXELS, PIN, NEO_GRB, pixels);
|
||||
|
||||
int delayval = 500; // delay for half a second
|
||||
|
||||
void setup() {
|
||||
pinMode(PIN, OUTPUT);
|
||||
// with tinyNeoPixel_Static, you need to set pinMode yourself. This means you can eliminate pinMode()
|
||||
// and replace with direct port writes to save a couple hundred bytes in sketch size (note that this
|
||||
// savings is only present when you eliminate *all* references to pinMode).
|
||||
// leds.begin() not needed on tinyNeoPixel
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
|
||||
|
||||
for (int i = 0; i < NUMPIXELS; i++) {
|
||||
|
||||
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
|
||||
leds.setPixelColor(i, leds.Color(0, 150, 0)); // Moderately bright green color.
|
||||
|
||||
leds.show(); // This sends the updated pixel color to the hardware.
|
||||
|
||||
delay(delayval); // Delay for a period of time (in milliseconds).
|
||||
}
|
||||
// with tinyNeoPixel_Static, since we have the pixel array, we can also directly manipulate it - this sacrifices the correction for the pixel order, and the clarity of setColor to save a tiny amount of flash and time.
|
||||
for (int i = 0; i < (NUMPIXELS * 3); i++) {
|
||||
pixels[i] = 150; // set byte i of array (this is channel (i%3) of led (i/3) (respectively, i%4 and i/4 for RGBW leds)
|
||||
leds.show(); // show
|
||||
delay(delayval); // delay for a period of time
|
||||
pixels[i] = 0; // turn off the above pixel
|
||||
// result is that each pixel will cycle through each of the primary colors (green, red, blue for most LEDs) in turn, and only one LED will be on at a time.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
#include <tinyNeoPixel_Static.h>
|
||||
|
||||
#define PIN 3
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = Arduino pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
// Parameter 4 = array to store pixel data in
|
||||
|
||||
#define NUMPIXELS 60
|
||||
|
||||
// Since this is for the static version of the library, we need to supply the pixel array
|
||||
// This saves space by eliminating use of malloc() and free(), and makes the RAM used for
|
||||
// the frame buffer show up when the sketch is compiled.
|
||||
|
||||
byte pixels[NUMPIXELS * 3];
|
||||
|
||||
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
|
||||
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
|
||||
// example for more information on possible values. Finally, for the 4th argument we pass the array we
|
||||
// defined above.
|
||||
|
||||
tinyNeoPixel strip = tinyNeoPixel(NUMPIXELS, PIN, NEO_GRB, pixels);
|
||||
|
||||
// IMPORTANT: 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 Arduino and first pixel. Avoid connecting
|
||||
// on a live circuit...if you must, connect GND first.
|
||||
|
||||
void setup() {
|
||||
pinMode(PIN, OUTPUT); // set pin output - this is not done internally by the library for Static version of library
|
||||
// strip.begin(); // Static version does not use this.
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Some example procedures showing how to display to the pixels:
|
||||
colorWipe(strip.Color(255, 0, 0), 50); // Red
|
||||
colorWipe(strip.Color(0, 255, 0), 50); // Green
|
||||
colorWipe(strip.Color(0, 0, 255), 50); // Blue
|
||||
// Send a theater pixel chase in...
|
||||
theaterChase(strip.Color(127, 127, 127), 50); // White
|
||||
theaterChase(strip.Color(127, 0, 0), 50); // Red
|
||||
theaterChase(strip.Color(0, 0, 127), 50); // Blue
|
||||
|
||||
rainbow(20);
|
||||
rainbowCycle(20);
|
||||
theaterChaseRainbow(50);
|
||||
}
|
||||
|
||||
// Fill the dots one after the other with a color
|
||||
void colorWipe(uint32_t c, uint8_t wait) {
|
||||
for (uint16_t i = 0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, c);
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
}
|
||||
|
||||
void rainbow(uint8_t wait) {
|
||||
uint16_t i, j;
|
||||
|
||||
for (j = 0; j < 256; j++) {
|
||||
for (i = 0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, Wheel((i + j) & 255));
|
||||
}
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
}
|
||||
|
||||
// Slightly different, this makes the rainbow equally distributed throughout
|
||||
void rainbowCycle(uint8_t wait) {
|
||||
uint16_t i, j;
|
||||
|
||||
for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
|
||||
for (i = 0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
|
||||
}
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
}
|
||||
|
||||
// Theatre-style crawling lights.
|
||||
void theaterChase(uint32_t c, uint8_t wait) {
|
||||
for (int j = 0; j < 10; j++) { // do 10 cycles of chasing
|
||||
for (int q = 0; q < 3; q++) {
|
||||
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
|
||||
strip.setPixelColor(i + q, c); // turn every third pixel on
|
||||
}
|
||||
strip.show();
|
||||
|
||||
delay(wait);
|
||||
|
||||
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
|
||||
strip.setPixelColor(i + q, 0); // turn every third pixel off
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Theatre-style crawling lights with rainbow effect
|
||||
void theaterChaseRainbow(uint8_t wait) {
|
||||
for (int j = 0; j < 256; j++) { // cycle all 256 colors in the wheel
|
||||
for (int q = 0; q < 3; q++) {
|
||||
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
|
||||
strip.setPixelColor(i + q, Wheel((i + j) % 255)); // turn every third pixel on
|
||||
}
|
||||
strip.show();
|
||||
|
||||
delay(wait);
|
||||
|
||||
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
|
||||
strip.setPixelColor(i + q, 0); // turn every third pixel off
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Input a value 0 to 255 to get a color value.
|
||||
// The colours are a transition r - g - b - back to r.
|
||||
uint32_t Wheel(byte WheelPos) {
|
||||
WheelPos = 255 - WheelPos;
|
||||
if (WheelPos < 85) {
|
||||
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||
}
|
||||
if (WheelPos < 170) {
|
||||
WheelPos -= 85;
|
||||
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||
}
|
||||
WheelPos -= 170;
|
||||
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For tinyNeopixel_Static
|
||||
#######################################
|
||||
# Class
|
||||
#######################################
|
||||
|
||||
tinyNeoPixel KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions
|
||||
#######################################
|
||||
|
||||
setPixelColor KEYWORD2
|
||||
getPixelColor KEYWORD2
|
||||
setPin KEYWORD2
|
||||
getPin KEYWORD2
|
||||
setBrightness KEYWORD2
|
||||
getBrightness KEYWORD2
|
||||
numPixels KEYWORD2
|
||||
getPixels KEYWORD2
|
||||
show KEYWORD2
|
||||
clear KEYWORD2
|
||||
fill KEYWORD2
|
||||
Color KEYWORD2
|
||||
ColorHSV KEYWORD2
|
||||
gamma8 KEYWORD2
|
||||
sine8 KEYWORD2
|
||||
gamma32 KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants
|
||||
#######################################
|
||||
|
||||
NEO_GRB LITERAL1
|
||||
NEO_RGB LITERAL1
|
||||
NEO_RBG LITERAL1
|
||||
NEO_GRB LITERAL1
|
||||
NEO_GBR LITERAL1
|
||||
NEO_BRG LITERAL1
|
||||
NEO_BGR LITERAL1
|
||||
NEO_WRGB LITERAL1
|
||||
NEO_WRBG LITERAL1
|
||||
NEO_WGRB LITERAL1
|
||||
NEO_WGBR LITERAL1
|
||||
NEO_WBRG LITERAL1
|
||||
NEO_WBGR LITERAL1
|
||||
NEO_RWGB LITERAL1
|
||||
NEO_RWBG LITERAL1
|
||||
NEO_RGWB LITERAL1
|
||||
NEO_RGBW LITERAL1
|
||||
NEO_RBWG LITERAL1
|
||||
NEO_RBGW LITERAL1
|
||||
NEO_GWRB LITERAL1
|
||||
NEO_GWBR LITERAL1
|
||||
NEO_GRWB LITERAL1
|
||||
NEO_GRBW LITERAL1
|
||||
NEO_GBWR LITERAL1
|
||||
NEO_GBRW LITERAL1
|
||||
NEO_BWRG LITERAL1
|
||||
NEO_BWGR LITERAL1
|
||||
NEO_BRWG LITERAL1
|
||||
NEO_BRGW LITERAL1
|
||||
NEO_BGWR LITERAL1
|
||||
NEO_BGRW LITERAL1
|
||||
@@ -0,0 +1,9 @@
|
||||
name=tinyNeoPixel Static
|
||||
version=2.0.7
|
||||
author=Adafruit (modified by Spence Konde)
|
||||
maintainer=Spence Konde <spencekonde@gmail.com>
|
||||
sentence=Arduino library for controlling single-wire-based LED pixels and strip for all modern (post 2016) AVR microcontrollers, and distributed with megaTinyCore and DxCore.
|
||||
paragraph=This library is closely based on the original Adafruit_NeoPixel library. It has been modified to account for the improved ST performance on the tinyAVR 0-series, tinyAVR 1-series and megaAVR 0-series, and add support for speeds from 4 MHz to 48 MHz. No specific actions to choose the port the port at any speed (enabled by ST improvements). Please refer to the documentation for more information.<br>2.0.7 - Fix critical defect in 10 and 12 MHz implementations which would output the first bit only.<br/> 2.0.6 - correct naming of labels in asm to conform with our naming policy. Add show(number), which will show up to the first (number) leds. This allows the static allocation version to light up a varying number of LEDs. 2.0.5 - correct some timing and compile issues at certain speeds. <br/> 2.0.4 - Add support for operation at speeds as low as 4 MHz. Ensure that the inline assembly is specified correctly. <br/>2.0.3 - Fix issue when millis is disabled.
|
||||
category=Display
|
||||
url=https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/tinyNeoPixel.md
|
||||
architectures=megaavr
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,334 @@
|
||||
/*--------------------------------------------------------------------
|
||||
This file is part of the tinyNeoPixel library, derived from
|
||||
Adafruit_NeoPixel.
|
||||
|
||||
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 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
|
||||
<http://www.gnu.org/licenses/>.
|
||||
--------------------------------------------------------------------*/
|
||||
// *INDENT-OFF* astyle hates this file
|
||||
// *PAD-OFF* and destroys the lookup tables!
|
||||
|
||||
#ifndef TINYNEOPIXEL_H
|
||||
#define TINYNEOPIXEL_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#if (__AVR_ARCH__ < 100)
|
||||
#error "This version of the library only supports AVRxt parts (tinyAVR 0/1/2-series, megaAVR 0-series and the AVR DA/DB/DD parts. For tinyNeoPixel, for classic AVR, get from ATTinyCore package"
|
||||
#endif
|
||||
|
||||
// The order of primary colors in the NeoPixel data stream can vary
|
||||
// among device types, manufacturers and even different revisions of
|
||||
// the same item. The third parameter to the Adafruit_NeoPixel
|
||||
// constructor encodes the per-pixel byte offsets of the red, green
|
||||
// and blue primaries (plus white, if present) in the data stream --
|
||||
// the following #defines provide an easier-to-use named version for
|
||||
// each permutation. e.g. NEO_GRB indicates a NeoPixel-compatible
|
||||
// device expecting three bytes per pixel, with the first byte
|
||||
// containing the green value, second containing red and third
|
||||
// containing blue. The in-memory representation of a chain of
|
||||
// NeoPixels is the same as the data-stream order; no re-ordering of
|
||||
// bytes is required when issuing data to the chain.
|
||||
|
||||
// Bits 5,4 of this value are the offset (0-3) from the first byte of
|
||||
// a pixel to the location of the red color byte. Bits 3,2 are the
|
||||
// green offset and 1,0 are the blue offset. If it is an RGBW-type
|
||||
// device (supporting a white primary in addition to R,G,B), bits 7,6
|
||||
// are the offset to the white byte...otherwise, bits 7,6 are set to
|
||||
// the same value as 5,4 (red) to indicate an RGB (not RGBW) device.
|
||||
// i.e. binary representation:
|
||||
// 0bWWRRGGBB for RGBW devices
|
||||
// 0bRRRRGGBB for RGB
|
||||
|
||||
// RGB NeoPixel permutations; white and red offsets are always same
|
||||
// Offset: W R G B
|
||||
#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2))
|
||||
#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1))
|
||||
#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1))
|
||||
#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0))
|
||||
|
||||
// RGBW NeoPixel permutations; all 4 offsets are distinct
|
||||
// Offset: W R G B
|
||||
#define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3))
|
||||
#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2))
|
||||
#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3))
|
||||
#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2))
|
||||
#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1))
|
||||
#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1))
|
||||
|
||||
#define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3))
|
||||
#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2))
|
||||
#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3))
|
||||
#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2))
|
||||
#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1))
|
||||
#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1))
|
||||
|
||||
#define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3))
|
||||
#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3))
|
||||
#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1))
|
||||
#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1))
|
||||
|
||||
#define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0))
|
||||
#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0))
|
||||
#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0))
|
||||
#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0))
|
||||
|
||||
#define NEO_KHZ800 0x0000 ///< 800 KHz data transmission
|
||||
|
||||
// 400 kHz neopixels are virtually absent from the market today
|
||||
// They are not supported.
|
||||
|
||||
// These two tables are declared outside the Adafruit_NeoPixel class
|
||||
// because some boards may require oldschool compilers that don't
|
||||
// handle the C++11 constexpr keyword.
|
||||
|
||||
/* A pre-calculated 8-bit sine look-up table stored in flash for use
|
||||
with the sine8() function. This is apparently of use in some animation
|
||||
algorithms. If __AVR_ARCH__==103, then all of the flash is memory
|
||||
mapped, and we can simply declare it const, access it like a
|
||||
normal variable, and it won't be copied to RAM.
|
||||
|
||||
AVRxt devices with too much flash for all of it to be mapped
|
||||
which includes the AVR64Dx and AVR128Dx parts. DxCore defines a
|
||||
.section for the area of PROGMEM that is mapped by default, and
|
||||
a PROGMEM_MAPPED macro. A variable declared const PROGMEM_MAPPED can
|
||||
be accessed normally, but will be stored in the flash and not copied to RAM.
|
||||
|
||||
Finally, if neither of those are an option - it gets declared with PROGMEM
|
||||
|
||||
|
||||
Copy & paste this snippet into a Python REPL to regenerate:
|
||||
import math
|
||||
for x in range(256):
|
||||
print("{:3},".format(int((math.sin(x/128.0*math.pi)+1.0)*127.5+0.5))),
|
||||
if x&15 == 15: print
|
||||
*/
|
||||
#if (__AVR_ARCH__==103)
|
||||
// All out flash is mapped - yay!
|
||||
static const uint8_t _NeoPixelSineTable[256] = {
|
||||
#elif defined(PROGMEM_MAPPED)
|
||||
// Some of it is - but we can put stuff there - yay!
|
||||
static const uint8_t PROGMEM_MAPPED _NeoPixelSineTable[256] = {
|
||||
#else
|
||||
// Back to progmem...
|
||||
static const uint8_t PROGMEM _NeoPixelSineTable[256] = {
|
||||
#endif
|
||||
128,131,134,137,140,143,146,149,152,155,158,162,165,167,170,173,
|
||||
176,179,182,185,188,190,193,196,198,201,203,206,208,211,213,215,
|
||||
218,220,222,224,226,228,230,232,234,235,237,238,240,241,243,244,
|
||||
245,246,248,249,250,250,251,252,253,253,254,254,254,255,255,255,
|
||||
255,255,255,255,254,254,254,253,253,252,251,250,250,249,248,246,
|
||||
245,244,243,241,240,238,237,235,234,232,230,228,226,224,222,220,
|
||||
218,215,213,211,208,206,203,201,198,196,193,190,188,185,182,179,
|
||||
176,173,170,167,165,162,158,155,152,149,146,143,140,137,134,131,
|
||||
128,124,121,118,115,112,109,106,103,100, 97, 93, 90, 88, 85, 82,
|
||||
79, 76, 73, 70, 67, 65, 62, 59, 57, 54, 52, 49, 47, 44, 42, 40,
|
||||
37, 35, 33, 31, 29, 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11,
|
||||
10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9,
|
||||
10, 11, 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35,
|
||||
37, 40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76,
|
||||
79, 82, 85, 88, 90, 93, 97,100,103,106,109,112,115,118,121,124};
|
||||
|
||||
/* Similar to above, but for an 8-bit gamma-correction table.
|
||||
Copy & paste this snippet into a Python REPL to regenerate:
|
||||
import math
|
||||
gamma=2.6
|
||||
for x in range(256):
|
||||
print("{:3},".format(int(math.pow((x)/255.0,gamma)*255.0+0.5))),
|
||||
if x&15 == 15: print
|
||||
*/
|
||||
#if (__AVR_ARCH__==103)
|
||||
// All our flash is mapped - yay!
|
||||
static const uint8_t _NeoPixelGammaTable[256] = {
|
||||
#elif defined(PROGMEM_MAPPED)
|
||||
// Some of it is - but we can put stuff there - yay!
|
||||
static const uint8_t PROGMEM_MAPPED _NeoPixelGammaTable[256] = {
|
||||
#else
|
||||
// Back to progmem...
|
||||
static const uint8_t PROGMEM _NeoPixelGammaTable[256] = {
|
||||
#endif
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
|
||||
3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7,
|
||||
7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12,
|
||||
13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20,
|
||||
20, 21, 21, 22, 22, 23, 24, 24, 25, 25, 26, 27, 27, 28, 29, 29,
|
||||
30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42,
|
||||
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
|
||||
58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 72, 73, 75,
|
||||
76, 77, 78, 80, 81, 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96,
|
||||
97, 99,100,102,103,105,106,108,109,111,112,114,115,117,119,120,
|
||||
122,124,125,127,129,130,132,134,136,137,139,141,143,145,146,148,
|
||||
150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,
|
||||
182,184,186,188,191,193,195,197,199,202,204,206,209,211,213,215,
|
||||
218,220,223,225,227,230,232,235,237,240,242,245,247,250,252,255};
|
||||
|
||||
|
||||
typedef uint8_t neoPixelType;
|
||||
|
||||
class tinyNeoPixel {
|
||||
|
||||
public:
|
||||
|
||||
// Constructor: number of LEDs, pin number, LED type
|
||||
tinyNeoPixel(uint16_t n, uint8_t p, neoPixelType t, uint8_t *pxl);
|
||||
~tinyNeoPixel();
|
||||
|
||||
void
|
||||
show(void),
|
||||
#if (PROGMEM_SIZE > 4096UL)
|
||||
show(uint16_t leds),
|
||||
#endif
|
||||
setPin(uint8_t p),
|
||||
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
|
||||
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w),
|
||||
setPixelColor(uint16_t n, uint32_t c),
|
||||
fill(uint32_t c = 0, uint16_t first = 0, uint16_t count = 0),
|
||||
setBrightness(uint8_t b),
|
||||
clear(),
|
||||
updateLatch(uint16_t latchtime = 50);
|
||||
uint8_t
|
||||
*getPixels(void) const,
|
||||
getBrightness(void) const;
|
||||
uint16_t
|
||||
numPixels(void) const;
|
||||
uint32_t
|
||||
getPixelColor(uint16_t n) const;
|
||||
uint8_t getPin(void) { return pin; }
|
||||
void begin(void) {return;}
|
||||
/*!
|
||||
@brief An 8-bit integer sine wave function, not directly compatible
|
||||
with standard trigonometric units like radians or degrees.
|
||||
@param 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.
|
||||
@return Sine result, 0 to 255, or -128 to +127 if type-converted to
|
||||
a signed int8_t, but you'll most likely want unsigned as this
|
||||
output is often used for pixel brightness in animation effects.
|
||||
*/
|
||||
static uint8_t sine8(uint8_t x) { // 0-255 in, 0-255 out
|
||||
#if (__AVR_ARCH__ == 103 || defined(PROGMEM_MAPPED))
|
||||
return _NeoPixelSineTable[x];
|
||||
#else // We had to put it in PROGMEM, and that's how we get it out
|
||||
return pgm_read_byte(&_NeoPixelSineTable[x]); // 0-255 in, 0-255 out
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief An 8-bit gamma-correction function for basic pixel brightness
|
||||
adjustment. Makes color transitions appear more perceptially
|
||||
correct.
|
||||
@param x Input brightness, 0 (minimum or off/black) to 255 (maximum).
|
||||
@return Gamma-adjusted brightness, can then be passed to one of the
|
||||
setPixelColor() functions. This uses a fixed gamma correction
|
||||
exponent of 2.6, which seems reasonably okay for average
|
||||
NeoPixels in average tasks. If you need finer control you'll
|
||||
need to provide your own gamma-correction function instead.
|
||||
*/
|
||||
|
||||
static uint8_t gamma8(uint8_t x) {
|
||||
#if (__AVR_ARCH__ == 103 || defined(PROGMEM_MAPPED))
|
||||
return _NeoPixelGammaTable[x];
|
||||
#else
|
||||
return pgm_read_byte(&_NeoPixelGammaTable[x]);
|
||||
#endif
|
||||
}
|
||||
/*!
|
||||
@brief Convert separate red, green and blue values into a single
|
||||
"packed" 32-bit RGB color.
|
||||
@param r Red brightness, 0 to 255.
|
||||
@param g Green brightness, 0 to 255.
|
||||
@param b Blue brightness, 0 to 255.
|
||||
@return 32-bit packed RGB value, which can then be assigned to a
|
||||
variable for later use or passed to the setPixelColor()
|
||||
function. Packed RGB format is predictable, regardless of
|
||||
LED strand color order.
|
||||
*/
|
||||
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||
}
|
||||
/*!
|
||||
@brief Convert separate red, green, blue and white values into a
|
||||
single "packed" 32-bit WRGB color.
|
||||
@param r Red brightness, 0 to 255.
|
||||
@param g Green brightness, 0 to 255.
|
||||
@param b Blue brightness, 0 to 255.
|
||||
@param w White brightness, 0 to 255.
|
||||
@return 32-bit packed WRGB value, which can then be assigned to a
|
||||
variable for later use or passed to the setPixelColor()
|
||||
function. Packed WRGB format is predictable, regardless of
|
||||
LED strand color order.
|
||||
*/
|
||||
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||
}
|
||||
static uint32_t ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255);
|
||||
/*!
|
||||
@brief A gamma-correction function for 32-bit packed RGB or WRGB
|
||||
colors. Makes color transitions appear more perceptially
|
||||
correct.
|
||||
@param x 32-bit packed RGB or WRGB color.
|
||||
@return Gamma-adjusted packed color, can then be passed in one of the
|
||||
setPixelColor() functions. Like gamma8(), this uses a fixed
|
||||
gamma correction exponent of 2.6, which seems reasonably okay
|
||||
for average NeoPixels in average tasks. If you need finer
|
||||
control you'll need to provide your own gamma-correction
|
||||
function instead.
|
||||
*/
|
||||
static uint32_t gamma32(uint32_t x);
|
||||
|
||||
#if (!defined(MILLIS_USE_TIMERNONE) && !defined(MILLIS_USE_TIMERRTC) && !defined(MILLIS_USE_TIMERRTC_XTAL) && !defined(MILLIS_USE_TIMERRTC_XOSC))
|
||||
inline bool canShow(void) { return (micros() - endTime) >= (uint32_t) latchTime; }
|
||||
#else
|
||||
inline bool canShow(void) {return 1;} // we don't have micros here;
|
||||
#endif
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
uint16_t
|
||||
numLEDs, // Number of RGB LEDs in strip
|
||||
numBytes, // Size of 'pixels' buffer below (3 or 4 bytes/pixel)
|
||||
latchTime; // Latch waiting period in us varies from 6 (contrary
|
||||
// to datasheet) for original 2812's, all the way to 250 us.
|
||||
// 50us is what the originals claim. Clones copied that, and some made it even longer.
|
||||
int8_t
|
||||
pin; // Output pin number (-1 if not yet set)
|
||||
uint8_t
|
||||
brightness,
|
||||
*pixels, // Holds LED color values (3 or 4 bytes each)
|
||||
rOffset, // Index of red byte within each 3- or 4-byte pixel
|
||||
gOffset, // Index of green byte
|
||||
bOffset, // Index of blue byte
|
||||
wOffset; // Index of white byte (same as rOffset if no white)
|
||||
uint32_t
|
||||
endTime; // Latch timing reference
|
||||
volatile uint8_t
|
||||
*port; // Output PORT register
|
||||
uint8_t
|
||||
pinMask; // Output PORT bitmask
|
||||
|
||||
};
|
||||
|
||||
#endif // TINYNEOPIXEL_H
|
||||
Reference in New Issue
Block a user