#include <Adafruit_NeoPixel.h>
// change these values to match your board.
#define BUTTON_LEAD 4
#define LED_LEAD 6
#define NUMBER_OF_PIXELS 28
#define NUMBER_OF_MODES 20
#define NUM_LEDS 28
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMBER_OF_PIXELS, LED_LEAD, NEO_GRB + NEO_KHZ800);
bool buttonState = LOW;
bool lastButtonState = LOW;
// The following constant is the delay between each pixel flash. It is used in all three modes, therefore, all modes
// flash at the same rate.
// If you need different flash rates, then declare different constants and use those in each mode function. Or let me know and
// I'll do it for you.
//const int PIXEL_FLASH_INTERVAL = 30;
uint8_t bpm = 30;
unsigned long previousMillis = millis();
int mode = 0; // Default mode is one.
byte colors[3][3] = { {0xff, 0, 0}, //red
{0, 0xff, 0}, //green
{0 , 0 , 0xff} }; //blue
void setup() {
pinMode(BUTTON_LEAD, INPUT_PULLUP);
strip.begin();
strip.show();
}
int pos = 0, dir = 1; // Position, direction of "eye"
void loop() {
switch (mode) {
case 0:
colorWipe(strip.Color(0, 0, 0));
break;
case 1:
theaterChase(strip.Color(255, 0, 0), 50); // Red
theaterChase(strip.Color(0, 0, 255), 50); // Blue
break;
//case 1:
//colorWipe(strip.Color(255, 255, 255)); //fehér
//break;
case 2:
colorWipe(strip.Color(0, 0, 255)); //kék
break;
case 3:
colorWipe(strip.Color(0, 255, 0)); //zöld
break;
case 4:
colorWipe(strip.Color(255, 0, 0)); //piros
break;
case 5:
colorWipe(strip.Color(255, 0, 0));
colorWipe(strip.Color(255, 255, 255));
colorWipe(strip.Color(0, 255, 0)); //piros-fehér-zöld forgó
colorWipe(strip.Color(0, 0, 0));
break;
case 6:
colorWipe(strip.Color(random(255), random(255), random(255))); //random szín forgó
break;
case 7:
BouncingColoredBalls(3, colors); //3 pattogó labda
break;
case 8:
scanner(); //Piros 5 Kocsis
break;
case 9:
scanner2(); //Kék 5 Kocsis
break;
case 10:
rainbowCycle(10); //Úszó Szivárvány (kissebb szám = nagyobb sebesség)
break;
case 11:
theaterChaseRainbow(25); //villogva futó szín átváltás
break;
case 12:
rainbow(15); //szín át úszás gyors
break;
case 13:
rainbow(50); //szín át úszás lassú
break;
case 14:
rainbowStrip(); //Piros Fehér Zöld futófény
break;
case 15:
theaterChase(strip.Color(255, 0, 0), 10); // Red
theaterChase(strip.Color(0, 0, 255), 10); // Blue //Gyors piros kék villogás
//Strobe(0xff, 0xff, 0xff, 20, 40, 10);
break;
case 16:
FadeInOut(0xff, 0x00, 0x00);
FadeInOut(0x00, 0x00, 0xff); //Lassú piros kék fade in-out
break;
case 17:
//middleFill(strip.Color(random(255), random(255), random(255)), 20);
middleFill(strip.Color(0, 0, 255), 100); //középről kétfelé szét kék
break;
case 18:
//sideFill(strip.Color(random(255), random(255), random(255)), 20);
sideFill(strip.Color(0, 0, 255), 100); //két széléről középre össze kék
break;
case 19:
Strobe(0xff, 0xff, 0xff, 20, 40, 10);
break;
case 20:
Strobe(0xff, 0x00, 0x00, 10, 40, 0);
Strobe(0x00, 0x00, 0xff, 10, 40, 0);
Strobe(0xff, 0x00, 0x00, 10, 40, 0);
Strobe(0x00, 0x00, 0xff, 10, 40, 0);
Strobe(0xff, 0xff, 0xff, 10, 40, 0);
break;
default:
mode = 0;
break;
}
}
/* colorWipe function */
void colorWipe(uint32_t color) {
uint32_t i = 0;
while (i < strip.numPixels()) {
if (millis() - previousMillis >= 30) {
previousMillis = millis();
i++;
}
strip.setPixelColor(i, color);
strip.show();
if (buttonListener()) {
break;
}
}
}
//SAJÁT
void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) {
setAll(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(NUM_LEDS-i-j, red, green, blue);
}
setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
showStrip();
if(buttonListener()) { return; }
delay(SpeedDelay);
}
delay(ReturnDelay);
}
void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) {
setAll(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(NUM_LEDS-i-j, red, green, blue);
}
setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
showStrip();
if(buttonListener()) { return; }
delay(SpeedDelay);
}
delay(ReturnDelay);
}
void middleFill(uint32_t c, uint8_t wait) {
// clearStrip();
delay(wait);
for(uint16_t i=0; i<(strip.numPixels()/2); i++) { // start from the middle, lighting an LED on each side
strip.setPixelColor(strip.numPixels()/2 + i, c);
strip.setPixelColor(strip.numPixels()/2 - i, c);
strip.show();
delay(wait);
}
strip.setPixelColor(0, c);
strip.show();
delay(wait);
for(uint16_t i=0; i<(strip.numPixels()/2); i++) { // reverse
strip.setPixelColor(i, strip.Color(0, 0, 0));
strip.setPixelColor(strip.numPixels() - i, strip.Color(0, 0, 0));
strip.show();
if(buttonListener()) { return; }
delay(wait);
}
showStrip();
}
// Light up the strip starting from the sides
void sideFill(uint32_t c, uint8_t wait) {
showStrip();
delay(wait);
for(uint16_t i=0; i<(strip.numPixels()/2); i++) { // fill strip from sides to middle
strip.setPixelColor(i, c);
strip.setPixelColor(strip.numPixels() - i, c);
strip.show();
delay(wait);
}
strip.setPixelColor(strip.numPixels()/2, c);
strip.show();
delay(wait);
for(uint16_t i=0; i<(strip.numPixels()/2); i++) { // reverse
strip.setPixelColor(strip.numPixels()/2 + i, strip.Color(0, 0, 0));
strip.setPixelColor(strip.numPixels()/2 - i, strip.Color(0, 0, 0));
strip.show();
if(buttonListener()) { return; }
delay(wait);
}
showStrip();
}
void RGBLoop(){
for(int j = 0; j < 3; j++ ) {
// Fade IN
for(int k = 0; k < 256; k++) {
switch(j) {
case 0: setAll(k,0,0); break;
case 1: setAll(0,k,0); break;
case 2: setAll(0,0,k); break;
}
showStrip();
delay(3);
}
// Fade OUT
for(int k = 255; k >= 0; k--) {
switch(j) {
case 0: setAll(k,0,0); break;
case 1: setAll(0,k,0); break;
case 2: setAll(0,0,k); break;
}
showStrip();
if(buttonListener()) { return; }
delay(3);
}
}
}
void FadeInOut(byte red, byte green, byte blue){
float r, g, b;
for(int k = 0; k < 256; k=k+1) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
if(buttonListener()) { return; }
showStrip();
}
for(int k = 255; k >= 0; k=k-2) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
if(buttonListener()) { return; }
showStrip();
}
}
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);
if(buttonListener()) { return; }
}
void rainbowStrip() {
int i = 0;
while(i<NUM_LEDS*4) {
strip.setPixelColor((i+1)%NUM_LEDS, strip.Color(0, 0, 0));
strip.setPixelColor((i+9)%NUM_LEDS, strip.Color(255, 0, 0));
strip.setPixelColor((i+18)%NUM_LEDS, strip.Color(255, 255, 255));
strip.setPixelColor((i+27)%NUM_LEDS, strip.Color(0, 255, 0));
strip.setPixelColor((i+1)%NUM_LEDS, strip.Color(0, 0, 0));
//strip.setPixelColor(i%NUM_LEDS, strip.Color(255, 255, 255)); //change RGB color value here
//strip.setPixelColor((i+1)%NUM_LEDS, strip.Color(255, 5, 180)); //change RGB color value here
//strip.setPixelColor((i+2)%NUM_LEDS, strip.Color(255, 0, 0)); //change RGB color value here
//strip.setPixelColor((i+3)%NUM_LEDS, strip.Color(255, 150, 0)); //change RGB color value here
//strip.setPixelColor((i+4)%NUM_LEDS, strip.Color(255, 255, 5)); //change RGB color value here
//strip.setPixelColor((i+5)%NUM_LEDS, strip.Color(0, 255, 0)); //change RGB color value here
//strip.setPixelColor((i+6)%NUM_LEDS, strip.Color(0, 0, 255)); //change RGB color value here
//strip.setPixelColor((i+7)%NUM_LEDS, strip.Color(135, 10, 215)); //change RGB color value here
//strip.setPixelColor((i+8)%NUM_LEDS, strip.Color(255, 255, 255)); //change RGB color value here
//strip.setPixelColor((i+9)%NUM_LEDS, strip.Color(255, 5, 180)); //change RGB color value here
//strip.setPixelColor((i+10)%NUM_LEDS, strip.Color(255, 0, 0)); //change RGB color value here
//strip.setPixelColor((i+11)%NUM_LEDS, strip.Color(255, 150, 0)); //change RGB color value here
//strip.setPixelColor((i+12)%NUM_LEDS, strip.Color(255, 255, 5)); //change RGB color value here
//strip.setPixelColor((i+13)%NUM_LEDS, strip.Color(0, 255, 0)); //change RGB color value here
//strip.setPixelColor((i+14)%NUM_LEDS, strip.Color(0, 0, 255)); //change RGB color value here
//strip.setPixelColor((i+15)%NUM_LEDS, strip.Color(135, 10, 215)); //change RGB color value here
//strip.setPixelColor((i+16)%NUM_LEDS, strip.Color(255, 255, 255)); //change RGB color value here
//strip.setPixelColor((i+17)%NUM_LEDS, strip.Color(255, 5, 180)); //change RGB color value here
//strip.setPixelColor((i+18)%NUM_LEDS, strip.Color(255, 0, 0)); //change RGB color value here
//strip.setPixelColor((i+19)%NUM_LEDS, strip.Color(255, 150, 0)); //change RGB color value here
//strip.setPixelColor((i+20)%NUM_LEDS, strip.Color(255, 255, 5)); //change RGB color value here
//strip.setPixelColor((i+21)%NUM_LEDS, strip.Color(0, 255, 0)); //change RGB color value here
//strip.setPixelColor((i+22)%NUM_LEDS, strip.Color(0, 0, 255)); //change RGB color value here
//strip.setPixelColor((i+23)%NUM_LEDS, strip.Color(135, 10, 215)); //change RGB color value here
//strip.setPixelColor((i+24)%NUM_LEDS, strip.Color(255, 255, 255)); //change RGB color value here
//strip.setPixelColor((i+25)%NUM_LEDS, strip.Color(255, 5, 180)); //change RGB color value here
//strip.setPixelColor((i+26)%NUM_LEDS, strip.Color(255, 0, 0)); //change RGB color value here
//strip.setPixelColor((i+27)%NUM_LEDS, strip.Color(255, 150, 0)); //change RGB color value here
//strip.setPixelColor((i+28)%NUM_LEDS, strip.Color(255, 255, 5)); //change RGB color value here
//strip.setPixelColor((i+29)%NUM_LEDS, strip.Color(0, 255, 0)); //change RGB color value here
i++;
strip.show();
if(buttonListener()) { return; }
delay(120);
}
}
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 (int i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, c); //turn every third pixel on
}
strip.show();
if(buttonListener()) { return; }
delay(wait);
for (int i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0); //turn every third pixel off
}
}
}
}
void theaterChaseRainbow(uint8_t wait) {
for (int j = 0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q = 0; q < 5; q++) {
for (int i = 0; i < strip.numPixels(); i = i + 5) {
strip.setPixelColor(i + q, Wheel( (i + j) % 255)); //turn every third pixel on
}
strip.show();
if(buttonListener()) { return; }
delay(wait);
for (int i = 0; i < strip.numPixels(); i = i + 2) {
strip.setPixelColor(i + q, 0); //turn every third pixel off
}
}
}
}
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();
if(buttonListener()) { return; }
delay(wait);
}
}
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();
if(buttonListener()) { return; }
delay(wait);
}
}
//SAJÁT VÉGE
/* Wheel function */
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);
}
/* monitor button press */
bool buttonListener() {
bool modeChanged = false;
buttonState = digitalRead(BUTTON_LEAD);
if (buttonState != lastButtonState) {
if (buttonState == LOW) {
mode++;
modeChanged = true;
delay(250); // Debounce delay. I checked the best parameter and 250 was it.
}
}
lastButtonState = buttonState;
return modeChanged;
}
void scanner() {
if (millis() - previousMillis >= 60) { //Sebesség Kissebb=gyorsabb
previousMillis = millis();
if(buttonListener()) { return; }
int j;
// Draw 3 pixels centered on pos. setPixelColor() will clip any
// pixels off the ends of the strip, we don't need to watch for that.
strip.setPixelColor(pos - 4, 0x730000);
strip.setPixelColor(pos - 3, 0x7D0000);
strip.setPixelColor(pos - 2, 0x870000);
strip.setPixelColor(pos - 1, 0xBF0000); // Medium red
strip.setPixelColor(pos , 0xff0000); // Center pixel is brightest
strip.setPixelColor(pos + 1, 0xBF0000); // Medium red
strip.setPixelColor(pos + 2, 0x870000);
strip.setPixelColor(pos + 3, 0x7D0000);
strip.setPixelColor(pos + 4, 0x730000);
strip.show();
//delay(60);
// Rather than being sneaky and erasing just the tail pixel,
// it's easier to erase it all and draw a new one next time.
for(j=-4; j<= 4; j++) strip.setPixelColor(pos+j, 0);
// Bounce off ends of strip
pos += dir;
if(pos < 0) {
pos = 1;
dir = -dir;
} else if(pos >= strip.numPixels()) {
pos = strip.numPixels() - 4;
dir = -dir;
}
}
}
void scanner2() {
if (millis() - previousMillis >= 40) { //Sebesség Kissebb=gyorsabb
previousMillis = millis();
if(buttonListener()) { return; }
int j;
// Draw 5 pixels centered on pos. setPixelColor() will clip any
// pixels off the ends of the strip, we don't need to watch for that.
strip.setPixelColor(pos - 4, 0x000073);
strip.setPixelColor(pos - 3, 0x000073);
strip.setPixelColor(pos - 2, 0x000087);
strip.setPixelColor(pos - 1, 0x0000d9); // Blue
strip.setPixelColor(pos , 0x0000ff); // Center pixel Blue
strip.setPixelColor(pos + 1, 0x0000d9); // Blue
strip.setPixelColor(pos + 2, 0x000087);
strip.setPixelColor(pos + 3, 0x000073);
strip.setPixelColor(pos + 4, 0x000073);
strip.show();
//delay(60);
// Rather than being sneaky and erasing just the tail pixel,
// it's easier to erase it all and draw a new one next time.
for(j=-4; j<= 4; j++) strip.setPixelColor(pos+j, 0);
// Bounce off ends of strip
pos += dir;
if(pos < 0) {
pos = 1;
dir = -dir;
}
else if(pos >= strip.numPixels()) {
pos = strip.numPixels() - 4;
dir = -dir;
}
}
}
void BouncingColoredBalls(int BallCount, byte colors[][3]) {
float Gravity = -9.81;
int StartHeight = 1;
float Height[BallCount];
float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
float ImpactVelocity[BallCount];
float TimeSinceLastBounce[BallCount];
int Position[BallCount];
long ClockTimeSinceLastBounce[BallCount];
float Dampening[BallCount];
for (int i = 0 ; i < BallCount ; i++) {
ClockTimeSinceLastBounce[i] = millis();
Height[i] = StartHeight;
Position[i] = 0;
ImpactVelocity[i] = ImpactVelocityStart;
TimeSinceLastBounce[i] = 0;
Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
}
while (true) {
for (int i = 0 ; i < BallCount ; i++) {
TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
if ( Height[i] < 0 ) {
Height[i] = 0;
ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
ClockTimeSinceLastBounce[i] = millis();
if ( ImpactVelocity[i] < 0.01 ) {
ImpactVelocity[i] = ImpactVelocityStart;
}
}
Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
}
for (int i = 0 ; i < BallCount ; i++) {
setPixel(Position[i],colors[i][0],colors[i][1],colors[i][2]);
}
if(buttonListener()) { return; }
showStrip();
setAll(0,0,0);
}
}
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}