/* Matchbox-Sized Digital Timer
* DigiSpark Attiny85 linked with TM1637 Display Module
* By T.K.Hareendran
*/
#include "TM1637.h"
// Frankie Chu’s Library for TM1637 Display
// Download this library from the GitHub link shown below
// Put it inside the “arduino/libraries” folder
// https://github.com/reeedstudio/libraries/tree/master/DigitalTube //{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
//0~9,A,b,C,d,E,F // Functional for display
// Wires for display
#define CLK 0
#define DIO 1
#define Pulse 2 // Alarm Trigger Output
int timer_val=1; // Countdown value in minutes
int timer_seconds=00; // Display seconds
// Variables used to store individual numbers
int firstnum=0;
int secondnum=0;
int thirdnum=0;
int fournum=0;
TM1637 tm1637(CLK,DIO); // Create instance of the Display
void setup(){
pinMode(Pulse, OUTPUT);
digitalWrite(Pulse, LOW);
tm1637.init(); // Display Reset
tm1637.set(BRIGHT_TYPICAL); // Brightness Level
// BRIGHT_DARKEST = 0,BRIGHTEST = 7 BRIGHT_TYPICAL = 2;
tm1637.point(POINT_ON); // Centre "colons" ON
delay(1000); // Delay of 1 second
}
void loop() {
// Check if timer is elapsed
while (timer_val == 0 && timer_seconds == 0) {
tm1637.clearDisplay(); // Clear display
tm1637.display(0,0);
tm1637.display(1,0);
tm1637.display(2,0);
tm1637.display(3,0);
digitalWrite(Pulse, HIGH); // Alarm Trigger ON
delay(1000); // Wait
tm1637.clearDisplay();
digitalWrite(Pulse, LOW); // Alarm Trigger OFF
delay(500); // Wait
}
// Breakdown minutes and seconds in individual numbers
if (timer_val > 9) {
firstnum = timer_val/10%10;
secondnum = timer_val%10;
}
else {
secondnum = timer_val;
}
if (timer_seconds > 9) {
thirdnum = timer_seconds/10%10;
fournum = timer_seconds%10;
}
else {
thirdnum = 0;
fournum = timer_seconds;
}
// Show countdown on 4 digit 7 segment display
tm1637.clearDisplay(); // Clear display
if (timer_val > 9) {
tm1637.display(0,firstnum);
}
if (timer_val > 0) {
tm1637.display(1,secondnum);
}
if (timer_seconds > 9 || timer_val > 0) {
tm1637.display(2,thirdnum);
}
tm1637.display(3,fournum);
// Decrease seconds
timer_seconds=timer_seconds-1;
delay(1000); // Delay of 1 second
// Decrease timer
if (timer_seconds == -1) {
timer_val=timer_val-1;
timer_seconds=59;
}
}
// END