different delay

Hello all,

I am new to Arduino...

playing with Timer1...

using 2 LEDs... one on pin 13 , second on pin 5...

Wrote little code:

 //UNO

#include <TimerOne.h>

int a;
int a1;
int b;
int b1;
//////////////////////////////////////////////////////
void setup() {

  Timer1.initialize(5000000);
  Timer1.attachInterrupt(chk);
 
  pinMode(13,OUTPUT);
  pinMode(5,OUTPUT);
}
///////////////////////////////////////////////////////
void loop(){
  for (a=0; a<=50; a++){
    digitalWrite(13,a1);
    a1 = a1 ^ 1;
    delay(200);  
  }
} 
//////////////////////////////////////////////////////
void chk(){

  for (a=0; a<=50; a++){
    digitalWrite(5,b1);
    b1 = b1 ^ 1;
    delay(200);  
  }

}

Can somebody explain me why in Void loop - LED blink in 200mS rhythm and in void chk, LED on pin 5 blink so fast that it looks like 1 blink ?

if you put 20000 instead of 200 in void chk then you can see it realy blinks...

THX

Thx Delta_G...

That was fast :slight_smile:

So, as I have something serious on my mind, where can I find what is also dependable of interrupts... What am I not supposed to put in that part of program?

where can I find what is also dependable of interrupts... What am I not supposed to put in that part of program?

Usefull....

Noticed that Serial is acting wierd....

TNX again.

if you want (near) identical behavior then within setup()Timer1.initialize(200000UL); and change void chk() to

void chk(){
   digitalWrite(5,b1);
   b1 = b1 ^ 1;
}

Yes, Deva_Rishi...

so interrupt would happen every 200mS and I will have change on pin 5...

My point was to understand behaviour of "delay" in ISR.

TNX anyway...

Lesson learned = dont use Delay (or Serial) in ISR

:slight_smile: