forked from Makuna/NeoPixelBus
provide better samples and more
two samples now are included improved the readme (changed from txt to md) NEO_RGB doesn;t require 400khz support, and 400khz support by default isn't compiled in
This commit is contained in:
@@ -1,123 +0,0 @@
|
||||
#include <NeoPixelBus.h>
|
||||
|
||||
NeoPixelBus strip = NeoPixelBus(16, 8);
|
||||
uint16_t p = 0;
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
strip.Begin();
|
||||
strip.Show();
|
||||
randomSeed(analogRead(0));
|
||||
Serial.begin(9600);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("next");
|
||||
|
||||
|
||||
|
||||
// LoopAround(192, 200);
|
||||
PickRandom(128);
|
||||
// FadeInFadeOutRinseRepeat(192);
|
||||
|
||||
// start animating
|
||||
strip.StartAnimating();
|
||||
|
||||
// wait until no more animations are running
|
||||
while (strip.IsAnimating())
|
||||
{
|
||||
strip.UpdateAnimations();
|
||||
strip.Show();
|
||||
delay(31); // ~30hz change cycle
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FadeInFadeOutRinseRepeat(uint8_t peak)
|
||||
{
|
||||
if (p == 0)
|
||||
{
|
||||
for (uint8_t pixel = 0; pixel < 16; pixel++)
|
||||
{
|
||||
uint16_t time = random(800,1000);
|
||||
strip.LinearFadePixelColor(time, pixel, RgbColor(random(peak), random(peak), random(peak)));
|
||||
}
|
||||
}
|
||||
else if (p == 1)
|
||||
{
|
||||
for (uint8_t pixel = 0; pixel < 16; pixel++)
|
||||
{
|
||||
uint16_t time = random(600,700);
|
||||
strip.LinearFadePixelColor(time, pixel, RgbColor(0, 0, 0));
|
||||
}
|
||||
}
|
||||
p = (p + 1) % 2; // next procedure and keep within the number of procedures
|
||||
|
||||
}
|
||||
|
||||
void PickRandom(uint8_t peak)
|
||||
{
|
||||
|
||||
// pick random set of pixels to animate
|
||||
uint8_t count = random(16);
|
||||
while (count > 0)
|
||||
{
|
||||
uint8_t pixel = random(16);
|
||||
|
||||
// configure the animations
|
||||
RgbColor color; // = strip.getPixelColor(pixel);
|
||||
|
||||
color = RgbColor(random(peak), random(peak), random(peak));
|
||||
|
||||
|
||||
uint16_t time = random(100,400);
|
||||
strip.LinearFadePixelColor( time, pixel, color);
|
||||
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
void LoopAround(uint8_t peak, uint16_t speed)
|
||||
{
|
||||
// Looping around the ring sample
|
||||
uint16_t prev;
|
||||
RgbColor prevColor;
|
||||
|
||||
// fade previous one dark
|
||||
prev = (p + 11) % 16;
|
||||
strip.LinearFadePixelColor(speed, prev, RgbColor(0, 0, 0));
|
||||
|
||||
// fade previous one dark
|
||||
prev = (p + 12) % 16;
|
||||
prevColor = strip.GetPixelColor( prev );
|
||||
prevColor.Darken(prevColor.CalculateBrightness() / 2);
|
||||
strip.LinearFadePixelColor(speed, prev, prevColor);
|
||||
|
||||
// fade previous one dark
|
||||
prev = (p + 13) % 16;
|
||||
prevColor = strip.GetPixelColor( prev );
|
||||
prevColor.Darken(prevColor.CalculateBrightness() / 2);
|
||||
strip.LinearFadePixelColor(speed, prev, prevColor);
|
||||
|
||||
// fade previous one dark
|
||||
prev = (p + 14) % 16;
|
||||
prevColor = strip.GetPixelColor( prev );
|
||||
prevColor.Darken(prevColor.CalculateBrightness() / 2);
|
||||
strip.LinearFadePixelColor(speed, prev, prevColor);
|
||||
|
||||
// fade previous one dark
|
||||
prev = (p + 15) % 16;
|
||||
prevColor = strip.GetPixelColor( prev );
|
||||
prevColor.Darken(prevColor.CalculateBrightness() / 2);
|
||||
strip.LinearFadePixelColor(speed, prev, prevColor);
|
||||
|
||||
// fade current one light
|
||||
strip.LinearFadePixelColor(speed, p, RgbColor(random(peak), random(peak), random(peak)));
|
||||
p = (p+1) % 16;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
#include <NeoPixelBus.h>
|
||||
|
||||
#define pixelCount 4
|
||||
|
||||
NeoPixelBus strip = NeoPixelBus(pixelCount, 8);
|
||||
uint16_t effectState = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
strip.Begin();
|
||||
strip.Show();
|
||||
SetRandomSeed();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// There are three fun functions that implement different effects
|
||||
// uncomment one at a time and upload to see the effect
|
||||
|
||||
// LoopAround(192, 200); // very interesting on rings of NeoPixels
|
||||
PickRandom(128);
|
||||
// FadeInFadeOutRinseRepeat(192);
|
||||
|
||||
// start animating
|
||||
strip.StartAnimating();
|
||||
|
||||
// wait until no more animations are running
|
||||
while (strip.IsAnimating())
|
||||
{
|
||||
strip.UpdateAnimations();
|
||||
strip.Show();
|
||||
delay(31); // ~30hz change cycle
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FadeInFadeOutRinseRepeat(uint8_t peak)
|
||||
{
|
||||
if (effectState == 0)
|
||||
{
|
||||
for (uint8_t pixel = 0; pixel < pixelCount; pixel++)
|
||||
{
|
||||
uint16_t time = random(800,1000);
|
||||
strip.LinearFadePixelColor(time, pixel, RgbColor(random(peak), random(peak), random(peak)));
|
||||
}
|
||||
}
|
||||
else if (effectState == 1)
|
||||
{
|
||||
for (uint8_t pixel = 0; pixel < pixelCount; pixel++)
|
||||
{
|
||||
uint16_t time = random(600,700);
|
||||
strip.LinearFadePixelColor(time, pixel, RgbColor(0, 0, 0));
|
||||
}
|
||||
}
|
||||
effectState = (effectState + 1) % 2; // next effectState and keep within the number of effectStates
|
||||
|
||||
}
|
||||
|
||||
void PickRandom(uint8_t peak)
|
||||
{
|
||||
|
||||
// pick random set of pixels to animate
|
||||
uint8_t count = random(pixelCount);
|
||||
while (count > 0)
|
||||
{
|
||||
uint8_t pixel = random(pixelCount);
|
||||
|
||||
// configure the animations
|
||||
RgbColor color; // = strip.getPixelColor(pixel);
|
||||
|
||||
color = RgbColor(random(peak), random(peak), random(peak));
|
||||
|
||||
|
||||
uint16_t time = random(100,400);
|
||||
strip.LinearFadePixelColor( time, pixel, color);
|
||||
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
void LoopAround(uint8_t peak, uint16_t speed)
|
||||
{
|
||||
// Looping around the ring sample
|
||||
uint16_t prevPixel;
|
||||
RgbColor prevColor;
|
||||
|
||||
// fade previous one dark
|
||||
prevPixel = (effectState + (pixelCount - 5)) % pixelCount;
|
||||
strip.LinearFadePixelColor(speed, prevPixel, RgbColor(0, 0, 0));
|
||||
|
||||
// fade previous one dark
|
||||
prevPixel = (effectState + (pixelCount - 4)) % pixelCount;
|
||||
prevColor = strip.GetPixelColor( prevPixel );
|
||||
prevColor.Darken(prevColor.CalculateBrightness() / 2);
|
||||
strip.LinearFadePixelColor(speed, prevPixel, prevColor);
|
||||
|
||||
// fade previous one dark
|
||||
prevPixel = (effectState + (pixelCount - 3)) % pixelCount;
|
||||
prevColor = strip.GetPixelColor( prevPixel );
|
||||
prevColor.Darken(prevColor.CalculateBrightness() / 2);
|
||||
strip.LinearFadePixelColor(speed, prevPixel, prevColor);
|
||||
|
||||
// fade previous one dark
|
||||
prevPixel = (effectState + (pixelCount - 2)) % pixelCount;
|
||||
prevColor = strip.GetPixelColor( prevPixel );
|
||||
prevColor.Darken(prevColor.CalculateBrightness() / 2);
|
||||
strip.LinearFadePixelColor(speed, prevPixel, prevColor);
|
||||
|
||||
// fade previous one dark
|
||||
prevPixel = (effectState + (pixelCount - 1)) % pixelCount;
|
||||
prevColor = strip.GetPixelColor( prevPixel );
|
||||
prevColor.Darken(prevColor.CalculateBrightness() / 2);
|
||||
strip.LinearFadePixelColor(speed, prevPixel, prevColor);
|
||||
|
||||
// fade current one light
|
||||
strip.LinearFadePixelColor(speed, effectState, RgbColor(random(peak), random(peak), random(peak)));
|
||||
effectState = (effectState + 1) % pixelCount;
|
||||
}
|
||||
|
||||
void SetRandomSeed()
|
||||
{
|
||||
uint32_t seed;
|
||||
|
||||
// random works best with a seed that can use 31 bits
|
||||
// analogRead on a unconnected pin tends toward less than four bits
|
||||
seed = analogRead(0);
|
||||
delay(1);
|
||||
|
||||
for (int shifts = 3; shifts < 31; shifts += 3)
|
||||
{
|
||||
seed ^= analogRead(0) << shifts;
|
||||
delay(1);
|
||||
}
|
||||
|
||||
// Serial.println(seed);
|
||||
randomSeed(seed);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <NeoPixelBus.h>
|
||||
|
||||
#define pixelCount 4
|
||||
#define colorSaturation 128
|
||||
|
||||
NeoPixelBus strip = NeoPixelBus(pixelCount, 8);
|
||||
|
||||
RgbColor red = RgbColor(colorSaturation, 0, 0);
|
||||
RgbColor green = RgbColor(0, colorSaturation, 0);
|
||||
RgbColor blue = RgbColor(0, 0, colorSaturation);
|
||||
RgbColor white = RgbColor(colorSaturation);
|
||||
RgbColor black = RgbColor(0);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// this resets all the neopixels to an off state
|
||||
strip.Begin();
|
||||
strip.Show();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
// set the colors,
|
||||
// if they don't match in order, you may need to use NEO_GRB flag
|
||||
strip.SetPixelColor(0, red);
|
||||
strip.SetPixelColor(1, green);
|
||||
strip.SetPixelColor(2, blue);
|
||||
strip.SetPixelColor(3, white);
|
||||
strip.Show();
|
||||
|
||||
delay(3000);
|
||||
|
||||
// turn off the pixels
|
||||
strip.SetPixelColor(0, black);
|
||||
strip.SetPixelColor(1, black);
|
||||
strip.SetPixelColor(2, black);
|
||||
strip.SetPixelColor(3, black);
|
||||
strip.Show();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user