/*Nastavi časovnik Timer2 tako, da bo prožil prekinitve 
tako, da bo LED utripala s frekvenco 0,5 Hz. Naredi 
primer z delilnikom 256 in še z 64. Kreiraj funkcijo 
onTimer, ki bo merila čas trajanja pulza in čas 
trajanja pavze.*/

/*
f = fclk / (N * (256 - TCNT))
f = 1 Hz
N1 = 256
N2 = 64
fclk = 16000000
S1 = ?
S2 = ?
_________________________________

TCNT = 256 - 16 MHz / (256 * 1Hz * S)
TCNT = 256 - 16 MHz / (256 * 1Hz * 500)
TCNT = 256 - 125
              manjše od 256, večje od 0, celo število
TCNT = 131 

TCNT2 = 256 - 16000000 / (64 * 1 * 1000)

TCNT = 256 - 16MHz / (256 * 1Hz * 500) // delilnik 256 skalar 500
ali
TCNT = 256 - 16MHz / (256 * 1 * 1000) // delilnik 64 in skalar 1000
*/
/*

delilnik 256

void setup() {
  Serial.begin(115200);
  DDRD |= (1 << PD7);
  cli();
  TCCR2A = 0;
  TCCR2B = 0;
  TCCR2B |= (1 << CS22) + (1 << CS21) + (0 << CS20);
  TCNT2 = 131;
  TIMSK2 |= (1 << TOIE2);
  sei();
}

ISR(TIMER2_OVF_vect) {
  TCNT2 = 131;
  static unsigned long stevec = 0;
  stevec ++;
  if (stevec >= 500) {
    PORTD ^= (1 << PD7);
    stevec = 0;
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}
*/



void setup() {
  Serial.begin(115200);
  DDRD |= (1 << PD7);
  cli();
  TCCR2A = 0;
  TCCR2B = 0;
  TCCR2B |= (1 << CS22) + (0 << CS21) + (0 << CS20);
  TCNT2 = 6;
  TIMSK2 |= (1 << TOIE2);
  sei();
}

ISR(TIMER2_OVF_vect) {
  TCNT2 = 6;
  static unsigned long stevec = 0;
  stevec ++;
  if (stevec >= 1000) {
    PORTD ^= (1 << PD7);
    stevec = 0;
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}