Koduino
Functions
Timer interrupts

Detailed Description

Usage

  1. Call attachTimerInterrupt()

Example: Parallel blink

const int ledg = PA8;
const int ledy = PD8;
const int ledr = PB15;
void blinky() {
digitalWrite(ledy, TOGGLE);
}
void blinkr() {
digitalWrite(ledr, TOGGLE);
}
void setup() {
pinMode(ledg, OUTPUT);
pinMode(ledy, OUTPUT);
pinMode(ledr, OUTPUT);
attachTimerInterrupt(0, blinky, 4);
attachTimerInterrupt(1, blinkr, 10000);
}
void loop() {
digitalWrite(ledg, TOGGLE);
delay(1000);
}
Authors
Avik De avikd.nosp@m.e@gm.nosp@m.ail.c.nosp@m.om

This file is part of koduino https://github.com/avikde/koduino

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, see http://www.gnu.org/licenses/.

Functions

void attachTimerInterrupt (uint8_t i, ISRType ISR, int freqHz)
 Begin a timer interrupt. More...
 
void detachTimerInterrupt (uint8_t i)
 Disable a timer interrupt. More...
 
void noTimerInterrupts ()
 Disable all timer interrupts. More...
 
void timerInterrupts ()
 Re-enable timer interrupts. More...
 

Function Documentation

void attachTimerInterrupt ( uint8_t  i,
ISRType  ISR,
int  freqHz 
)

Begin a timer interrupt.

Starts calling the interrupt handler specified at the frequency specified.

Parameters
iOne of 0, 1, or 2 (#3 is used for pwmIn, and #4 is used for the system clock)
ISRInterrupt handler (similar to usage for external interrupts)
freqHzFrequency in Hz, between ~0.061Hz and ~36MHz.
void detachTimerInterrupt ( uint8_t  i)

Disable a timer interrupt.

This forgets the attached interrupt handler, i.e. to restart, attachTimerInterrupt() has to be called again!

Parameters
iOne of 0, 1, or 2
void noTimerInterrupts ( )

Disable all timer interrupts.

Call this to temporarily suspend all timer interrupts, and timerInterrupts() to resume them again

void timerInterrupts ( )

Re-enable timer interrupts.

To be called after noTimerInterrupts()