# include <Adafruit_NeoPixel.h>
# define LED_PIN 2 //Output pin
# define LED_COUNT 25
int delayval = 10; // 25;// Delay in ticks(1000ticks = 1 sec)
int colorRed = 0;
int colorGreen = 0;
int colorBlue = 0;
int switch_pin = 9;
int switch_state;
int l = 0;
bool interrupted;
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// NEO_GRB means how it will send the color signals, green, red, and finally blue. You may need to change it.
//...
bool myDelay(unsigned long milliseconds)
{
//... uncomment to use real delay
// delay(milliseconds);
// return false;
unsigned long startTime = millis();
while (millis() - startTime <= milliseconds)
if (digitalRead(switch_pin) == LOW)
return true;
return false;
}
void setup() {
Serial.begin(115200);
Serial.println("\nNews, Weather and Sports!\n");
strip.begin(); // Start Strip
strip.show(); // Clears out the colors from the previous program
pinMode(LED_BUILTIN, OUTPUT); // Activates built-in LED to confirm code is working
pinMode(switch_pin, INPUT_PULLUP);
}
void loop() {
static long counter;
Serial.print("loop... ");
Serial.println(counter);
counter++;
switch_state = digitalRead(switch_pin) == HIGH;
Serial.println(" gonna onOff");
onOff();//detects whether switch is on or off and runs on and off animations
Serial.println(" gonna pulse");
pulse();//pulse/breathing animation.
digitalWrite(LED_BUILTIN, HIGH);//test to make sure the board is running correctly
}
void onOff() {
if (!switch_state) {//if switch is off lights activate in a down pattern
for (l=LED_COUNT; l >= 0; l--) {
//... colorRed = 0;
strip.setPixelColor(l, strip.Color(0, 0, 0));
strip.show();
delay(17);
}
}
else {
for (l=0; l < LED_COUNT; l++) {//if switch is on lights activate in an up pattern
colorRed = 255;
strip.setPixelColor(l, strip.Color(colorRed, 0, 0));// Set color RGB
strip.show();// This makes the color actually appear.
delay(17);
}
}
}
void pulse() {
if (switch_state != LOW) {
for (colorRed=255; colorRed > 5; colorRed -=1) {// brings red value from 255 down gradually to 5
for (int i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, colorRed, colorGreen, colorBlue);
}
strip.show();
if (myDelay(delayval)) return;
}
for (colorRed=5; colorRed < 255; colorRed +=1) {//brings red value from 5 up gradually to 255
for (int i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, colorRed, colorGreen, colorBlue);
}
strip.show();
if (myDelay(delayval)) return;
}
}
}