#include "fDigitsSegtPin.h"
fDigitsSegtPin Display(6, 5, 9, 4, 8, 13, 3, 12, 11, 7, 2, 10);
const int StartStop = 1;
const int Reset = 0;
int lastStartStop = LOW;
int curStartStop = LOW;
int lastReset = LOW;
int curReset = LOW;
bool StopwatchWork = false;
int debounce(int last, int buttonNum){
int current = digitalRead(buttonNum);
if(last != current){
delay(5);
current = digitalRead(buttonNum);
}
return current;
}
void setup()
{
Display.begin();
pinMode(StartStop, INPUT);
pinMode(Reset, INPUT);
}
void loop()
{
static unsigned long timer = millis(); //текущее время
static float seconds = 0; //время, отображаемое на индикаторе
curStartStop = debounce(lastStartStop, StartStop);
if(lastStartStop == HIGH && curStartStop == LOW){
StopwatchWork = !StopwatchWork;
timer = millis();
}
lastStartStop = curStartStop;
if(StopwatchWork == false){
curReset = debounce(lastReset, Reset);
if(lastReset == HIGH && curReset == LOW){
seconds = 0;
}
lastReset = curReset;
} else{
if (millis() - timer >= 1000) //прошло 100 мс
{
timer += 1000;
seconds+=1;
if (seconds >= 9999) // выход из диапазона
{
seconds = 0;
}
}
}
Display.print(seconds/100); //периодический вызов функции в основном цикле
}