#include <SevSeg.h>
// Create a SevSeg object
SevSeg sevseg;
// Define button pins
const int startButtonPin = 2; // Start button
const int resetButtonPin = 13; // Reset button
// Variables for counting
volatile bool counting = false;
unsigned long startTime;
float countValue = 0.0;
void setup() {
// Setup 7-segment display
byte numDigits = 3;
byte digitPins[] = {2, 3, 4}; // Update according to your wiring
byte segmentPins[] = {4, 5, 6, 7, 8, 9, A0, A1}; // Update according to your wiring
sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);
// Setup button pins
pinMode(startButtonPin, INPUT_PULLUP);
pinMode(resetButtonPin, INPUT_PULLUP);
// Attach interrupts for button presses
attachInterrupt(digitalPinToInterrupt(startButtonPin), startCounting, FALLING);
attachInterrupt(digitalPinToInterrupt(resetButtonPin), resetCounting, FALLING);
// Initialize display
sevseg.setNumber(0, 1);
}
void loop() {
if (counting) {
unsigned long elapsedTime = millis() - startTime;
// Count from 0.0 to 88.0
if (elapsedTime < 15000) { // Count for 15 seconds
countValue = (elapsedTime / 1000.0) * (88.0 / 15.0); // Scale to 0-88
sevseg.setNumber(countValue, 1);
} else {
// After 15 seconds, show the middle display's bottom dot
sevseg.setNumber(0, 1); // Reset displayed value
sevseg.setDecimalPoint(1); // Show bottom dot
}
}
sevseg.refreshDisplay(); // Refresh display
}
void startCounting() {
if (!counting) {
counting = true;
startTime = millis();
}
}
void resetCounting() {
counting = false;
countValue = 0.0;
sevseg.setNumber(0, 1); // Reset display
sevseg.setDecimalPoint(0); // Turn off the bottom dot
}