// Timer with an ISR example
// Author: Nick Gammon
// Date: 13th January 2012
// Modified: 19 October 2014
//#include <digitalWriteFast.h>
const byte FIRE_SENSOR = 2; // note this is interrupt 0
const byte SPARKPLUG = 9;
void activateInterrupt0 ()
{
EICRA &= ~(bit(ISC00) | bit (ISC01)); // clear existing flags
EICRA |= bit (ISC01); // set wanted flags (falling level interrupt)
EIFR = bit (INTF0); // clear flag for interrupt 0
EIMSK |= bit (INT0); // enable it
} // end of activateInterrupt0
void deactivateInterrupt0 ()
{
EIMSK &= ~bit (INT0); // disable it
} // end of deactivateInterrupt0
ISR (INT0_vect)
{
digitalWrite (SPARKPLUG, HIGH);
} // end of ISR (INT0_vect)
void setup()
{
//TCCR1A = 0; // normal mode
//TCCR1B = 0; // stop timer
//TIMSK1 = 0; // cancel timer interrupt
pinMode (SPARKPLUG, OUTPUT);
pinMode (FIRE_SENSOR, INPUT_PULLUP);
activateInterrupt0 ();
} // end of setup
void loop()
{
// read sensors, compute time to fire spark
digitalWrite (SPARKPLUG, LOW);
} // end of loop