5 #include <ESP8266WiFi.h>
7 #include <Adafruit_NeoPixel.h>
12 * TO CONFIGURE YOUR SSID AND TIME ZONE, EDIT CONFIG.H
18 static uint16_t hue = 0; // 0-359
19 uint8_t saturation = 100; // 0-100
20 uint8_t lightness = 50; // 0-100
22 unsigned int HColor = 0;
23 unsigned int MColor = 0;
24 unsigned int SColor = 0;
26 unsigned int Hour1 = 0;
27 unsigned int Hour2 = 0;
28 unsigned int Minute1 = 0;
29 unsigned int Minute2 = 0;
30 unsigned int Second1 = 0;
31 unsigned int Second2 = 0;
34 NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
35 Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
38 //const int dataPin = 13; //Outputs the byte to transfer
39 //const int loadPin = 11; //3 //Controls the internal transference of data in SN74HC595 internal registers
40 //const int clockPin = 12; // 4//Generates the clock signal to control the transference of data
43 //const int dataPin = 14; //Outputs the byte to transfer
44 //const int loadPin = 0; //3 //Controls the internal transference of data in SN74HC595 internal registers
45 //const int clockPin = 4; // 4//Generates the clock signal to control the transference of data
48 const int dataPin = 14; //D5 //Outputs the byte to transfer
49 const int loadPin = 0; //D3 //3 //Controls the internal transference of data in SN74HC595 internal registers
50 const int clockPin = 4; //D2 // 4//Generates the clock signal to control the transference of data
69 MColor = HColor + COLOR_OFFSET;
70 SColor = MColor + COLOR_OFFSET;
72 pinMode(dataPin, OUTPUT);
73 pinMode(loadPin, OUTPUT);
74 pinMode(clockPin, OUTPUT);
75 digitalWrite(loadPin, 0);
76 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
77 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
78 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
79 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
80 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
81 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
82 digitalWrite(loadPin, 1);
84 WiFi.begin(ssid, password);
87 while ( WiFi.status() != WL_CONNECTED ) {
89 digitalWrite(loadPin, 0);
90 shiftOut(dataPin, clockPin, LSBFIRST, digits[i]); //right
91 shiftOut(dataPin, clockPin, LSBFIRST, digits[b]); //left
92 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
93 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
94 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
95 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
96 digitalWrite(loadPin, 1);
103 digitalWrite(loadPin, 0);
104 shiftOut(dataPin, clockPin, LSBFIRST, 0b00000001); //right
105 shiftOut(dataPin, clockPin, LSBFIRST, 0b00001011); //right
106 shiftOut(dataPin, clockPin, LSBFIRST, 0b00111010); //00111111
107 shiftOut(dataPin, clockPin, LSBFIRST, 0b00001010); //right
108 shiftOut(dataPin, clockPin, LSBFIRST, 0b00001010); //right
109 shiftOut(dataPin, clockPin, LSBFIRST, 0b10011110); //left
110 digitalWrite(loadPin, 1);
117 strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
118 strip.show(); // Turn OFF all pixels ASAP
119 strip.setBrightness(25); // Set BRIGHTNESS to about 1/5 (max = 255)
124 for (unsigned int j=0; j<5; j++) {
125 for (unsigned int i=0; i<8; i++) {
126 digitalWrite(loadPin, 0);
128 shiftOut(dataPin, clockPin, LSBFIRST, disp); //right
129 shiftOut(dataPin, clockPin, LSBFIRST, disp); //left
130 digitalWrite(loadPin, 1);
138 for (unsigned int i=0; i<20; i++) {
139 digitalWrite(loadPin, 0);
140 shiftOut(dataPin, clockPin, LSBFIRST, digits[random(0,9)]); //right
141 shiftOut(dataPin, clockPin, LSBFIRST, digits[random(0,9)]); //left
142 shiftOut(dataPin, clockPin, LSBFIRST, digits[random(0,9)]); //left
143 shiftOut(dataPin, clockPin, LSBFIRST, digits[random(0,9)]); //left
144 shiftOut(dataPin, clockPin, LSBFIRST, digits[random(0,9)]); //left
145 shiftOut(dataPin, clockPin, LSBFIRST, digits[random(0,9)]); //left
146 digitalWrite(loadPin, 1);
152 * Map HSL color space to RGB
154 * Totally borrowed from:
155 * http://www.niwa.nu/2013/05/math-behind-colorspace-conversions-rgb-hsl/
157 * Probably not the most efficient solution, but
158 * it get's the job done.
160 uint32_t hsl(uint16_t ih, uint8_t is, uint8_t il) {
162 float h, s, l, t1, t2, tr, tg, tb;
165 h = (ih % 360) / 360.0;
166 s = constrain(is, 0, 100) / 100.0;
167 l = constrain(il, 0, 100) / 100.0;
171 return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
174 if ( l < 0.5 ) t1 = l * (1.0 + s);
175 else t1 = l + s - l * s;
182 r = hsl_convert(tr, t1, t2);
183 g = hsl_convert(tg, t1, t2);
184 b = hsl_convert(tb, t1, t2);
186 // NeoPixel packed RGB color
187 return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
193 uint8_t hsl_convert(float c, float t1, float t2) {
196 else if ( c > 1 ) c-=1;
198 if ( 6 * c < 1 ) c = t2 + ( t1 - t2 ) * 6 * c;
199 else if ( 2 * c < 1 ) c = t1;
200 else if ( 3 * c < 2 ) c = t2 + ( t1 - t2 ) * ( 2/3.0 - c ) * 6;
203 return (uint8_t)(c*255);
210 unsigned int Hour = timeClient.getHours();
211 unsigned int Minute = timeClient.getMinutes();
212 unsigned int Seconds = timeClient.getSeconds();
214 digitalWrite(loadPin, 0);
215 shiftOut(dataPin, clockPin, LSBFIRST, 0b000000000000000000000000000000000000000000000000);
216 digitalWrite(loadPin, 1);
221 Hour1 = (Hour/10U) % 10;
222 Hour2 = (Hour/1U) % 10;
223 Minute1 = (Minute/10U) % 10;
224 Minute2 = (Minute/1U) % 10;
225 Second1 = (Seconds/10U) % 10;
226 Second2 = (Seconds/1U) % 10;
227 unsigned int pause = 1000;
229 strip.setPixelColor(0, hsl(HColor, saturation, lightness));
230 strip.setPixelColor(1, hsl(HColor, saturation, lightness));
231 strip.setPixelColor(2, hsl(MColor, saturation, lightness));
232 strip.setPixelColor(3, hsl(MColor, saturation, lightness));
233 strip.setPixelColor(4, hsl(SColor, saturation, lightness));
234 strip.setPixelColor(5, hsl(SColor, saturation, lightness));
236 HColor = (HColor + 1) % 360;
237 MColor = (MColor + 1) % 360;
238 SColor = (SColor + 1) % 360;
251 digitalWrite(loadPin, 0);
253 shiftOut(dataPin, clockPin, LSBFIRST, digits[Second2]); //right
254 shiftOut(dataPin, clockPin, LSBFIRST, digits[Second1]); //left
255 shiftOut(dataPin, clockPin, LSBFIRST, digits[Minute2]); //right
256 shiftOut(dataPin, clockPin, LSBFIRST, digits[Minute1]); //left
257 shiftOut(dataPin, clockPin, LSBFIRST, digits[Hour2]); //right
258 shiftOut(dataPin, clockPin, LSBFIRST, digits[Hour1]); //left
259 digitalWrite(loadPin, 1);