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