I'm trying to get this countdown timer to stop, after which I will be attempting to combine this code with a scoreboard.
I thought maybe I could move the Loop into the setup and then the countdown would end, after its done, and the Loop would be free for the scoreboard section thinking that would help keep the complications from combining the two to a minimum.
Is it possible for this counter to run in the setup?
And if so; How would I insert it?
Also, can I get the LED in pin 13 to light up (and stay lit) at the end of the counter?
#include <TM1637Display.h>
#define numberofseconds(time) ((time / 1000) % 60)
#define numberofminutes(time) (((time / 1000) /60) % 60)
#define gameled 13
const uint8_t OFF[] = {0, 0, 0, 0};
// in the libary, the byte order is .GFEDCBA
const uint8_t PLAY[] = {B01110011, B00111000, B01110111, B01101110};
//clock, data
TM1637Display display(7, 6);
// 1000ms in one sec, 1000x60x60 = 3600000ms = 1hour 300000 = 5min
unsigned long timeLimit = 60000;
void setup() {
Serial.begin(9600);
display.setBrightness(0x0d);
display.setSegments(OFF);
pinMode(gameled, OUTPUT);
}
void countdown() {
unsigned long timeRemaining = timeLimit - millis();
while (timeRemaining > 0) {
int seconds = numberofseconds(timeRemaining);
int minutes = numberofminutes(timeRemaining);
display.showNumberDecEx(seconds, 0, true, 2, 2);
display.showNumberDecEx(minutes, 0x80>>3, true, 2, 0);
timeRemaining = timeLimit - millis();
}
}
void displayText() {
display.setSegments(PLAY);
delay(2000);
}
void loop() {
displayText();
countdown();
digitalWrite(gameled, HIGH);
}
I'm using a TM1637 module for the display.