/*
This program turns on and off a LED on pin 13 each 1 second using an internal timer
Dieses Programm schaltet mithilfe eines internen Timers alle 1 Sekunde eine LED an Pin 13 ein und aus
*/
int timer=0;
bool state=0;
void setup() {
pinMode(13,OUTPUT);
TCCR0A=(1<<WGM01); //Set the CTC mode //Stellen Sie den CTC-Modus ein
OCR0A=0xF9; //Value for ORC0A for 1ms//Wert für ORC0A für 1ms
TIMSK0|=(1<<OCIE0A); //Set the interrupt request//Stellen Sie die Interrupt-Anfrage ein
sei(); //Enable interrupt//Interrupt aktivieren
TCCR0B|=(1<<CS01); //Set the prescale 1/64 clock//Stellen Sie die Vorskalierung auf 1/64 ein
TCCR0B|=(1<<CS00);
}
void loop() {
//in this way you can count 1 second because the nterrupt request is each 1ms
//Auf diese Weise können Sie 1 Sekunde zählen, da die Interrupt-Anforderung alle 1 ms erfolgt
if(timer>500){
state=!state;
timer=0;
}
digitalWrite(13,state);
}
ISR(TIMER0_COMPA_vect){ //This is the interrupt request//Dies ist die Interrupt-Anfrage
timer++;
}