#include <TM1637Display.h>
// TM1637 Module connection pins (Digital Pins)
#define CLK 5
#define DIO 6
TM1637Display display(CLK, DIO);
int bt =3;
int led = 13;
int state = 0;
const uint8_t SEG_DONE = {
SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O
SEG_C | SEG_E | SEG_G, // n
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E
};
// time calc
#define numberOfSeconds(time) ((time / 1000) % 60)
#define numberOfMinutes(time) ((time / 1000) / 60)
// hold time selected in ms.
unsigned long timeLimit = 600000;// 1000601 = 10mins
void setup() {
pinMode(led,OUTPUT);
pinMode(bt,INPUT);
// Setup serial
Serial.begin(115200);
delay(50);
Serial.println("-----------Timer Arduino Comms up------------");
//display setup
display.setBrightness(4); // LED 밝기조정 0~6
//display.setBrightness(0x0c);
display.showNumberDecEx(0, 0x40, true); //64
}
void loop() {
int value = digitalRead(bt);
if(value == LOW){
if(state ==0){
state = 1;}
else if (state == 1){
state = 0;}
delay(500);
}
if(state == 0){
digitalWrite(led,LOW);}
else if(state == 1){
digitalWrite(led,HIGH);}
for (long i = timeLimit; i > 0; i=i-1000) // data type = long
{
// To display the countdown in mm:ss format, separate the parts
int seconds = numberOfSeconds(i);
int minutes = numberOfMinutes(i);
Serial.println(i);
// 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 >> 1), true, 2, 0) ; // turn on colon 원본은 0x80 >> 3 인데 콜론이 on 되지 않아 0x80 >> 1 로 변경
delay(1000);
}
display.setSegments(SEG_DONE);
delay(2000);
timeLimit = 0;
}