Prior to using interrupts for the first time in project, I did a simple test using the code below.
The interrupt fires constantly and the LCD shows variable "i" incrementing rapidly.
This happens with pin D0 connected to my switch debounce circuit (shown in the upper right in the photo below). It also happens with pin D0 connected directly to ground or to +Vcc via 10k resistor.
My little commented-out test works - I can read pin D0 and make the LED change state that way.
The same problem occurs if I use pin D1.
Google searching shows constant firing when pin is unconnected (due to noise), but that's not my issue since I'm grounding (or holding high) via resistor.
Any suggestions would be appreciated!
// simple interrupt test
//
// prior to upload and when FTDI is attached
// disconnect wires to interrupt pins
// (used by FTDI for serial comm)// includes
#include <LiquidCrystal.h>// defines
int pin = 13;
volatile int i = 0;
volatile int state = LOW;// the following puts all LCD wires on the same side of Ardweeny
LiquidCrystal lcd(2, 3, 5, 4, 6, 7);void setup()
{
pinMode(pin, OUTPUT);
attachInterrupt(0, blink, CHANGE);lcd.begin(8, 2);
lcd.setCursor(0, 0);
lcd.print("hello!");}
void loop()
{
// TEST
// can we turn off interrupts
// and just read the pin and change the state
// based on pin state? yes...this works
// state = digitalRead(0);digitalWrite(pin, state);
lcd.setCursor(0, 1);
lcd.print("i=");
lcd.print(i);}
void blink()
{
//ISR..toggle state on interrupt and increment counter
state = !state;
i += 1;
}