Hi, I have similar problem with my Adafruit 3.5" 320x480 Color TFT Touchscreen in SPI mode. In my project additionally I tried use typical KeyPad 4x4 connected by 8 PIN in my Arduino MEGA. I use Keypad.h library and getKey() function to entry number from KeyPad. When I use the getKey() function, the display stops responding to all my calls. At the same time, the Serial communication is working properly.
Below the code.
// SPI
#include <SPI.h>
// TFT
#include "Adafruit_GFX.h"
#include "Adafruit_HX8357.h"
// These are 'flexible' lines that can be changed
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8 // RST can be set to -1 if you tie it to Arduino's reset
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'#','0','*','D'}
};
byte rowPins[ROWS] = {53,51,49,47}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {45,43,41,39}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
char buff[11];
void setup(){
Serial.begin(9600);
tft.begin(HX8357D); // TFT Start
tft.setRotation(1); // TFT Rotation
tft.fillScreen(HX8357_BLACK); // TFT CLS
tft.setCursor(100,100); // Cursor Position
tft.setTextColor(HX8357_WHITE); // Text Color
tft.setTextSize(6); // Text Size
tft.println("Hello Test"); // Text Example TFT OK
for (int i=0 ; i < 11 ; i++) {
buff[ i ] = getKey();
Serial.print(buff[i]);
tft.println(buff[i]);
}
Serial.print("Serial Output is OK");
tft.println("TFT Output isn't OK"); // TFT Frozen
Serial.print("Serial Output is OK");
}
void loop()
{
}
char getKey()
{
char key = NO_KEY;
while ( key == NO_KEY ) {
key = keypad.getKey();
}
return( key );
}
void tekst()
{
tft.fillScreen(HX8357_BLUE);
tft.setCursor(180, 190);
tft.setTextColor(HX8357_WHITE);
tft.setTextSize(2);
tft.print("Hello Test");
}