#define led_1 13
#define led_2 4
#define led_3 7
int prv=0;
int count1 = 0;
int count2 = 0;
int count3 = 0;
uint8_t flag_ms_on=1;
uint8_t flag_ms_off=0;
uint8_t flag_10ms_on=1;
uint8_t flag_10ms_off=0;
uint8_t flag_100ms_on=1;
uint8_t flag_100ms_off=0;
ISR(TIMER1_COMPA_vect) {
TCNT1=0;
OCR1A += 62;
// Serial.println(count3);
count1++;
count2++;
count3++;
//Serial.println(count1);
// Serial.println(count2);
//Serial.println(count3);
}
ISR(TIMER1_OVF_vect)
{
// TCNT1=0;
}
void time_set()
{
TCCR1B = 0;
TCCR1A = 0;
OCR1A = 62;
TCCR1B |= B00000100; // Set prescaler to 256
TIMSK1 |= B00000011; // Enable Timer1 compare match A interrupt
Serial.begin(9600);
}
void pin_dec()
{
pinMode(led_1, OUTPUT);
pinMode(led_2, OUTPUT);
pinMode(led_3, OUTPUT);
}
void setup() {
pin_dec();
time_set();
}
void loop() {
// Your main code here
// Uncomment the following line if you want to print count1 and count2
if (count1==1 && flag_ms_on==1) {
task_on(led_1);
flag_ms_off=1;
flag_ms_on=0;
count1=0;
//Serial.println( flag_ms_off);
}
if(count1==1 && flag_ms_off==1)
{
task_off(led_1);
flag_ms_on=1;
flag_ms_off=0;
count1=0;
// Serial.println(flag_ms_on);
}
if (count2==39 && flag_10ms_on==1) {
prv=count2;
task_on(led_2);
flag_10ms_off=1;
flag_10ms_on=0;
count2=0;
}
if(count2==39 && flag_10ms_off==1)
{
task_off(led_2);
flag_10ms_on=1;
flag_10ms_off=0;
count2=0;
}
if(count3==100 && flag_100ms_on==1)
{
task_on(led_3);
flag_100ms_off=1;
flag_100ms_on=0;
count3=0;
}
if( count3==100 && flag_100ms_off==1)
{
task_off(led_3);
Serial.println( flag_100ms_on=1);
flag_100ms_off=0;
count3=0;
}
}
void task_on(int led) {
digitalWrite(led, HIGH);
//prv=millis();
}
void task_off(int led)
{
digitalWrite(led, LOW);
// count1 = 0; // Reset count1
}