// High-speed clock for timing slow-motion videos // Will display time with ms precision on a // 4-digit 7-segment display. // The display can be directly connected to an Arduino Nano //for common anode display #define DIGON HIGH #define DIGOFF LOW #define SEGON LOW #define SEGOFF HIGH //for common cathode display //#define DIGON LOW //#define DIGOFF HIGH //#define SEGON HIGH //#define SEGOFF LOW const byte ndig=4; const byte nseg=8; //breadboard setup //const byte digs[ndig] = { 7, 4, 3,A5}; // digs 1 2 3 4 //const byte segs[nseg] = { 6, 2,A3,A1,A0, 5,A4,A2}; // segs ABCDEFGH //nano setup const byte digs[ndig] = { 4, 7, 8,A0}; // digs 1 2 3 4 const byte segs[nseg] = { 5, 9,A2,A4,A5, 6,A1,A3}; // segs ABCDEFGH //translate number into corresponding segements const byte val2seg[10]={ B11111100, //0 B01100000, //1 B11011010, //2 B11110010, //3 B01100110, //4 B10110110, //5 B10111110, //6 B11100000, //7 B11111110, //8 B11110110, //9 }; void setup() { // set to output and switch off all digits for (byte idig=0; idig0){ digitalWrite(segs[iseg], SEGON); } else { digitalWrite(segs[iseg], SEGOFF); } } // set the decimal dot if needed if (idig==0){ digitalWrite(segs[7], SEGON); } else{ digitalWrite(segs[7], SEGOFF); } // switch on the present digit digitalWrite(digs[idig],DIGON); // keep record of the present digit prevdig=idig; // calculate the value of the next digit to process idig=(idig+1)%ndig; // introduce some delay to light the digit a bit longer //delayMicroseconds(1); }