Devices & Components
Arduino Uno Rev3
Solderless Breadboard Full Size
Resistor 1k ohm
SparkFun 7-Segment Serial Display - Red
Jumper wires (generic)
Tactile Switch, Top Actuated
Capacitor 100 nF
Capacitor 10 µF
Resistor 10k ohm
MAX7219/MAX7221 LED Display Drivers
Software & Tools
Arduino IDE
Project description
Code
8.ino
arduino
1#include "LedControl.h" 2 3/* 4 Now we need a LedControl to work 5 with. 6 pin 12 is connected to the DataIn 7 pin 11 is connected to LOAD 8 9 pin 10 is connected to the CLK 10 */ 11LedControl lc=LedControl(12,10,11,1); 12const 13 int seth = 4; 14const int setm = 3; 15const int setc = 2; 16 17int second ; 18 19 int minute ; 20int hour ; 21 22int correction = 0; 23 24 25unsigned long previousMillis 26 = 0; 27const long interval = 1000; 28 29 30void setup() { 31 lc.shutdown(0,false); 32 33 lc.setIntensity(0,12); 34 lc.clearDisplay(0); 35} 36void loop() { 37 if 38 (digitalRead(seth)== HIGH){ 39 hour++; 40 delay(200); 41 if(hour>23){ 42 43 hour=00; 44 } 45 } 46 if (digitalRead(setm)== HIGH){ 47 minute++; 48 49 delay(200); 50 if(minute>59){ 51 minute=00; 52 } 53 } 54 if (digitalRead(setc)== 55 HIGH){ 56 correction++; 57 delay(200); 58 if(correction>59){ 59 correction=00; 60 61 } 62 } 63 unsigned long currentMillis = millis(); 64 if (currentMillis - 65 previousMillis >= interval) { 66 previousMillis = currentMillis; 67 second++; 68 69 if(second>59) 70 { 71 minute++; 72 second=00; 73 } 74 if(minute>59) 75 76 { 77 hour++; 78 minute=00; 79 second = second + correction; 80 } 81 if(hour>23) 82 { hour=00; minute=00; second=correction; } 83 } 84 85lc.setDigit(0,1,hour % 10,true); 86lc.setDigit(0,0,(hour 87 - hour % 10) / 10,false); 88lc.setDigit(0,3,minute % 10,false); 89lc.setDigit(0,2,(minute 90 - minute % 10) / 10,false); 91lc.setDigit(0,5,second % 10,true); 92lc.setDigit(0,4,(second 93 - second % 10) / 10,false); 94lc.setDigit(0,7,correction % 10,false); 95lc.setDigit(0,6,(correction 96 - correction % 10) / 10,false); 97} 98
8.ino
arduino
1#include "LedControl.h" 2 3/* 4 Now we need a LedControl to work with. 5 pin 12 is connected to the DataIn 6 pin 11 is connected to LOAD 7 pin 10 is connected to the CLK 8 */ 9LedControl lc=LedControl(12,10,11,1); 10const int seth = 4; 11const int setm = 3; 12const int setc = 2; 13 14int second ; 15 int minute ; 16int hour ; 17 18int correction = 0; 19 20 21unsigned long previousMillis = 0; 22const long interval = 1000; 23 24 25void setup() { 26 lc.shutdown(0,false); 27 lc.setIntensity(0,12); 28 lc.clearDisplay(0); 29} 30void loop() { 31 if (digitalRead(seth)== HIGH){ 32 hour++; 33 delay(200); 34 if(hour>23){ 35 hour=00; 36 } 37 } 38 if (digitalRead(setm)== HIGH){ 39 minute++; 40 delay(200); 41 if(minute>59){ 42 minute=00; 43 } 44 } 45 if (digitalRead(setc)== HIGH){ 46 correction++; 47 delay(200); 48 if(correction>59){ 49 correction=00; 50 } 51 } 52 unsigned long currentMillis = millis(); 53 if (currentMillis - previousMillis >= interval) { 54 previousMillis = currentMillis; 55 second++; 56 if(second>59) 57 { 58 minute++; 59 second=00; 60 } 61 if(minute>59) 62 { 63 hour++; 64 minute=00; 65 second = second + correction; 66 } 67 if(hour>23) { hour=00; minute=00; second=correction; } 68 } 69 70lc.setDigit(0,1,hour % 10,true); 71lc.setDigit(0,0,(hour - hour % 10) / 10,false); 72lc.setDigit(0,3,minute % 10,false); 73lc.setDigit(0,2,(minute - minute % 10) / 10,false); 74lc.setDigit(0,5,second % 10,true); 75lc.setDigit(0,4,(second - second % 10) / 10,false); 76lc.setDigit(0,7,correction % 10,false); 77lc.setDigit(0,6,(correction - correction % 10) / 10,false); 78} 79
Downloadable files
7_segment_clock_7__0P3R06WZN2.png
7_segment_clock_7__0P3R06WZN2.png

Comments
Only logged in users can leave comments