// Countdown Timer using Arduino Uno
// Connect common cathode 7-segment display to pins 2-9 (a-g) and 10-13 (digit selection)
const int a = 12;
const int b = 10;
const int c = 8;
const int d = 7;
const int e = 6;
const int f = 11;
const int g = 9;
int p = 0; // Placeholder for digit selection pin
int startStopReset = 13; // Button to start/reset the timer
long n = 60000; // Initial time (in milliseconds)
int x = 100; // Update interval (milliseconds)
int del = 55; // Delay for display refresh (microseconds)
void setup() {
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(p, OUTPUT);
pinMode(startStopReset, INPUT);
digitalWrite(startStopReset, HIGH);
}
void loop() {
digitalWrite(p, HIGH);
clearLEDs();
pickDigit(1);
pickNumber((n / x / 1000) % 10);
delayMicroseconds(del);
// Repeat for other digits (2, 3, 4)...
n--; // Decrement time (you can use 'n++' for a stopwatch)
if (digitalRead(startStopReset) == LOW) {
n = 60000; // Reset time (change to your original start time)
}
}
// Helper functions for displaying numbers (0-9) on the 7-segment display
// Implement these based on your display's pin configuration
void pickDigit(int x) {
// Select the appropriate digit (1-4)
// Set the corresponding digit pin LOW
// Other digit pins should be HIGH
// Example: digitalWrite(d1, LOW);
}
void pickNumber(int x) {
// Display the number (0-9) on the 7-segment display
// Implement this using individual segment pins (a-g)
// Example: digitalWrite(a, HIGH); digitalWrite(b, LOW); ...
}
void clearLEDs() {
// Turn off all segments (set all pins LOW)
}
// Implement functions zero(), one(), ..., nine() for each digit
// Remember to connect your 7-segment display properly!