Functions in ISR() can't get values from loop()?

I'm implementing interrupts, but it seems that the functions in ISR() can't get the value from loop(). For example, I have the codes below:

/////////////////////////////////////////////// ISR(TIMER2_COMPA_vect){ Serial.println (a); }

void loop() { a = digitalRead(1); } ///////////////////////////////////////////////

In the serial monitor window, the program is just keeping printing 0.

I set the interrupt freq. already. What do I do to get the values of a in ISR and print them? Thank you!

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you tell us your electronics, programming, Arduino, hardware experience?

I think you need to google arduino interrupts

Thanks.. Tom.. :)

Why are you reading the Tx pin, anyway?

How do you know that 0 isn't the correct value.

DO NOT put any Serial.print statements inside an ISR. They are slow and they rely on interrupts and interrupts are turned off inside an ISR. Use the ISR to set a flag to let the rest of your program know that the ISR has happened and then do the printing after the ISR completes.

Global variables can be accessed in an ISR. Variables that are local to another function cannot.

...R