Tasmota/lib/lib_basic/NeoPixelBus-2.6.1.4/examples/NeoPixelBrightness/NeoPixelBrightness.ino
Jason2866 0e0275cf43
Patch 2 (#173)
* ili9341 update

* update ili9341

* Update support_tasmota.ino

* fix scripter bug

* Deep+

* Update ILI9341_2.cpp

Fix invert display

* Update xdsp_04_ili9341.ino

Fix display modes

* fix ili9341 m5stack

* Refactor DHT negative temps

* Standardize on unconnected pin being -1

* Back to chain+

* Strict

* strict

* Update platformio_tasmota32.ini

* Fix renderer

* Change NeoPixelBus library from v2.6.0 to v2.6.1.4

* display batch

* Update xdrv_13_display.ino

* ldf strict

Co-authored-by: gemu2015 <gmutz2010@googlemail.com>
Co-authored-by: Theo Arends <11044339+arendst@users.noreply.github.com>
2021-02-14 16:04:03 +01:00

84 lines
2.1 KiB
C++

// NeoPixelBrightness
// This example will cycle brightness from high to low of
// three pixels colored Red, Green, Blue.
// This demonstrates the use of the NeoPixelBrightnessBus
// with integrated brightness support
//
// There is serial output of the current state so you can
// confirm and follow along
//
#include <NeoPixelBrightnessBus.h> // instead of NeoPixelBus.h
const uint16_t PixelCount = 3; // this example assumes 3 pixels, making it smaller will cause a failure
const uint8_t PixelPin = 14; // make sure to set this to the correct pin, ignored for Esp8266
#define colorSaturation 255 // saturation of color constants
RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation);
// Make sure to provide the correct color order feature
// for your NeoPixels
NeoPixelBrightnessBus<NeoRgbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// you loose the original color the lower the dim value used
// here due to quantization
const uint8_t c_MinBrightness = 8;
const uint8_t c_MaxBrightness = 255;
int8_t direction; // current direction of dimming
void setup()
{
Serial.begin(115200);
while (!Serial); // wait for serial attach
Serial.println();
Serial.println("Initializing...");
Serial.flush();
// this resets all the neopixels to an off state
strip.Begin();
strip.Show();
direction = -1; // default to dim first
Serial.println();
Serial.println("Running...");
// set our three original colors
strip.SetPixelColor(0, red);
strip.SetPixelColor(1, green);
strip.SetPixelColor(2, blue);
strip.Show();
}
void loop()
{
uint8_t brightness = strip.GetBrightness();
Serial.println(brightness);
delay(100);
// swap diection of dim when limits are reached
//
if (direction < 0 && brightness <= c_MinBrightness)
{
direction = 1;
}
else if (direction > 0 && brightness >= c_MaxBrightness)
{
direction = -1;
}
// apply dimming
brightness += direction;
strip.SetBrightness(brightness);
// show the results
strip.Show();
}