123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
/*
Under Door Lighting Sketch by PerfectPixel, 2016. Code edited from examples on Tweaking4all.com.
Library provided by Adafruit.
Tweaking4all: http://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
Adafruit: https://www.adafruit.com/
PerfectPixel: http://www.instructables.com/member/perfectpixel
all code is public domain.
*/
#include <Adafruit_NeoPixel.h>
#define PIN 9
#define NUM_LEDS 27
int BUTTON1_A = 11;
int BUTTON1_B = 12;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(BUTTON1_A, OUTPUT);
pinMode(BUTTON1_B, INPUT);
digitalWrite(BUTTON1_A, HIGH);
strip.begin();
strip.show();
}
void loop(){
while(digitalRead(BUTTON1_B) == LOW){ //Effects while the door is open
switch(random(11)){ //change these effects to suit your preferences!
case 1:
CylonBounce(0, 255, 150, 7, 35, 100);
break;
case 2:
rainbowCycle(5);
break;
case 3:
RunningLights(0,0,255, 50);
break;
case 4:
CylonBounce(255, 100, 0, 7, 35, 100);
break;
case 5:
RunningLights(255,0,0, 50);
break;
case 6:
rainbowCycle(2);
break;
case 7:
CylonBounce(100, 100, 100, 3, 35, 100);
break;
case 8:
RunningLights(0,255,0, 50);
break;
case 9:
rainbowCycle(6);
break;
case 10:
rainbowCycle(10);
break;
}
}
while(digitalRead(BUTTON1_B) == HIGH){ //Effects while the door is closed
setAll(0,0,0);
}
}
/*
*
*
*
*
*
------------------ */
void CylonBounce(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);
showStrip();
delay(SpeedDelay);
}
delay(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);
showStrip();
delay(SpeedDelay);
}
delay(ReturnDelay);
}
void rainbowCycle(int SpeedDelay) {
byte *c;
uint16_t i, j;
for(j=0; j<256*2; j++) {
for(i=0; i< NUM_LEDS; i++) {
c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
setPixel(i, *c, *(c+1), *(c+2));
}
showStrip();
delay(SpeedDelay);
}
}
byte * Wheel(byte WheelPos) {
static byte c[3];
if(WheelPos < 85) {
c[0]=WheelPos * 3;
c[1]=255 - WheelPos * 3;
c[2]=0;
} else if(WheelPos < 170) {
WheelPos -= 85;
c[0]=255 - WheelPos * 3;
c[1]=0;
c[2]=WheelPos * 3;
} else {
WheelPos -= 170;
c[0]=0;
c[1]=WheelPos * 3;
c[2]=255 - WheelPos * 3;
}
return c;
}
void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
int Position=0;
for(int i=0; i<NUM_LEDS*2; i++)
{
Position++; // = 0; //Position + Rate;
for(int i=0; i<NUM_LEDS; i++) {
// sine wave, 3 offset waves make a rainbow!
//float level = sin(i+Position) * 127 + 128;
//setPixel(i,level,0,0);
//float level = sin(i+Position) * 127 + 128;
setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
((sin(i+Position) * 127 + 128)/255)*green,
((sin(i+Position) * 127 + 128)/255)*blue);
}
showStrip();
delay(WaveDelay);
}
}
/* ---------------------
*
*
*
*
*/
void showStrip() {
strip.show();
}
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 < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}