#include <Adafruit_NeoPixel.h>
#define PIN 6
#define N_LEDS 36
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
uint32_t greenishwhite = strip.Color(0, 64, 0, 64);
int countColor = 0;
int previous = 0;
const int POT1 = A0;
const int POT2 = A1;
const int POT3 = A2;
const int BUTTON = 7;
int red = 0, green = 0, blue = 0;
int outputRed = 0, outputGreen = 0, outputBlue = 0;
int count = 0;
void setup() {
strip.begin();
pinMode(BUTTON, INPUT_PULLUP);
}
void loop() {
int val = digitalRead(BUTTON);
if (val == 0) {
delay(1000);
count++;
}
if (count > 3) {
count = 0;
}
red = analogRead(POT1);
green = analogRead(POT2);
blue = analogRead(POT3);
outputRed = map(red, 0, 1023, 0, 255);
outputGreen = map(green, 0, 1023, 0, 255);
outputBlue = map(blue, 0, 1023, 0, 255);
if (count == 0) {
uint32_t currentColor = strip.Color(outputRed, outputGreen, outputBlue);
strip.fill(currentColor, 0, 36);
strip.show();
}
if (count == 1) {
Strobe(0xff, 0xff, 0xff, 1, 45, 0);
}
if (count == 2) {
chase(strip.Color(255, 0, 0)); // Red
chase(strip.Color(0, 255, 0)); // Green
chase(strip.Color(0, 0, 255)); // Blue
}
if (count == 3) {
TwinkleRandom(20, 100, false);
}
}
static void chase(uint32_t c) {
for(uint16_t i=0; i<strip.numPixels()+4; i++) {
strip.setPixelColor(i , c);
strip.setPixelColor(i-4, 0);
strip.show();
delay(30);
}
}
void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
for(int j = 0; j < StrobeCount; j++) {
setAll(red,green,blue);
showStrip();
delay(FlashDelay);
setAll(0,0,0);
showStrip();
delay(FlashDelay);
}
delay(EndPause);
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < N_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
void showStrip() {
strip.show();
}
void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
setAll(0,0,0);
for (int i=0; i<Count; i++) {
setPixel(random(N_LEDS),random(0,255),random(0,255),random(0,255));
showStrip();
delay(SpeedDelay);
if(OnlyOne) {
setAll(0,0,0);
}
}
delay(SpeedDelay);
}