-
Notifications
You must be signed in to change notification settings - Fork 0
/
Neopix60easy.ino
300 lines (251 loc) · 7.6 KB
/
Neopix60easy.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
This is my sketch for a NEO PIXEL ring LED clock.
*/
// Includes below:
#include <Wire.h>
#include <stdio.h>
#include <Adafruit_NeoPixel.h>
#include <RTClib.h>
RTC_DS1307 RTC; // Create RTC object
// Define things here and set things up.
#define LED_Loop 60
#define PIN 6 // This is defining which Arduino pin is driving the Pixel ring used pin 6 but any digital will work
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_Loop, PIN, NEO_GRB + NEO_KHZ800);
int LED[LED_Loop];
int THREE = (LED_Loop / 4);
int SIX = (THREE * 2);
int NINE = (THREE * 3);
int TWELVE = (LED_Loop-1);
int HR_Fade = 7;
int MN_Fade;
long HR_Colour;
long SE_Colour = 0x000055;
long THIS_LED;
int Led_Flag;
int argh;
// trying this way to get colours working.
int HR_R;
int HR_G;
int HR_B;
int HR1_R = 0x55;
int HR1_G = 0;
int HR1_B = 0;
int HR2_R = 0x0D;
int HR2_G = 0;
int HR2_B = 0x0D;
int MN_R = 0;
int MN_G = 33;
int MN_B = 0;
//int SE_R = 0;
//int SE_G = 0;
//int SE_B = 0x55;
int hour_led;
int minute_led;
int second_led;
int new_minute;
//----------------------------- Set up here -----------------------------//
void setup()
{
// put your setup code here, to run once:
delay(2000); // This is just to give you time to open the window and watch.
Serial.begin(9600);
Serial.println("-------------------------------");
Serial.println("Setting up");
Wire.begin();
strip.begin();
strip.show(); // Initialize all pixels to 'off'
if (! RTC.isrunning())
{
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
Serial.println("Done setting up");
Serial.println("-------------------------------");
}
//----------------------------- MAIN LOOP here -----------------------------//
void loop()
{
// Get time
DateTime now = RTC.now();
// 24 hour time change colour of hour hand.
int hr = now.hour();
if (hr < 12)
{
//HR_Colour = HR_Colour1;
HR_R = HR1_R;
HR_G = HR1_G;
HR_B = HR1_B;
}
else
{
//HR_Colour = HR_Colour2;
HR_R = HR2_R;
HR_G = HR2_G;
HR_B = HR2_B;
}
int mins = now.minute(); // This line is only incase any maths had to be done.
second_led = now.second();
//
// calculate leds
hour_led = (((LED_Loop/12) * hr) + (mins / (LED_Loop/5)))%LED_Loop;
if (hour_led == 60)
{
hour_led = 59;
}
minute_led = mins;
// Debug code below
//
//------------------------------------------//
/*
Serial.print(now.year());
Serial.print('/');
Serial.print(now.month());
Serial.print('/');
Serial.print(now.day());
Serial.print(' ');
Serial.print(now.hour());
Serial.print(':');
Serial.print(now.minute());
Serial.print(':');
Serial.print(now.second());
Serial.println();
*/
//------------------------------------------//
/*
Serial.println("=========================");
Serial.println(hr);
Serial.println(mins);
Serial.println("-------------------------");
Serial.println(hour_led);
Serial.println(minute_led);
Serial.println(second_led);
*/
//------------------------------------------//
//
// Show LEDs ------------------ Main loop here -----------------
// Keep this at the top so it doesn't mess up any other settings when LEDs are
// turned on.
strip.setPixelColor(second_led-1,SE_Colour/2);
strip.setPixelColor(second_led-2,SE_Colour/4);
strip.setPixelColor(second_led-3,SE_Colour/8);
strip.setPixelColor(second_led-4,SE_Colour/16);
strip.setPixelColor(second_led-5,0);
//
// show THREE, SIX, NINE and TWELVE
//
strip.setPixelColor (THREE, 0x050505);
strip.setPixelColor (SIX, 0x050505);
strip.setPixelColor (NINE, 0x050505);
strip.setPixelColor (TWELVE, 0x050505);
//
// Now start setting LEDs below here.
//
if (second_led == 0)
{
strip.setPixelColor(LED_Loop-1, SE_Colour/2);
strip.setPixelColor(LED_Loop-2,SE_Colour/4);
strip.setPixelColor(LED_Loop-3,SE_Colour/8);
strip.setPixelColor(LED_Loop-4,SE_Colour/16);
strip.setPixelColor(LED_Loop-5,0);
new_minute = 1;
}
if (second_led == 1)
{
strip.setPixelColor(second_led-1, SE_Colour/2);
strip.setPixelColor(LED_Loop-1, SE_Colour/4);
strip.setPixelColor(LED_Loop-2,SE_Colour/8);
strip.setPixelColor(LED_Loop-3,SE_Colour/16);
strip.setPixelColor(LED_Loop-4,0);
}
if (second_led == 2)
{
strip.setPixelColor(second_led-1, SE_Colour/2);
strip.setPixelColor(second_led-2, SE_Colour/4);
strip.setPixelColor(LED_Loop-1, SE_Colour/8);
strip.setPixelColor(LED_Loop-2,SE_Colour/16);
strip.setPixelColor(LED_Loop-3,0);
}
if (second_led == 3)
{
strip.setPixelColor(second_led-1, SE_Colour/2);
strip.setPixelColor(second_led-2, SE_Colour/4);
strip.setPixelColor(second_led-3, SE_Colour/8);
strip.setPixelColor(LED_Loop-1,SE_Colour/16);
strip.setPixelColor(LED_Loop-2,0);
}
if (second_led == 4)
{
strip.setPixelColor(second_led-1, SE_Colour/2);
strip.setPixelColor(second_led-2, SE_Colour/4);
strip.setPixelColor(second_led-3, SE_Colour/8);
strip.setPixelColor(second_led-4,SE_Colour/16);
strip.setPixelColor(LED_Loop-1,0);
}
/*
if (Led_Flag == 0)
{
//
Led_Flag = 1;
THIS_LED = strip.getPixelColor(second_led);
// This is where I am at.
Serial.print(second_led);
Serial.print(" ");
Serial.println(THIS_LED);
}
*/
/*---------------- Draw SECOND HAND on clock ----------------*/
strip.setPixelColor(second_led,SE_Colour);
// strip.setPixelColor(second_led,SE_Colour+THIS_LED);
// strip.setPixelColor(second_led-1,THIS_LED);
if (new_minute == 1)
{
//new_minute = 0;
// strip.setPixelColor(minute_led-1,MN_Colour/50);
}
/*---------------- Draw MINUTE HAND on clock ----------------*/
//strip.setPixelColor(minute_led,MN_Colour);
// MN_Fade for fading.
strip.setPixelColor(minute_led,MN_R,MN_G,MN_B);
strip.setPixelColor(minute_led+1, MN_R, (MN_G * (second_led*10/6)/100) , MN_B);
strip.setPixelColor(minute_led-1, MN_R, (MN_G * (100-(second_led*10/6))/100) , MN_B);
/*---------------- Draw HOUR HAND on clock ----------------*/
strip.setPixelColor(hour_led,HR_R,HR_G,HR_B);
//strip.setPixelColor((hour_led-1)%LED_Loop,HR_R/HR_Fade,HR_G,HR_B/HR_Fade);
//strip.setPixelColor((hour_led+1)%LED_Loop,HR_R/HR_Fade,HR_G,HR_B/HR_Fade);
/*
strip.setPixelColor(hour_led,HR_Colour);
strip.setPixelColor((hour_led-1)%LED_Loop,HR_Colour);
strip.setPixelColor((hour_led+1)%LED_Loop,HR_Colour);
*/
if (second_led > minute_led)
{
new_minute = 0;
}
/*
if (second_led != argh)
{
Led_Flag = 0;
argh = second_led;
}
*/
//
// show alarms
//
strip.show();
delay(400);
// ------------------ End of Main loop here -----------------
}
//==================================================================
//==================================================================
//
// end of code
//
//==================================================================