// Two Digit Count Down Timer
#include <SevSeg.h>
SevSeg sevseg;
#define degit1 2
#define degit2 3
unsigned long previousMillis = 0;
const long interval = 1000; // 1 second
int countdownSeconds = 20;
void setup() {
// put your setup code here, to run once:
byte numDigits = 2;
byte digitPins[] = {degit1, degit2};
byte hardwareConfig = COMMON_CATHODE;
byte segmentPins[] = {4, 5, 6, 7, 8, 9,10};
bool resistorsOnSegments = true;
sevseg.begin(numDigits, digitPins, hardwareConfig, segmentPins, resistorsOnSegments);
sevseg.setBrightness(90);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis = millis();
// check if 1s is passed
if (currentMillis - previousMillis >= interval) {
// update time method
updateTimer();
// save current time for iteration
previousMillis = currentMillis;
}
// Display the Numbers
sevseg.setNumber(countdownSeconds, 0);
sevseg.refreshDisplay();
}
void updateTimer() {
// decrement
countdownSeconds--;
// check if the countdown reach zero
if(countdownSeconds < 0 ) {
// reset the countdown
countdownSeconds = 20;
}
}