// Two digit Seven Segment Countdown Clock // Define the LED digit patters, from 0 - 9 // Note that these patterns are for common cathode displays // For common anode displays, change the 1's to 0's and 0's to 1's // 1 = LED on, 0 = LED off, in this order: // Arduino ones pin: 0,1,2,3,4,5,6 // Arduino tens pin: 7,8,9,10,11,12,13 byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 }, // = 0 { 0,1,1,0,0,0,0 }, // = 1 { 1,1,0,1,1,0,1 }, // = 2 { 1,1,1,1,0,0,1 }, // = 3 { 0,1,1,0,0,1,1 }, // = 4 { 1,0,1,1,0,1,1 }, // = 5 { 1,0,1,1,1,1,1 }, // = 6 { 1,1,1,0,0,0,0 }, // = 7 { 1,1,1,1,1,1,1 }, // = 8 { 1,1,1,1,0,1,1 } // = 9 }; byte circular_digits[6][7] = { { 1,0,0,0,0,0,0 }, // = 0 { 0,1,0,0,0,0,0 }, // = 1 { 0,0,1,0,0,0,0 }, // = 2 { 0,0,0,1,0,0,0 }, // = 3 { 0,0,0,0,1,0,0 }, // = 4 { 0,0,0,0,0,1,0 }, // = 5 }; void setup() { //set all pins to output mode pinMode(0, OUTPUT); pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); } void writeDot(byte dot) { digitalWrite(9, dot); } void sevenSegWrite(byte digit, byte place) { byte pin; if (place == 1) { pin = 0; } else { pin = 7; } for (byte segCount = 0; segCount < 7; ++segCount) { digitalWrite(pin, seven_seg_digits[digit][segCount]); ++pin; } } void circularDigitWrite(byte digit, byte pin){ for (byte segCount = 0; segCount < 7; ++segCount) { digitalWrite(pin, circular_digits[digit][segCount]); ++pin; } } void loop() { for (byte count = 60; count > 0; --count) { delay(991); sevenSegWrite((int)((count-1)/10), 10); sevenSegWrite(count-1-((int)((count-1)/10)*10), 1); } for (byte count = 6; count > 0; --count) { delay(50); circularDigitWrite(count-1, 0); circularDigitWrite(count-1, 7); if (count <= 1) { count = 7; } } }