/*
WWA NeoPixel strip using ColorConverter
This sketch uses the Adafruit NeoPixel library to drive a strip of
WS2812 warm white-cool white-amber (WWA) LEDs
and the ColorConverter library to do warm-to-cool conversion.
A potentimeter on A0 fades the strip from warm to cool.
created 11 Feb 2019
by Tom Igoe
*/
// #include <Adafruit_NeoPixel.h>
// #include <ColorConverter.h>
// const int neoPixelPin = 5;
// const int pixelCount = 20; // number of pixels
// // set up strip. Note BRG setting. You might have to experiment
// // to determine which way your LEDs are wired:
// Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, neoPixelPin, NEO_BRG + NEO_KHZ800);
// ColorConverter converter;
// int h = 10; // hue
// int s = 100; // saturation
// int i = 100; // intensity
// void setup() {
// Serial.begin(9600);
// strip.begin(); // initialize pixel strip
// strip.clear(); // turn all LEDs off
// strip.show(); // update strip knob.write(0);
// }
// void loop() {
// int sensorReading = analogRead(A0);
// // map the result from 0 - 240
// // (not 360, because you want warm to cool, not
// // warm to cool and back:
// int mix = map(sensorReading, 0, 1023, 0, 240);
// // create a single color from hue, sat, intensity:
// RGBColor color = converter.HSItoRGB(mix, s, i);
// // change the ColorConverter labels to something you can use:
// int amber = color.red;
// int warm = color.green;
// int cool = color.blue;
// // loop over all the pixels:
// for (int pixel = 0; pixel < pixelCount; pixel++) {
// // set the color for this pixel:
// strip.setPixelColor(pixel, amber, warm, cool);
// }
// // update the strip
// strip.show();
// }
// /*
// Simple NeoPixel control
// This sketch allows serial control over RGBW NeoPixels. It shows how to control
// them using a single long integer, written as a hexadecimal string, like
// web colors, (e.g. 00FF0000 is red)
// Uses Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
// created 28 Oct 2017
// updated 7 Jun 2021
// by Tom Igoe
// */
// #include <Adafruit_NeoPixel.h>
// const int neoPixelPin = 5; // control pin
// const int pixelCount = 7; // number of pixels
// // set up strip:
// Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, neoPixelPin, NEO_GRBW + NEO_KHZ800);
// void setup() {
// Serial.begin(9600);
// Serial.setTimeout(10);
// strip.begin(); // initialize pixel strip
// strip.clear(); // turn all LEDs off
// strip.show(); // Initialize all pixels
// }
// unsigned long color = 0x0000FF00;
// void loop() {
// /*
// Each byte of the color is a hue, in the sequence WWRRGGBB.
// 0xFF000000 is white
// 0x00FF0000 is red
// 0x0000FF00 is green
// 0x000000FF is blue
// Other colors are made by combining, e.g.
// 0x000077FF is teal
// 0x003300FF is violet
// */
// // print the color in hex so you know what you're seeing:
// Serial.println(color, HEX);
// // loop over all the pixels:
// for (int pixel = 0; pixel < pixelCount; pixel++) {
// strip.setPixelColor(pixel, color);// set the color for this pixel
// }
// strip.show(); // refresh the strip
// delay(1000);
// if (color >= 0xFF000000) {
// color = 0xFF;
// } else {
// color = color << 8;
// }
// }
// /*
// Simple NeoPixel control
// This sketch allows serial control over RGBW NeoPixels.
// Uses Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
// created 28 March 2016
// updated 28 Jun 2018
// by Tom Igoe
// */
// #include <Adafruit_NeoPixel.h>
// const int neoPixelPin = 5; // control pin
// const int pixelCount = 7; // number of pixels
// // set up strip:
// Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, neoPixelPin, NEO_GRBW + NEO_KHZ800);
// void setup() {
// strip.begin(); // initialize pixel strip
// strip.clear(); // turn all LEDs off
// }
// void loop() {
// byte red = 23; // set colors
// byte green = 0;
// byte blue = 255;
// byte white = 0;
// // loop over all the pixels:
// for (int pixel = 0; pixel < pixelCount; pixel++) {
// strip.setPixelColor(pixel, red, green, blue, white);// set the color for this pixel
// delay(250);
// strip.show(); // refresh the strip
// }
// delay(1000);
// strip.clear();
// }
// /*
// NeoPixel HSV control with Adafruit NeoPixel Library
// This sketch shows how to convert a hue, saturation, and value range
// to a single color value for controlling RGBW neopixels. Doesn't work on
// RGB addressable LEDs.
// Uses Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
// created 7 Jun 2021
// modified 31 Jan 2023
// by Tom Igoe
// */
// #include <Adafruit_NeoPixel.h>
// const int neoPixelPin = 5; // control pin
// const int pixelCount = 7; // number of pixels
// unsigned long hue = 18000;
// unsigned long color = 0;
// int sat = 255;
// int val = 255;
// int hChange = 10;
// // set up strip:
// Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, neoPixelPin, NEO_GRBW + NEO_KHZ800);
// void setup() {
// Serial.begin(9600);
// Serial.setTimeout(10);
// strip.begin(); // initialize pixel strip
// strip.clear(); // turn all LEDs off
// strip.show(); // Initialize all pixels
// }
// void loop() {
// // hue fades through the color spectrum, starting from red.
// Serial.print(hue);
// Serial.print(",");
// Serial.print(sat);
// Serial.print(",");
// Serial.print(val);
// Serial.print("\t");
// Serial.println(color, HEX);
// // loop over all the pixels:
// for (int pixel = 0; pixel < pixelCount; pixel++) {
// color = strip.ColorHSV(hue, sat, val);
// strip.setPixelColor(pixel, color);// set the color for this pixel
// }
// strip.show(); // refresh the strip
// hue += hChange;
// // keep it in a range from blue to green:
// if (hue > 32767 || hue < 18000) {
// hChange = -hChange;
// }
// // add 10 to the hue and delay a little bit:
// if (hue > 32767) {
// hue = 18000;
// } else {
// hue += 10;
// }
// delay(5);
// }
// /*
// NeoPixel gamma32 control with Adafruit NeoPixel Library
// This sketch shows how to use the gamma32 command to color correct
// a color. Doesn't work on RGB addressable LEDs, only RGBW.
// Uses Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
// created 7 Jun 2021
// by Tom Igoe
// */
// #include <Adafruit_NeoPixel.h>
// const int neoPixelPin = 5; // control pin
// const int pixelCount = 7; // number of pixels
// // set up strip:
// Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, neoPixelPin, NEO_GRBW + NEO_KHZ800);
// void setup() {
// Serial.begin(9600);
// Serial.setTimeout(10);
// strip.begin(); // initialize pixel strip
// strip.clear(); // turn all LEDs off
// strip.show(); // Initialize all pixels
// }
// void loop() {
// // put in any color here:
// unsigned long color = 0x7FFF0000;
// unsigned long corrected = strip.gamma32(color);
// // loop over all the pixels:
// for (int pixel = 0; pixel < pixelCount; pixel++) {
// strip.setPixelColor(pixel, color);// set the color for this pixel
// }
// Serial.print("color: ");
// Serial.println(color, HEX);
// strip.show(); // refresh the strip
// delay(3000);
// // loop over all the pixels:
// for (int pixel = 0; pixel < pixelCount; pixel++) {
// strip.setPixelColor(pixel, corrected);// set the color for this pixel
// }
// Serial.print("gamma32 corrected: ");
// Serial.println(corrected, HEX);
// strip.show(); // refresh the strip
// delay(3000);
// }
// /*
// NeoPixel RGB key color fade
// This sketch fades the RGB of a neoPixel device from one key color to another.
// Uses Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
// Uses Interval library: https://github.com/tigoe/Interval
// created 31 Jan 2017
// modified 29 Oct 2017
// by Tom Igoe
// */
// #include <Adafruit_NeoPixel.h>
// const int neoPixelPin = 5;
// const int pixelCount = 7;
// Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, neoPixelPin, NEO_GRBW + NEO_KHZ800);
// // changing range of keyframe colors for the pixels to flicker to:
// unsigned long keyColors[] = {0xCB500F, 0xB4410C, 0x95230C, 0x853E0B};
// unsigned long targetColor[pixelCount]; // next target for each pixel
// unsigned long pixelColor[pixelCount]; // current color for each pixel
// // count of keyframe colors:
// int numColors = sizeof(keyColors) / 4;
// int interval = 30;
// int lastFlicker = 0;
// void setup() {
// strip.begin(); // initialize pixel strip
// strip.clear(); // turn off pixel
// strip.show(); // refresh the strip
// }
// void loop() {
// if (millis() - lastFlicker > interval) {
// flickerPixels();
// lastFlicker = millis();
// }
// // update the strip:
// strip.show();
// }
// /*
// this function creates the flicker effect:
// */
// void flickerPixels() {
// // iterate over all pixels:
// for (int thisPixel = 0; thisPixel < pixelCount; thisPixel++) {
// // if the target color matches the current color for this pixel,
// // then pick a new target color randomly:
// if (targetColor[thisPixel] == pixelColor[thisPixel]) {
// int nextColor = random(numColors);
// targetColor[thisPixel] = keyColors[nextColor];
// }
// // fade the pixel one step from the current color to the target color:
// pixelColor[thisPixel] = compare(pixelColor[thisPixel], targetColor[thisPixel]);
// // set the pixel color in the strip:
// strip.setPixelColor(thisPixel, pixelColor[thisPixel]);// set the color for this pixel
// }
// }
// /*
// takes two colors and returns a color that's a point on each axis (r, g, b)
// closer to the target color
// */
// unsigned long compare(unsigned long thisColor, unsigned long thatColor) {
// // separate the first color:
// byte r = thisColor >> 16;
// byte g = thisColor >> 8;
// byte b = thisColor;
// // separate the second color:
// byte targetR = thatColor >> 16;
// byte targetG = thatColor >> 8;
// byte targetB = thatColor;
// // fade the first color toward the second color:
// if (r > targetR) r--;
// if (g > targetG) g--;
// if (b > targetB) b--;
// if (r < targetR) r++;
// if (g < targetG) g++;
// if (b < targetB) b++;
// // combine the values to get the new color:
// unsigned long result = ((unsigned long)r << 16) | ((unsigned long)g << 8) | b;
// return result;
// }
// /*
// This sketch makes neoPixels chase, with a fading trail.
// The trail changes directions with the chasing pixel.
// created 28 March 2016
// modified 31 Jan 2023
// by Tom Igoe
// */
// #include <Adafruit_NeoPixel.h>
// const int neoPixelPin = 5; // control pin
// const int pixelCount = 128; // number of pixels
// const int trailLength = pixelCount/10; // length of the fading trail
// // set up strip:
// Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, neoPixelPin, NEO_GRBW + NEO_KHZ800);
// unsigned long trailColor[pixelCount]; // array of colors for the trail
// int currentPixel = 0; // the current pixel
// int trailingPixel = pixelCount; // the final trailing pixel
// int trailDirection = 1; // direction of the trail
// void setup() {
// // set the trail colors:
// Serial.begin(9600);
// if (!Serial) delay(3000);
// for (int p = 0; p < trailLength; p++) {
// trailColor[p] = (p * 255) / 8 ;
// Serial.println(trailColor[p]);
// }
// Serial.println(" " );
// for (int p = 9; p < 12; p++) {
// trailColor[p] = 255 / (p -8);
// Serial.println(trailColor[p]);
// }
// Serial.println(" " );
// // fill the rest with zeroes:
// for (int p = 12; p < pixelCount; p++) {
// trailColor[p] = 0;
// // Serial.println(trailColor[p]);
// }
// //while (true);
// strip.begin(); // initialize pixel strip
// strip.clear(); // turn off pixels
// strip.show(); // refresh the strip
// }
// void loop() {
// // increment the current pixel number:
// currentPixel += trailDirection;
// // if the current pixel is at either end of the strip,
// // reverse the direction of counting:
// if (currentPixel < 0 || currentPixel >= pixelCount) {
// trailDirection = -trailDirection;
// }
// // set the current pixel:
// strip.setPixelColor(currentPixel, trailColor[currentPixel]);
// // copy the current pixel number for setting the trail:
// trailingPixel = currentPixel;
// // while the trailing pixel number is still in range:
// while (trailingPixel < pixelCount && trailingPixel >= 0) {
// // color number is the distance from current pixel in either direction:
// int colorNum = abs(currentPixel - trailingPixel);
// // set the color:
// strip.setPixelColor(trailingPixel, trailColor[colorNum]);
// // move to the next trailing pixel:
// trailingPixel -= trailDirection;
// }
// // update the strip:
// strip.show();
// // delay 0.1 seconds:
// delay(100);
// }
// /*
// Brightness
// This sketch shows how to use setBrightness() with neoPixels
// Uses Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
// created 28 March 2016
// by Tom Igoe
#include <Adafruit_NeoPixel.h>
const int pinNumber = 9; // Pin number of the DIN line to the neoPixels
const int pixelCount = 7; // number of pixels
// declare the strip of pixels:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, pinNumber, NEO_RGBW + NEO_KHZ800);
void setup() {
strip.begin(); // initialize pixel strip
strip.show(); // Initialize all pixels to 'off'
// turn on all the pixels first:
for (int pixel = 0; pixel < pixelCount; pixel++) {
strip.setPixelColor(pixel, 0x1500CC);
}
strip.show();
}
void loop() {
// loop from brightest to dimmest:
for (int brightness = 255; brightness >= 0; brightness--) {
for (int pixel = 0; pixel < pixelCount; pixel++) {
strip.setBrightness(brightness); // set the brightness
// brightness just acts as a limit on whatever color you set, so
// you still have to set color for all the pixels, but you'll get
// a dimmed version of the color you set:
// loop over all the pixels, turn on one at a time:
strip.setPixelColor(pixel, 0x1500CC);
}
strip.show(); // refresh the strip
delay(10); // wait a hundredth of a second
}
delay(1000);
}