Goodmorning,
I want to make a countdown timer with timer1, but I am inexperienced with the library.
I have done one program but It doesn't work:
#include "TimerOne.h"
volatile int STbutton = 22;
int CDtimer = 0;
int Tcount = 10;
void setup(){
Timer1.initialize(1000000);
Timer1.attachInterrupt(clock);
pinMode (STbutton, INPUT);
Serial.begin(9600);
}
void clock(){
if ( digitalRead(STbutton) == HIGH ){
CDtimer = Tcount - 1;
}
}
void loop(){
if ( CDtimer >= 0 ){
Serial.print(CDtimer);
Serial.println(" sec");
}
}
The program that i want to do It's simple:
Whenever STbutton == HIGH a timer start counting down every 1sec
Please any suggestions on the program or any help with the library.