I have issues with Nokia 5110 LCD - it shuts down when using interrupts. I decided to use encoder instead of buttons for setting values, but after its first turn LCD becomes blank. I stripped sketch, where I left interrupt function for encoder, which only sets backlight for LCD. I clearly see encoder activity in port monitor, back-light is changing, but screen becomes blank.
The same code works well with buttons instead of encoder.
For display I used Adafruis library, but i changed RST pin into pin 1, because I needed pins 2 and 3.
What is wrong?
By the way, if you "uncomment" Serial.println in the end of loop(), screen also blank. I have doubts the reason is somewhere there.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <Rotary.h>
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 1);
Rotary r = Rotary(2, 3);
int light = 90;
int bl=9;
int result = 1;
volatile int enc = 0;
void setup()
{
Serial.begin(9600);
display.begin();
PCICR |= (1 << PCIE2);
PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
sei();
pinMode(mode, INPUT); //Mode button
pinMode(bl, OUTPUT); //LCD light
analogWrite(bl, light);
}// Setup
void loop() {
display.clearDisplay();
if (enc == 1)
{
Serial.println(enc);
if (light<120) light +=30;
if (light>=120) light = 150;
}
if (enc == -1)
{
Serial.println(enc);
if (light >30 ) light -=30;
if (light<=30) light = 0;
}
analogWrite(bl, light);
display.println(light);
display.display();
//Serial.println(light);
} //End loop
ISR(PCINT2_vect)
{
unsigned char result = r.process();
if (result == DIR_NONE) enc =0;
else if (result == DIR_CW) enc =1;
else if (result == DIR_CCW) enc =-1;
}