Practicing Arduino

After following tutorials on Arduino I started to understand some basic jargon for coding. For my lights, I would want them to read the location they were in, then adapt the brightness and color of the lights to match the sunset and sunrise time. I found this code online which has brought me one step closer to achieving this.

#include <Adafruit_NeoPixel.h>
#define N_Pixels 8 //number of pixels in strand is 8
#define LED_PIN 2 //NeoPixel strand is connected to this pin
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_Pixels, LED_PIN, NEO_GRB + NEO_KHZ800);
int wait = 40;//balance this number with faderate to regulate speed of fade
int faderate = 400;//higher number here for smoother fades
void setup()
{
strip.begin();
strip.setBrightness(200);//change how bright here
strip.show();

}
void loop()
{
// specify how long you’d like to sleep here
int hours = 0;
int minutes = 2;
int seconds = 20;

sleeping(hours, minutes, seconds);

//start out off, fade up to first color orange (255, 80, 0)
for (int i = 0; i < faderate; i++)
{
int r = map(i, 0, faderate, 0, 255);//fade up the value of red
int g = map(i, 0, faderate, 0, 80); //fade up the value of green
colorWipe (strip.Color(r, g, 0),0);
strip.show();
delay (wait);
}
delay (10000);
colorWipe(strip.Color(0, 0, 0), 0);
}
void sleeping(int hours, int minutes, int seconds) {
int delayTime = (seconds * 1000) + (minutes * 60000) + (hours * 3600000);
delay(delayTime);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}

I want to play around and see if i can adapt this to fade into differnt colours over a specific amount of time, I found the schedule of the sunrise today which I can use as a test.

00:00 – 05:03 = Night
05:03 – 05:42 = Astronomical twilight (1:18) (RGB 102,81,80)
05:42 – 06:20 = Nautical twilight (1:17) (RGB 226,130,80)
06:20 – 06:53 = Civil twilight (1:07) (RGB 228,157,75)
06:54 – 07:30 = Golden Hour (0:36) (RGB 235,196,105)
07:30-17:55 = Daylight (10:25)  (RGB 244,233,125)

 

Added int b = map(i, 0, faderate, 0, 80); //fade up the value of blue

colorWipe (strip.Color(r, g, b, 0),0);

to add blue colour

View at Medium.com

View at Medium.com

%d bloggers like this: