22 April 2010

Week 8 - Lab 1: External Interrupts

Setting Up the Interrupts

/*
* Project: Week-08_Lab-1_ExternalInterrupts
* Author: Jane-Maree Howard
* Date: Monday 18/04/2010
* Platform: Arduino 18
* Purpose: To do nothing apart from demonstrating ISRs
(Interrupt Service Rountines).
For each of the 2 interrupt lines (0 & 1), its ISR
outputs a string to the Serial Monitor which identifies
the interrupt line number to which the ISR is attached
*/
const int buttonPin = 2; // Interrupt 0 - pushbutton pin
const int otherPin = 3; // Interrupt 1 - 'somethingElse' pin

void setup()
{
Serial.begin(9600);
// initialise Digital Pins
pinMode(buttonPin, INPUT);
pinMode(otherPin, INPUT);
// attach Interrupts
attachInterrupt(0, SM_Output_0, LOW);
attachInterrupt(1, SM_Output_1, LOW);
}//setup()

void loop()
{
}//loop()

/* Interrupt Service Routines */
// Output 0
void SM_Output_0()
{
Serial.println("\tInterrupt on line 0 - LOW\n");
}//SM_Output_0()

// Output 1
void SM_Output_1()
{
Serial.println("\tInterrupt on line 1\n");
}//SM_Output_1()

3 comments:

  1. It works with the button, but i also tried to hook up a CdS-LDR & i couldn't make that work; i suspect i'll have to set up a routine to get the LDR to rigger an Interrupt pin to go LOW so the event will be recorded on the Serial Monitor as per the ISR.
    Maybe if i write that all into the ISR itself, tho' that's not recommended since ISRs should be kept as short as possible...

    ReplyDelete
  2. That was the 'somethingElse' pin in the software..
    Interrupt 1 on 'otherPin'

    ReplyDelete
  3. I should do a Fritzing Diagram, but i spent most of my time here (OASuite) downloading lumps of software (Open Office, etc) which are too large Not to Take Forever @home.
    Now i'm tired & I Wanna Go Home!!

    ReplyDelete