Hey everyone! I'm using a TM1637 4 digit seven segment display to make a count-down timer.
But I am unable to get the ":" in-between the min and seconds to light.
can anyone help me with how I could do this?
I'm using the TM1637 module (pins 6,7) and the <TM1637Display.h> library.
the clock starts by Displaying text (in this example it's the word "play") and then counts down from 5:00 to 0, and then flashes "0000" and lights an LED (pin13).
I'd like the ":" to be displayed during the countdown but obviously not when it displays the text at start.
#include <TM1637Display.h>
#define numberofseconds(time) ((time / 1000) % 60)
#define numberofminutes(time) (((time / 1000) /60) % 60)
#define gameled 13
const uint8_t ZEROS[] = {0b00111111, 0b00111111, 0b00111111, 0b00111111 };
const uint8_t OFF[] = {0, 0, 0, 0};
// in the libary, the byte order is .GFEDCBA
// .GFEDCBA
const uint8_t PLAY[] = {B01110011, B00111000, B01110111, B01101110};
//clock, data
TM1637Display display(7, 6);
// 1000ms in one sec, 1000x60x60 = 3600000ms = 1hour 300000 = 5min
const unsigned long timeLimit = 60000;
unsigned long timeStart;
bool bcountdownDone;
void setup()
{
Serial.begin(9600);
display.setBrightness(0x0d);
display.setSegments(OFF);
pinMode(gameled, OUTPUT);
display.setSegments(PLAY);
timeStart = millis(); //used to time display of PLAY
}//setup
#define ST_SHOWPLAY 0
#define ST_COUNT 1
#define ST_FLASH_ZEROS 2
void countdown()
{
static byte
stateCountdown = ST_SHOWPLAY;
//the vars used by countdown state
static bool
bcountdownDone = false;
int
seconds,
minutes;
static int
lastseconds = -1;
unsigned long
timeRemaining,
timeElapsed;
switch( stateCountdown )
{
case ST_SHOWPLAY:
//PLAY is showing from setup...time to start countdown?
if( (millis() - timeStart) > 2000 )
{
stateCountdown = ST_COUNT;
timeStart = millis();
}//if
break;
case ST_COUNT:
timeElapsed = millis() - timeStart;
timeRemaining = timeLimit - timeElapsed;
seconds = numberofseconds(timeRemaining);
minutes = numberofminutes(timeRemaining);
if( seconds != lastseconds )
{
lastseconds = seconds;
display.showNumberDecEx(seconds, 0, true, 2, 2);
display.showNumberDecEx(minutes, 0x80>>3, true, 2, 0);
}//if
if( seconds == 0 && minutes == 0 )
{
digitalWrite( gameled, HIGH );
stateCountdown = ST_FLASH_ZEROS;
}//if
break;
case ST_FLASH_ZEROS:
FlashZeros();
break;
}//switch
}//countdown
void loop()
{
countdown();
}//loop
void FlashZeros( void )
{
static bool
bState = true; //reflect that countdown left digits at 0000 to begin
static unsigned long
timeFlash = 0;
if( millis() - timeFlash > 300 )
{
timeFlash = millis();
if( bState )
{
display.setSegments(OFF);
bState = false;
}//if
else
{
display.setSegments(ZEROS);
bState = true;
}//else
}//if
}//FlashZeros