External Interrupt and LiquidCrystal

Hi There,

I'd like to have an external interrupt induce something (eg variable++) and be able to show something (eg variable's new value) on an LCD. I wrote code, which I thought should work, but after some frustration with unexpected behavior I wrote a simple sketch to debug:

#include <LiquidCrystal.h>

const int interruptPin = 2;
const int ledPin = 13;
LiquidCrystal lcd(12, 3, 4, 5, 6, 7);

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16,2);
  lcd.clear();
  pinMode(interruptPin, INPUT);
  pinMode(ledPin, OUTPUT);
  attachInterrupt(0, interruptFunc, RISING);
}

void loop() {
  // put your main code here, to run repeatedly: 
  lcd.clear();
  delay(100);
}

void interruptFunc(){
  digitalWrite(ledPin, digitalRead(ledPin) ^ 1);
}

For simplicity I've connected a debounced button to pin 2. I'd expect that every time I push the button I get a state change on the led. If I comment out the lcd.clear() I get expected behavior. If, however, I leave it in then my led gets into some funky and seemingly random intermediary state where it's about 1/2 as bright as it would be. Sometimes I can see the flicker and sometimes I can't. Presumably I'm triggering tons of external interrupts and I'm effectively putting a square wave out on the led and not DC. My question is how and why am I seeing this behavior? What does lcd.clear() (or any of the lcd commands for that matter -- clear() is just a canonical example) have to do with external interrupts? Thanks a lot!

D

Do you have a pull-up or pull-down resistor? If not, the pin is probably floating, and generating lots of interrupts.

What is the purpose of clearing screen 10 times a second?

To Nick: yes I have a pullup. The switch is debounced with a 1k pull up to +5V and a .1uF cap to GND.

To Liudr: Per my original post clear() is simply an example. Functionality is identical if I print a value to the LCD, which is the ultimate goal.

Yes, but clearing the LCD 10 times a second is likely to make it look dim.

To Nick: the state of the lcd is inconsequential right now -- you can change from clear() to print(someval) and you'll get the identical behavior. The question is why does calling something LCD related seemingly trigger my ISR?

Well this is an embarrassing bug. I had a led on the output of the switch. The current draw of the led was such that I had a large voltage drop on the 10k pullup. That led me to have a V that sat right in the undetermined middle of the 0-5, which triggered tons of random interrupts. Unclear at this point why lcd related commands caused different behavior vis-a-vis amount of interrupting, but seemingly problem solved.