Hi
I am wondering how shall I declare a global variable that can be changed within an interrupt.
Any advice or warnings regarding this?
Hi
I am wondering how shall I declare a global variable that can be changed within an interrupt.
Any advice or warnings regarding this?
How will the interrupt change the variable? increment/decrement it?
HazardsMind:
How will the interrupt change the variable? increment/decrement it?
//ICR interrupt vector
ISR(TIMER1_CAPT_vect){
isr_increment++;
if (isr_increment > 5)
{
isr_increment = 0;
frequency++
}
Coding badly solution may be the most logical
void loop()
cli();
frequency=frequency1;
sei();
frequency1...
...
most important hints in a nutshell
volatile unsigned long counter = 0;
ISR()
{
counter++;
}
loop()
{
cli();
unsigned long workcopy = counter;
sei();
...
}
Coding badlyNick Gammon's solution may be the most logical