-
1Step 1
HARDWARE:
1) Get one Arduino Nano (or clone). I used one with an ATmega328 chip. $2.49 from ebay.
2) Get one 4 Digit 7 Segment LED Clock Display. I used a 5462BS. A CL5642BH also works. I suspect that most of the ones with the colon in the middle have the same pinout. I will put the pinout below before the code. Positive goes to the 'Digit' and negative goes to the 'Segment' so it is a 'Common Anode' type. $2.49 from ebay.
Plug them together like this -
Now you can solder the pins of just bend them out to about 45 degrees. If you bend them out and then take them apart and then straighten the pins from the top ends, the board will clip back into place from the kinks in the bottom of the pins.
The pinout is like this -
1 a f 2 3 b * * * * * * 8.8.:8.8. * * * * * * e d : c g 4
The : pin is the colon (:) in the centre and works with Digit '2'.
1, 2, 3, 4 are digits 1 to 4 from left to right.
a, b, c, d, e, f, g are the seven segments in the standard order.
The decimal points don't work / aren't connected.
SOFTWARE:
Warning: I did intend to 'Charlieplex' the display but I forgot when I was writing the dec to 7 seg routine so now the 'digit' pin will be drawing way too much power from the ATmega328 pins. This may (over time) damage the chip.
I can change the code to include 'Charlieplexing' if anyone wants (just leave a comment).
#define SegA 5 // Segements are active LOW #define SegB 9 #define SegC 16 #define SegD 18 #define SegE 19 #define SegF 6 #define SegG 15 #define SegDP 17 #define Dig1 4 // Digits are active HIGH #define Dig2 7 #define Dig3 8 #define Dig4 14 void setup() { digitalWrite(Dig1, LOW); // Off pinMode(Dig1, OUTPUT); digitalWrite(Dig2, LOW); // Off pinMode(Dig2, OUTPUT); digitalWrite(Dig3, LOW); // Off pinMode(Dig3, OUTPUT); digitalWrite(Dig4, LOW); // Off pinMode(Dig4, OUTPUT); digitalWrite(SegA, HIGH); // Off pinMode(SegA, OUTPUT); digitalWrite(SegB, HIGH); // Off pinMode(SegB, OUTPUT); digitalWrite(SegC, HIGH); // Off pinMode(SegC, OUTPUT); digitalWrite(SegD, HIGH); // Off pinMode(SegD, OUTPUT); digitalWrite(SegE, HIGH); // Off pinMode(SegE, OUTPUT); digitalWrite(SegF, HIGH); // Off pinMode(SegF, OUTPUT); digitalWrite(SegG, HIGH); // Off pinMode(SegG, OUTPUT); digitalWrite(SegDP, HIGH); // Off pinMode(SegDP, OUTPUT); } void loop() { static int hours = 12; static int minutes = 59; static int seconds = 50; unsigned long start = millis(); while((millis() - start) < 500) { show_time(minutes, seconds, 0); } while((millis() - start) < 1000 ) { show_time(minutes, seconds, 1); } seconds--; if(seconds == -1) { seconds = 59; minutes--; if(minutes == -1) { minutes = 59; hours--; if(hours == 0) { hours = 12; } } } } void show_time(int hours, int minutes, int colon) { int d1 = int(hours / 10); int d2 = hours - d1 * 10; if(d1 == 0) {d1 = 11;} int d3 = int(minutes / 10); int d4 = minutes - d3 * 10; set_digits(1); set_segments(d1); delay(5); set_digits(2); set_segments(d2); set_colon(colon); delay(5); set_digits(3); set_segments(d3); delay(5); set_digits(4); set_segments(d4); delay(5); all_segments_off(); } void set_colon(int colon) { switch(colon) { case 1: digitalWrite(SegDP, LOW); // Segements are active LOW break; default: digitalWrite(SegDP, HIGH); break; } } void set_digits(int digit) { switch(digit) { case 1: digitalWrite(Dig1, HIGH); // Digits are active HIGH digitalWrite(Dig2, LOW); digitalWrite(Dig3, LOW); digitalWrite(Dig4, LOW); break; case 2: digitalWrite(Dig1, LOW); // Digits are active HIGH digitalWrite(Dig2, HIGH); digitalWrite(Dig3, LOW); digitalWrite(Dig4, LOW); break; case 3: digitalWrite(Dig1, LOW); // Digits are active HIGH digitalWrite(Dig2, LOW); digitalWrite(Dig3, HIGH); digitalWrite(Dig4, LOW); break; case 4: digitalWrite(Dig1, LOW); // Digits are active HIGH digitalWrite(Dig2, LOW); digitalWrite(Dig3, LOW); digitalWrite(Dig4, HIGH); break; default: digitalWrite(Dig1, LOW); // Digits are active HIGH digitalWrite(Dig2, LOW); digitalWrite(Dig3, LOW); digitalWrite(Dig4, LOW); break; } } void set_segments(char digit) { switch(digit) { case 0: digitalWrite(SegA, LOW); // Segements are active LOW digitalWrite(SegB, LOW); digitalWrite(SegC, LOW); digitalWrite(SegD, LOW); digitalWrite(SegE, LOW); digitalWrite(SegF, LOW); digitalWrite(SegG, HIGH); break; case 1: digitalWrite(SegA, HIGH); // Segements are active LOW digitalWrite(SegB, LOW); digitalWrite(SegC, LOW); digitalWrite(SegD, HIGH); digitalWrite(SegE, HIGH); digitalWrite(SegF, HIGH); digitalWrite(SegG, HIGH); break; case 2: digitalWrite(SegA, LOW); // Segements are active LOW digitalWrite(SegB, LOW); digitalWrite(SegC, HIGH); digitalWrite(SegD, LOW); digitalWrite(SegE, LOW); digitalWrite(SegF, HIGH); digitalWrite(SegG, LOW); break; case 3: digitalWrite(SegA, LOW); // Segements are active LOW digitalWrite(SegB, LOW); digitalWrite(SegC, LOW); digitalWrite(SegD, LOW); digitalWrite(SegE, HIGH); digitalWrite(SegF, HIGH); digitalWrite(SegG, LOW); break; case 4: digitalWrite(SegA, HIGH); // Segements are active LOW digitalWrite(SegB, LOW); digitalWrite(SegC, LOW); digitalWrite(SegD, HIGH); digitalWrite(SegE, HIGH); digitalWrite(SegF, LOW); digitalWrite(SegG, LOW); break; case 5: digitalWrite(SegA, LOW); // Segements are active LOW digitalWrite(SegB, HIGH); digitalWrite(SegC, LOW); digitalWrite(SegD, LOW); digitalWrite(SegE, HIGH); digitalWrite(SegF, LOW); digitalWrite(SegG, LOW); break; case 6: digitalWrite(SegA, LOW); // Segements are active LOW digitalWrite(SegB, HIGH); digitalWrite(SegC, LOW); digitalWrite(SegD, LOW); digitalWrite(SegE, LOW); digitalWrite(SegF, LOW); digitalWrite(SegG, LOW); break; case 7: digitalWrite(SegA, LOW); // Segements are active LOW digitalWrite(SegB, LOW); digitalWrite(SegC, LOW); digitalWrite(SegD, HIGH); digitalWrite(SegE, HIGH); digitalWrite(SegF, HIGH); digitalWrite(SegG, HIGH); break; case 8: digitalWrite(SegA, LOW); // Segements are active LOW digitalWrite(SegB, LOW); digitalWrite(SegC, LOW); digitalWrite(SegD, LOW); digitalWrite(SegE, LOW); digitalWrite(SegF, LOW); digitalWrite(SegG, LOW); break; case 9: digitalWrite(SegA, LOW); // Segements are active LOW digitalWrite(SegB, LOW); digitalWrite(SegC, LOW); digitalWrite(SegD, LOW); digitalWrite(SegE, HIGH); digitalWrite(SegF, LOW); digitalWrite(SegG, LOW); break; default: digitalWrite(SegA, HIGH); // Segements are active LOW digitalWrite(SegB, HIGH); digitalWrite(SegC, HIGH); digitalWrite(SegD, HIGH); digitalWrite(SegE, HIGH); digitalWrite(SegF, HIGH); digitalWrite(SegG, HIGH); break; } } void all_segments_off() { digitalWrite(Dig1, LOW); // Digits are active HIGH digitalWrite(Dig2, LOW); digitalWrite(Dig3, LOW); digitalWrite(Dig4, LOW); digitalWrite(SegA, HIGH); // Segements are active LOW digitalWrite(SegB, HIGH); digitalWrite(SegC, HIGH); digitalWrite(SegD, HIGH); digitalWrite(SegE, HIGH); digitalWrite(SegF, HIGH); digitalWrite(SegG, HIGH); digitalWrite(SegDP, HIGH); }
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.