I am working in my project and i want to use Timer2 interrupt every 100ms to get new measurement from the output of my 5 sensors which connected to pins A1,A2,A3,A4,A5.
I read in some article that using delay instruction is not as good as using timers'Interruptions so, I tried this code put it didn't work properly :
void setup(){
cli();
TCCR2A = 0;
TCCR2B = 0;
TCNT2 = 0;
OCR2A = 99;
TCCR2A |= (1 << WGM21);
TCCR2B |= (1 << CS21);
TIMSK2 |= (1 << OCIE2A);
sei();
Serial.begin(9600);
}
void loop()
{
Serial.print(digitalRead(1));
Serial.print(' ');
Serial.print(digitalRead(2));
Serial.print(' ');
Serial.print(digitalRead(3));
Serial.print(' ');
Serial.print(digitalRead(4));
Serial.print(' ');
Serial.print(digitalRead(5));
Serial.println(' ');
}
ISR(TIMER2_COMPA_vect){ ..code here.. }
. However with your current setting the ISR gets called once every 0.5ms.