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