#include <SevSeg.h>
// Create SevSeg object
SevSeg sevseg;
// Define pins for the 7-segment display
#define digit3 11
#define digit4 12
#define segmentA 4
#define segmentB 5
#define segmentC 6
#define segmentD 7
#define segmentE 8
#define segmentF 9
#define segmentG 10
// Define time variables
unsigned long previousMillis = 0;
const long interval = 1000; // Update every 1 second
int countdownSeconds = 15; // Initial countdown value
void setup() {
// Initialize SevSeg
byte numDigits = 2;
byte digitPins[] = {digit3, digit4};
// bool resistorsOnSegments = true;
byte hardwareConfig = COMMON_CATHODE;
byte segmentPins[] = {4, 5, 6, 7, 8, 9, 10};
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins);
// Set brightness (optional)
sevseg.setBrightness(100);
}
void loop() {
// Get the current time
unsigned long currentMillis = millis();
// Check if one second has passed
if (currentMillis - previousMillis >= interval) {
// Update the timer
updateTimer();
// Save the current time for the next iteration
previousMillis = currentMillis;
}
// Display the countdown on the 7-segment display
sevseg.setNumber(countdownSeconds, 0);
sevseg.refreshDisplay();
}
void updateTimer() {
// Decrease the countdown by one second
countdownSeconds--;
// Check if the countdown has reached zero
if (countdownSeconds < 0) {
// Reset the countdown
countdownSeconds = 15;
}
}