--- /dev/null
+boolean toggle1 = 0;
+
+void setup() {
+ pinMode(13, OUTPUT);
+ noInterrupts(); //cli(); // Stop reception of interrupts
+
+ // Set Timer 1 Control registers and counter to 0
+ TCCR1A = 0;
+ TCCR1B = 0;
+ TCNT1 = 0;
+
+ // Set compare match value = Fclk_io / (Fout * Prescaler) - 1
+ OCR1A = 15624; // = (16MHz) / (1 * 1024) - 1
+ TIMSK1 |= (1 << OCIE1A); // Enable compare match interrupt
+
+ // Set Timer 1 Mode of operation and clock prescalers
+ TCCR1B |= (1 << WGM12); // Mode 4
+ TCCR1B |= (1 << CS12) | (1 << CS10); // Set prescaler to 1024 (=> enable the clock)
+
+
+ interrupts(); //sei();
+}
+
+void loop() {
+ // put your main code here, to run repeatedly:
+}
+
+ISR(TIMER1_COMPA_vect){//timer1 interrupt 1Hz toggles pin 13 (LED)
+//generates pulse wave of frequency 1Hz/2 = 0.5kHz (takes two cycles for full wave- toggle high then toggle low)
+ if (toggle1){
+ digitalWrite(13,HIGH);
+ toggle1 = 0;
+ }
+ else{
+ digitalWrite(13,LOW);
+ toggle1 = 1;
+ }
+}