Components and supplies
Female Header 8 Position 1 Row (0.1")
Dot Pcb
Male-Header 36 Position 1 Row- Long (0.1")
Tactile Switch, Top Actuated
Arduino Nano R3
5 mm LED: Red
Hook Up Wire Kit, 22 AWG
Tools and machines
Solder Wire, Lead Free
Soldering iron (generic)
PCB Holder, Soldering Iron
Solder Flux, Soldering
Apps and platforms
Arduino IDE
Project description
Code
Arduino Code
c_cpp
7 Segment Led Clock
1//feel free to contact 2//sreeramaj53@gmail.com 3//www.youtube.com/ZenoModiff 4 5#include <TimeLib.h> 6int digit1 = 10; 7int digit2 = 11; 8int digit3 = 12; 9int digit4 = 13; 10 11int segA = 8;//Display pin A 12int segB = 7;//splay pin b 13int segC = 6; //Display pin c 14int segD = 5; //Display pin d 15int segE = 4; //Display pin e 16int segF = 3; //Display pin f 17int segG = 2; //Display pin g 18int segDP = 9;// Display pin dot 19 20byte SW0 = A0; 21byte SW1 = A1; 22byte SW2 = A2; 23 24void setup() { 25 26 pinMode(segA, OUTPUT); 27 pinMode(segB, OUTPUT); 28 pinMode(segC, OUTPUT); 29 pinMode(segD, OUTPUT); 30 pinMode(segE, OUTPUT); 31 pinMode(segF, OUTPUT); 32 pinMode(segG, OUTPUT); 33 pinMode(segDP, OUTPUT); 34 35 pinMode(digit1, OUTPUT); 36 pinMode(digit2, OUTPUT); 37 pinMode(digit3, OUTPUT); 38 pinMode(digit4, OUTPUT); 39 40 Serial.begin(9600); 41 42 pinMode(SW0, INPUT); 43 pinMode(SW1, INPUT); 44 pinMode(SW2, INPUT); 45 46 digitalWrite(SW0, HIGH); 47 digitalWrite(SW1, HIGH); 48 digitalWrite(SW2, HIGH); 49} 50 51void loop() { 52 digitalWrite(segDP, HIGH); 53 int hr = hour(); 54 int timp = ( (hr>12)?(hr%12):hr)*100+minute(); 55 Serial.println(timp); 56 57 for(int i = 250 ; i >0 ; i--) { 58 if (timp > 100) displayNumber01(timp); 59 else displayNumber02(timp); 60 } 61 62 for(int i = 250 ; i >0 ; i--) { 63 if (timp > 100) displayNumber03(timp); 64 else displayNumber04(timp); 65 } 66 67 if (!(digitalRead(SW0))) set_time(); 68} 69 70void set_time() { 71 byte minutes1 = 0; 72 byte hours1 = 0; 73 byte minutes = minute(); 74 byte hours = hour(); 75 76 while (!digitalRead(SW0)) 77 { 78 minutes1=minutes; 79 hours1=hours; 80 81 while (!digitalRead(SW1)) 82 { 83 minutes++; 84 85 if (minutes > 59) minutes = 0; 86 for(int i = 20 ; i >0 ; i--) { 87 int timp= hours*100+minutes; 88 if (timp > 1000) displayNumber01(timp); 89 else displayNumber02(timp); 90 } 91 92 delay(150); 93 } 94 95 while (!digitalRead(SW2)) 96 { 97 hours++; 98 99 if (hours > 12) hours = 0; 100 101 for(int i = 20 ; i >0 ; i--) { 102 int timp= hours*100+minutes; 103 if (timp > 1000) displayNumber01(timp); 104 else displayNumber02(timp); 105 } 106 107 delay(150); 108 } 109 110 for(int i = 20 ; i >0 ; i--) { 111 displayNumber01(hours*100+minutes); 112 } 113 setTime(hours,minutes,0,0,0,0); 114 delay(150); 115 116 } 117 118} 119 120void displayNumber01(int toDisplay) { 121#define DISPLAY_BRIGHTNESS 500 122 123#define DIGIT_ON HIGH 124#define DIGIT_OFF LOW 125 126 for(int digit = 4 ; digit > 0 ; digit--) { 127 128 129 switch(digit) { 130 case 1: 131 digitalWrite(digit1, DIGIT_ON); 132 digitalWrite(segDP, LOW); 133 break; 134 case 2: 135 digitalWrite(digit2, DIGIT_ON); 136 digitalWrite(segDP, LOW); 137 break; 138 case 3: 139 digitalWrite(digit3, DIGIT_ON); 140 digitalWrite(segDP, LOW); 141 break; 142 case 4: 143 digitalWrite(digit4, DIGIT_ON); 144 digitalWrite(segDP, LOW); 145 break; 146 } 147 lightNumber(toDisplay % 10); 148 toDisplay /= 10; 149 delayMicroseconds(DISPLAY_BRIGHTNESS); 150 151 152 lightNumber(10); 153 154 155 digitalWrite(digit1, DIGIT_OFF); 156 digitalWrite(digit2, DIGIT_OFF); 157 digitalWrite(digit3, DIGIT_OFF); 158 digitalWrite(digit4, DIGIT_OFF); 159} 160} 161 162void displayNumber02(int toDisplay) { 163#define DISPLAY_BRIGHTNESS 500 164 165#define DIGIT_ON HIGH 166#define DIGIT_OFF LOW 167 168 for(int digit = 4 ; digit > 0 ; digit--) { 169 170 171 switch(digit) { 172 case 1: 173 lightNumber(10); 174 digitalWrite(segDP, LOW); 175 break; 176 case 2: 177 digitalWrite(digit2, DIGIT_ON); 178 digitalWrite(segDP, LOW); 179 break; 180 case 3: 181 digitalWrite(digit3, DIGIT_ON); 182 digitalWrite(segDP, LOW); 183 break; 184 case 4: 185 digitalWrite(digit4, DIGIT_ON); 186 digitalWrite(segDP, LOW); 187 break; 188 } 189 lightNumber(toDisplay % 10); 190 toDisplay /= 10; 191 delayMicroseconds(DISPLAY_BRIGHTNESS); 192 193 194 lightNumber(10); 195 196 197 digitalWrite(digit1, DIGIT_OFF); 198 digitalWrite(digit2, DIGIT_OFF); 199 digitalWrite(digit3, DIGIT_OFF); 200 digitalWrite(digit4, DIGIT_OFF); 201} 202} 203 204void displayNumber03(int toDisplay) { 205#define DISPLAY_BRIGHTNESS 500 206 207#define DIGIT_ON HIGH 208#define DIGIT_OFF LOW 209 210 for(int digit = 4 ; digit > 0 ; digit--) { 211 212 213 switch(digit) { 214 case 1: 215 digitalWrite(digit1, DIGIT_ON); 216 digitalWrite(segDP, HIGH); 217 break; 218 case 2: 219 digitalWrite(digit2, DIGIT_ON); 220 digitalWrite(segDP, HIGH); 221 break; 222 case 3: 223 digitalWrite(digit3, DIGIT_ON); 224 digitalWrite(segDP, HIGH); 225 break; 226 case 4: 227 digitalWrite(digit4, DIGIT_ON); 228 digitalWrite(segDP, HIGH); 229 break; 230 } 231 lightNumber(toDisplay % 10); 232 toDisplay /= 10; 233 delayMicroseconds(DISPLAY_BRIGHTNESS); 234 235 236 lightNumber(10); 237 238 239 digitalWrite(digit1, DIGIT_OFF); 240 digitalWrite(digit2, DIGIT_OFF); 241 digitalWrite(digit3, DIGIT_OFF); 242 digitalWrite(digit4, DIGIT_OFF); 243} 244} 245 246void displayNumber04(int toDisplay) { 247#define DISPLAY_BRIGHTNESS 500 248 249#define DIGIT_ON HIGH 250#define DIGIT_OFF LOW 251 252 for(int digit = 4 ; digit > 0 ; digit--) { 253 254 255 switch(digit) { 256 case 1: 257 lightNumber(10); 258 digitalWrite(segDP, HIGH); 259 break; 260 case 2: 261 digitalWrite(digit2, DIGIT_ON); 262 digitalWrite(segDP, HIGH); 263 break; 264 case 3: 265 digitalWrite(digit3, DIGIT_ON); 266 digitalWrite(segDP, HIGH); 267 break; 268 case 4: 269 digitalWrite(digit4, DIGIT_ON); 270 digitalWrite(segDP, HIGH); 271 break; 272 } 273 lightNumber(toDisplay % 10); 274 toDisplay /= 10; 275 delayMicroseconds(DISPLAY_BRIGHTNESS); 276 277 lightNumber(10); 278 279 digitalWrite(digit1, DIGIT_OFF); 280 digitalWrite(digit2, DIGIT_OFF); 281 digitalWrite(digit3, DIGIT_OFF); 282 digitalWrite(digit4, DIGIT_OFF); 283} 284} 285 286void lightNumber(int numberToDisplay) { 287 288#define SEGMENT_ON LOW 289#define SEGMENT_OFF HIGH 290 291 switch (numberToDisplay){ 292 293 case 0: 294 digitalWrite(segA, SEGMENT_ON); 295 digitalWrite(segB, SEGMENT_ON); 296 digitalWrite(segC, SEGMENT_ON); 297 digitalWrite(segD, SEGMENT_ON); 298 digitalWrite(segE, SEGMENT_ON); 299 digitalWrite(segF, SEGMENT_ON); 300 digitalWrite(segG, SEGMENT_OFF); 301 break; 302 303 case 1: 304 digitalWrite(segA, SEGMENT_OFF); 305 digitalWrite(segB, SEGMENT_ON); 306 digitalWrite(segC, SEGMENT_ON); 307 digitalWrite(segD, SEGMENT_OFF); 308 digitalWrite(segE, SEGMENT_OFF); 309 digitalWrite(segF, SEGMENT_OFF); 310 digitalWrite(segG, SEGMENT_OFF); 311 break; 312 313 case 2: 314 digitalWrite(segA, SEGMENT_ON); 315 digitalWrite(segB, SEGMENT_ON); 316 digitalWrite(segC, SEGMENT_OFF); 317 digitalWrite(segD, SEGMENT_ON); 318 digitalWrite(segE, SEGMENT_ON); 319 digitalWrite(segF, SEGMENT_OFF); 320 digitalWrite(segG, SEGMENT_ON); 321 break; 322 323 case 3: 324 digitalWrite(segA, SEGMENT_ON); 325 digitalWrite(segB, SEGMENT_ON); 326 digitalWrite(segC, SEGMENT_ON); 327 digitalWrite(segD, SEGMENT_ON); 328 digitalWrite(segE, SEGMENT_OFF); 329 digitalWrite(segF, SEGMENT_OFF); 330 digitalWrite(segG, SEGMENT_ON); 331 break; 332 333 case 4: 334 digitalWrite(segA, SEGMENT_OFF); 335 digitalWrite(segB, SEGMENT_ON); 336 digitalWrite(segC, SEGMENT_ON); 337 digitalWrite(segD, SEGMENT_OFF); 338 digitalWrite(segE, SEGMENT_OFF); 339 digitalWrite(segF, SEGMENT_ON); 340 digitalWrite(segG, SEGMENT_ON); 341 break; 342 343 case 5: 344 digitalWrite(segA, SEGMENT_ON); 345 digitalWrite(segB, SEGMENT_OFF); 346 digitalWrite(segC, SEGMENT_ON); 347 digitalWrite(segD, SEGMENT_ON); 348 digitalWrite(segE, SEGMENT_OFF); 349 digitalWrite(segF, SEGMENT_ON); 350 digitalWrite(segG, SEGMENT_ON); 351 break; 352 353 case 6: 354 digitalWrite(segA, SEGMENT_ON); 355 digitalWrite(segB, SEGMENT_OFF); 356 digitalWrite(segC, SEGMENT_ON); 357 digitalWrite(segD, SEGMENT_ON); 358 digitalWrite(segE, SEGMENT_ON); 359 digitalWrite(segF, SEGMENT_ON); 360 digitalWrite(segG, SEGMENT_ON); 361 break; 362 363 case 7: 364 digitalWrite(segA, SEGMENT_ON); 365 digitalWrite(segB, SEGMENT_ON); 366 digitalWrite(segC, SEGMENT_ON); 367 digitalWrite(segD, SEGMENT_OFF); 368 digitalWrite(segE, SEGMENT_OFF); 369 digitalWrite(segF, SEGMENT_OFF); 370 digitalWrite(segG, SEGMENT_OFF); 371 break; 372 373 case 8: 374 digitalWrite(segA, SEGMENT_ON); 375 digitalWrite(segB, SEGMENT_ON); 376 digitalWrite(segC, SEGMENT_ON); 377 digitalWrite(segD, SEGMENT_ON); 378 digitalWrite(segE, SEGMENT_ON); 379 digitalWrite(segF, SEGMENT_ON); 380 digitalWrite(segG, SEGMENT_ON); 381 break; 382 383 case 9: 384 digitalWrite(segA, SEGMENT_ON); 385 digitalWrite(segB, SEGMENT_ON); 386 digitalWrite(segC, SEGMENT_ON); 387 digitalWrite(segD, SEGMENT_ON); 388 digitalWrite(segE, SEGMENT_OFF); 389 digitalWrite(segF, SEGMENT_ON); 390 digitalWrite(segG, SEGMENT_ON); 391 break; 392 393 394 case 10: 395 digitalWrite(segA, SEGMENT_OFF); 396 digitalWrite(segB, SEGMENT_OFF); 397 digitalWrite(segC, SEGMENT_OFF); 398 digitalWrite(segD, SEGMENT_OFF); 399 digitalWrite(segE, SEGMENT_OFF); 400 digitalWrite(segF, SEGMENT_OFF); 401 digitalWrite(segG, SEGMENT_OFF); 402 break; 403 404 } 405} 406
Downloadable files
Schematics
7 Segment Led Clock
Schematics
Schematics
7 Segment Led Clock
Schematics
Comments
Only logged in users can leave comments