#include <TM1637.h>
/*
This simulation program doesn't work, but it works with the 7segment and button.
There should be a 100 nF capacitor connected in parall with the button.
TM1637_RT library should be installed in the "Library Manager" tab first.
In Ver.0.3.8, ini() method is replaced by begin() method.
For details, refer to https://github.com/RobTillaart/TM1637_RT, Readme.md
*/
// pin declaration
#define CLK 13
#define DIO 3
#define B_PIN 2
// create a tm1637 object
TM1637 tm;
volatile long counter = 0; //displayInt() method asks for long type.
void push_int() //ISR
{
delayMicroseconds(1000000);
counter++;
}
void setup() {
// put your setup code here, to run once:
pinMode(B_PIN, INPUT_PULLUP);
tm.begin(CLK, DIO, 4);
tm.displayClear();
attachInterrupt(digitalPinToInterrupt(B_PIN), push_int, FALLING);
}
void loop() {
// put your main code here, to run repeatedly:
if(counter <= 30)
tm.displayInt(counter);
else
counter = 0;
delay(500);
}