/* example of interrupt function using Arduino 22 */
int iPin = 13;
volatile int iState = LOW;
void setup()
{
// open Serial
Serial.begin(9600);
// set pin13 as OUTPUT
pinMode(iPin, OUTPUT);
// interrupt1 calls blink() when pin13 flip-flops
attachInterrupt(1, blink, CHANGE);
digitalWrite(iPin, 1);
Serial.println("\nStart\n");
}//setup()
void loop()
{
// delay 1 second
delay(1000);
// in effect, flip pin13
Serial.println(iState);
digitalWrite(iPin, iState);
}//loop()
void blink()
{
// flip value to trigger interrupt
iState = !iState;
}//blink()
//END
i have been trying to get this interrupt program to work - it doesn't alternate the way i think/assume it should.
it just changes at random, sometimes acting like a touch or proximity switch!
i'm baffled :-?
here's where the example code came from - i've modified it to produce a serial monitor output, & inserted another digitalWrite() statement in the setup to try to get the thing triggering regularly..
..but it doesn't {sigh}..
i just WAVE MY HAND AT IT, & it flip-flops
ReplyDeleteGRRRR!