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)
126 for (unsigned int j=0; j<5; j++) {
127 for (unsigned int i=0; i<8; i++) {
128 digitalWrite(loadPin, 0);
130 shiftOut(dataPin, clockPin, LSBFIRST, disp); //right
131 shiftOut(dataPin, clockPin, LSBFIRST, disp); //left
132 digitalWrite(loadPin, 1);
140 for (unsigned int i=0; i<20; i++) {
141 digitalWrite(loadPin, 0);
142 shiftOut(dataPin, clockPin, LSBFIRST, digits[random(0,9)]); //right
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 shiftOut(dataPin, clockPin, LSBFIRST, digits[random(0,9)]); //left
147 shiftOut(dataPin, clockPin, LSBFIRST, digits[random(0,9)]); //left
148 digitalWrite(loadPin, 1);
154 * Map HSL color space to RGB
156 * Totally borrowed from:
157 * http://www.niwa.nu/2013/05/math-behind-colorspace-conversions-rgb-hsl/
159 * Probably not the most efficient solution, but
160 * it get's the job done.
162 uint32_t hsl(uint16_t ih, uint8_t is, uint8_t il) {
164 float h, s, l, t1, t2, tr, tg, tb;
167 h = (ih % 360) / 360.0;
168 s = constrain(is, 0, 100) / 100.0;
169 l = constrain(il, 0, 100) / 100.0;
173 return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
176 if ( l < 0.5 ) t1 = l * (1.0 + s);
177 else t1 = l + s - l * s;
184 r = hsl_convert(tr, t1, t2);
185 g = hsl_convert(tg, t1, t2);
186 b = hsl_convert(tb, t1, t2);
188 // NeoPixel packed RGB color
189 return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
195 uint8_t hsl_convert(float c, float t1, float t2) {
198 else if ( c > 1 ) c-=1;
200 if ( 6 * c < 1 ) c = t2 + ( t1 - t2 ) * 6 * c;
201 else if ( 2 * c < 1 ) c = t1;
202 else if ( 3 * c < 2 ) c = t2 + ( t1 - t2 ) * ( 2/3.0 - c ) * 6;
205 return (uint8_t)(c*255);
212 unsigned int Hour = timeClient.getHours();
213 unsigned int Minute = timeClient.getMinutes();
214 unsigned int Seconds = timeClient.getSeconds();
216 digitalWrite(loadPin, 0);
217 shiftOut(dataPin, clockPin, LSBFIRST, 0b000000000000000000000000000000000000000000000000);
218 digitalWrite(loadPin, 1);
223 Hour1 = (Hour/10U) % 10;
224 Hour2 = (Hour/1U) % 10;
225 Minute1 = (Minute/10U) % 10;
226 Minute2 = (Minute/1U) % 10;
227 Second1 = (Seconds/10U) % 10;
228 Second2 = (Seconds/1U) % 10;
229 unsigned int pause = 1000;
231 strip.setPixelColor(0, hsl(HColor, saturation, lightness));
233 strip.setPixelColor(1, hsl(HColor, saturation, lightness));
235 strip.setPixelColor(2, hsl(MColor, saturation, lightness));
237 strip.setPixelColor(3, hsl(MColor, saturation, lightness));
239 strip.setPixelColor(4, hsl(SColor, saturation, lightness));
241 strip.setPixelColor(5, hsl(SColor, saturation, lightness));
244 HColor = (HColor + 1) % 360;
245 MColor = (MColor + 1) % 360;
246 SColor = (SColor + 1) % 360;
259 digitalWrite(loadPin, 0);
261 shiftOut(dataPin, clockPin, LSBFIRST, digits[Second2]); //right
262 shiftOut(dataPin, clockPin, LSBFIRST, digits[Second1]); //left
263 shiftOut(dataPin, clockPin, LSBFIRST, digits[Minute2]); //right
264 shiftOut(dataPin, clockPin, LSBFIRST, digits[Minute1]); //left
265 shiftOut(dataPin, clockPin, LSBFIRST, digits[Hour2]); //right
266 shiftOut(dataPin, clockPin, LSBFIRST, digits[Hour1]); //left
267 digitalWrite(loadPin, 1);