hi mates, i am trying to make a 3 minutes timer with 3 jumbo 7 segment displays with display1=minute, display2=seconds1 and display2=seconds2. Am facing an issue with the code where the minute display is not getting updated after 60 seconds. both the seconds display works perfectly and the minutes display remains displaying 0. Kindly help me out with the below code.
// Define pin numbers for each segment (a to g) for the minutes display
const int segmentPinsMinutes[] = {2, 3, 4, 5, 6, 7, 8};
// Define pin numbers for each segment (a to g) for the first seconds display
const int segmentPinsSeconds1[] = {22, 24, 26, 28, 30, 32, 34};
// Define pin numbers for each segment (a to g) for the second seconds display
const int segmentPinsSeconds2[] = {31, 33, 35, 37, 39, 41, 43};
int currentMinutes = 0;
int currentSeconds = 0;
void setup() {
// Set segment pins as OUTPUT for all displays
for (int i = 0; i < 7; i++) {
pinMode(segmentPinsMinutes[i], OUTPUT);
pinMode(segmentPinsSeconds1[i], OUTPUT);
pinMode(segmentPinsSeconds2[i], OUTPUT);
}
}
void loop() {
unsigned long startTime = millis() / 1000;
for (int minutes = 0; minutes < 3; minutes++) {
for (int seconds = 0; seconds < 60; seconds++) {
unsigned long currentTime = startTime + minutes * 60 + seconds;
displayTime(currentTime / 60, currentTime % 60);
delay(1000); // Display each second
}
// Add a small delay before restarting the loop for the next minute
delay(500); // Adjust as needed
}
// After 3 minutes, you can choose to reset the timer or take some other action
// For now, let's reset the timer to 0 and wait for a brief moment
startTime = millis() / 1000;
delay(2000); // Wait for 2 seconds before restarting the timer
}
void displayTime(int minutes, int seconds) {
const byte digitSegments[][7] = {
{0, 0, 1, 0, 0, 0, 0}, // Digit 0
{1, 1, 1, 1, 1, 0, 0}, // Digit 1
{0, 1, 0, 0, 0, 1, 0}, // Digit 2
{0, 1, 0, 1, 0, 0, 0}, // Digit 3
{1, 0, 0, 1, 1, 0, 0}, // Digit 4
{0, 0, 0, 1, 0, 0, 1}, // Digit 5
{0, 0, 0, 0, 0, 0, 1}, // Digit 6
{0, 1, 1, 1, 1, 0, 0}, // Digit 7
{0, 0, 0, 0, 0, 0, 0}, // Digit 8
{0, 0, 0, 1, 0, 0, 0} // Digit 9
};
// Display the tens and units of minutes
int tensMinutes = minutes / 10;
int unitsMinutes = minutes % 10;
// Display the minutes
displaySegments(segmentPinsMinutes, digitSegments[tensMinutes]);
delayMicroseconds(500); // Add a small delay for multiplexing
displaySegments(segmentPinsSeconds1, digitSegments[unitsMinutes]);
delayMicroseconds(500);
// Display the tens and units of seconds on the first display
int tensSeconds = seconds / 10;
int unitsSeconds = seconds % 10;
displaySegments(segmentPinsSeconds1, digitSegments[tensSeconds]);
delayMicroseconds(500);
displaySegments(segmentPinsSeconds2, digitSegments[unitsSeconds]);
delayMicroseconds(500);
}
void displaySegments(const int pins[], const byte segments[]) {
// Display the segments for the selected digit
for (int i = 0; i < 7; i++) {
digitalWrite(pins[i], segments[i]);
}
}
I noticed that the minutes display is getting updated from 0 to 1, after 10 minutes.
thanks in advance.