/*
* Project: Project_interrupt
* Author: Jane-Maree Howard
* Date: Monday 21/11/2011
* Platform: Arduino 22
* Purpose: To demonstrate an interrupt on Digital pin 3
* Operation: Description: Connect a 20kilOhm resistor from
* digital pin3 to digital pin13!
* Earlier problem solved as we now have a hardware feedback
* from OUTPUT digi-pin13 to INPUT digi-pin3,
* to which the interrupt is attached.
* The digital flip-flop occurs every second, is fed to digi-pin3,
* which registers the change & triggers the interrupt,
* which, in turn, calls blink() where the pin state variable is flipped.
* This state change is fed back via digi-pin13 to digi-pin3, triggering
* the interrupt once again.
*/
int iPin13 = 13;
int iPin3 = 3;
volatile int iState = LOW;
void setup()
{
// open Serial port
Serial.begin(9600);
// set pin13, pin3 as OUTPUTs
pinMode(iPin13, OUTPUT);
pinMode(iPin3, INPUT);
// interrupt1 calls blink() when pin13 flip-flops
attachInterrupt(1, blink, CHANGE);
digitalWrite(iPin3, iState);
Serial.println("\nStart\n");
}//setup()
void loop()
{
// delay 1 second
delay(1000);
// in effect, flip pin13
Serial.println(iState);
digitalWrite(iPin13, iState);
digitalWrite(iPin3, iState);
}//loop()
void blink()
{
// flip value to trigger interrupt
iState = !iState;
}//blink()
//END
i finally cracked it!
most annoying though..
..but when i wondered about which pin the interrupt operated on, i went back to the appropriate page..
..where i saw that interrupt-0 can be attached to digital pin 2, & interrupt-1 to digital pin 3.
after that, it was pretty much plain sailing - the feedback resistor instead of some weird software, & as can be seen at left, it works beeootifly-thank-yew!
on to my next problem: how can i use LDR hardware to trigger an interrupt (for my "fridge door open" stuff!
{sigh of relief!}.
hmmm.. i wonder if s FET could be used to trigger the interrupt if the Drain is connected to Dpin3, source to Dpin13, & the Base to an LDR voltage divider network..
ReplyDeleteFETs have a pretty high internal resistance..
Hmmmmmm..
if you're wondering why i don't just use an Analog pin, it's because i've only got 6 of them, 2 of them (4 & 5) are 'booked' for TWI, leaving only four for my thermistors..
ReplyDelete..i don't want to 'waste' one on an interrupt, even tho it'd be simpler..