#include <fDigitsSegtPin.h>
// fDigitsSegtPin(E, D, DP, C, G, 4, B, 3, 2, F, A, 1)
fDigitsSegtPin Display(6, 5, 9, 4, 8, 13, 3, 12, 11, 7, 2, 10);
#define START 1
#define RESET 0
bool started = false;
int Seconds = 0;
int curr_start = LOW, curr_reset = LOW;
int last_start = LOW, last_reset = LOW;
int Debounce(int last, int button){
int current = digitalRead(button);
if(last != current){
delay(5);
current = digitalRead(button);
}
return current;
}
void Button_StartStop(){
curr_start = Debounce(last_start, START);
if(last_start == HIGH && curr_start == LOW){
started = !started;
}
last_start = curr_start;
}
void Button_Reset(){
curr_reset = Debounce(last_reset, RESET);
if(last_reset == HIGH && curr_reset == LOW && started == false){
Seconds = 0;
}
last_reset = curr_reset;
}
void Counting(){
if(started){
Seconds += 1; // 1000 мс = 1 сек
if (Seconds >= 9999) // выход из диапазона
{
Seconds = 0;
}
}
}
void setup()
{
Display.begin();
pinMode(START, INPUT);
digitalWrite(START, HIGH);
pinMode(RESET, INPUT);
digitalWrite(RESET, HIGH);
}
void loop()
{
Button_StartStop();
Button_Reset();
static unsigned long timer = millis(); //текущее время
if (millis() - timer >= 1000) //прошло 1000 мс
{
timer += 1000;
Counting();
}
Display.print(Seconds);
}