hello!
i am trying to make a simple timer to countdown from 20 min to 0sec. So far, eveything works and i can see that it works as it should using the serial monitor.
My problem is how do i convert the time stamp hours:min:sec to just min and sec so it will "fit" in the TM1637?
#include "Countimer.h"
#include <TM1637Display.h>
#define CLK 2
#define DIO 3
TM1637Display display(CLK, DIO);
Countimer tDown;
boolean timePause = 1;
boolean timePlay = 0;
//button setup
int startButton = 7;//pin bouton
int resetButton = 8;//
int greenLed = 13;//
//debounce
long lastDebounceTime = 0;
long debounceDelay = 30;
void setup()
{
Serial.begin(9600);
{
display.setBrightness(5);
//display.setSegments(data);
delay(50);
}
pinMode(greenLed, OUTPUT);
pinMode(startButton, INPUT_PULLUP);
pinMode(resetButton, INPUT_PULLUP);
// Count-down timer with 21s
tDown.setCounter(0, 00, 10, tDown.COUNT_DOWN, tDownComplete);
// Call print_time2() method every 1s.
tDown.setInterval(print_time2, 1000);
}
void loop()
{
tDown.run();
if ( (millis() - lastDebounceTime) > debounceDelay) {
if ((digitalRead(startButton) == 0) && timePlay == 0) {
digitalWrite(greenLed, HIGH);
timePlay = 1;
tDown.start();
lastDebounceTime = millis();
delay(100);
}
if ((digitalRead(startButton) == 0) && timePlay == 1) {
digitalWrite(greenLed, LOW);
timePlay = 0;
tDown.pause();
lastDebounceTime = millis();
delay(100);
}
if ((digitalRead(resetButton) == 0)) {
delay(50);
digitalWrite(greenLed, LOW);
timePlay = 0;
tDown.restart();
tDown.pause();
lastDebounceTime = millis();
delay(100);
}
print_time2();
}
}
void print_time2()
{
//Serial.print("tDown: ");
Serial.println(tDown.getCurrentTime());
/*
// This displays the seconds in the last two places
display.showNumberDecEx(seconds, 0, true, 2, 2);
// Display the minutes in the first two places, with colon
display.showNumberDecEx(minutes, 0x80>>3, true, 2, 0);
//delay(1000);
*/
}
void tDownComplete()
{
digitalWrite(greenLed, HIGH);
delay(500);
digitalWrite(greenLed, LOW);
delay(500);
digitalWrite(greenLed, HIGH);
delay(500);
digitalWrite(greenLed, LOW);
}