I am trying to use 4 interrupts on arduino mega wired to a 2.4 MCUFRIEND TFT Display. When I try to setup the interrupts the TFT Displays partially initialize then stops, tft.fillScreen(BLACK); fills the screen very slow then nothing else is displayed on the screen. The code after tft.fillScreen(BLACK) runs perfectly but nothing is displayed on the scrren.
Any help will be apprecieted.
int touch1 = 0;
int isr_flag1 = 0;
int isr_flag2 = 0;
const int commandPin = 18; //connects to digital pin 10 on Nano
//const int splash1 = 3; //connects to touch switch 1
const int splash2 = 20; //connects to touch switch 2
void setup() {
Serial.begin(57600);
SPI.begin();
pinMode(Rec_led, OUTPUT);
digitalWrite(Rec_led, LOW);
pinMode(XMTR_led, OUTPUT);
digitalWrite(XMTR_led, LOW);
pinMode(commandPin, INPUT);
pinMode(splash2, INPUT);
attachInterrupt(5, interruptRoutine1, LOW); //connects to digital pin 10 on nano (interrupt pin 18, interrupt 5
attachInterrupt(3, interruptRoutine2, HIGH); //connects to TOUCH SWITCH (interrupt pin 20, interrupt 3
tft.reset();
ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
// if (ID == 0xD3D3) ID = 0x9481; // write-only shield
if (ID == 0xD3D3) ID = 0x9486; // write-only shield
tft.begin(ID);
tft.setRotation(1);
tft.fillScreen(BLACK);
tft.setTextWrap(false); // Don't wrap text to next line
tft.setTextSize(2); // large letters
}
void loop() {
//Interrupt Routines
//Get PCF8574 Data If Available
if ( isr_flag1 == 1 ) {
detachInterrupt(5);
handlePCFIn();
isr_flag1 = 0;
attachInterrupt(5, interruptRoutine1, LOW); //connects to digital pin 10 on nano (interrupt pin 18, interrupt 5
}
//Handle Touch Interrupt
if ( isr_flag2 == 1 ) {
detachInterrupt(3);
handleTouch1();
isr_flag2 = 0;
attachInterrupt(3, interruptRoutine2, HIGH); //connects to TOUCH SWITCH 2 (interrupt pin 20, interrupt 3
}
tft.setCursor(69, 29);
tft.setTextColor(YELLOW, BLACK); tft.setTextSize(2);
tft.println("PCF DATA =");
tft.println(NUM);
tft.setCursor(80, 49);
tft.setTextColor(GREEN);
tft.println("SwitchScreen = ");
tft.println(switchScreen);
}
//ISR Routine for Command Input PCF8574
void interruptRoutine1() {
isr_flag1 = 1;
}
//ISR Routine for Touch Switch 1
void interruptRoutine2() {
isr_flag2 = 1;
header = 0; //set main screen header value
}
//PCF8574
void handlePCFIn() {
switchScreen = 1; //set switchScreen to 1 if voice command received, change from swicthScreen 2 or swicthScreen 2
Wire.requestFrom(PCF_address, 1);
if (Wire.available())
NUM = Wire.read();
Wire.endTransmission();
Serial.print("NUM = ");
Serial.println(NUM);
}
//Touch 1
void handleTouch1() {
if (touch1 == 0) {
switchScreen = 2;
++touch1;
}
else if (touch1 == 1) {
switchScreen = 1;
--touch1;
}
}