hi,
I wrote a simple program for Timer 1 but did not work and responded quickly.
What is the reason for not working Timer 1 in a simple program?
i use TimerOne library
#include <TimerOne.h>
//after get card (switch is on)delay 1 second and turn on led
volatile int card_in_key = 6 ;
const boolean card_in = 1 ;
boolean t1_flag = 0;
void setup()
{
delay(100);
pinMode(card_in_key,INPUT_PULLUP); // add pullup after not work timer
pinMode(7,OUTPUT);
Timer1.initialize(1000000); // 1 s
Timer1.attachInterrupt(delay_time); //
}
void loop() {
while ( digitalRead(card_in_key)== card_in )
{
delayMicroseconds(50); // add after
if (t1_flag == 0 )
{
Timer1.restart(); // restart and start not work
t1_flag = 1;
//my other code
}
}
delay(100); // delay ms added after the timer 1 not work
digitalWrite(7 , HIGH );
Timer1.stop();
t1_flag = 0 ;
}
void delay_time(){
Timer1.stop();
t1_flag = 1;
digitalWrite(7 , LOW ) ;
}