#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SdFat.h>
#include <Adafruit_SPIFlash.h>
#include <Adafruit_ImageReader.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#define USE_SD_CARD
#define SD_CS 4
#define TFT_CS 10
#define TFT_DC 8
#define TFT_RST 9
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {22, 24, 26, 28};
byte colPins[COLS] = {23, 25, 27, 29};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
LiquidCrystal lcd(7, 6, 5, 3, 2, 11);
#if defined(USE_SD_CARD)
SdFat SD;
Adafruit_ImageReader reader(SD);
#else
#if defined(__SAMD51__) || defined(NRF52840_XXAA)
Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS,
PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
#else
#if (SPI_INTERFACES_COUNT == 1)
Adafruit_FlashTransport_SPI flashTransport(SS, &SPI);
#else
Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1);
#endif
#endif
Adafruit_SPIFlash flash(&flashTransport);
FatFileSystem filesys;
Adafruit_ImageReader reader(filesys);
#endif
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
Adafruit_Image img;
int32_t width = 0,
height = 0;
void setup() {
ImageReturnCode stat;
Serial.begin(9600);
#if !defined(ESP32)
while (!Serial);
#endif
tft.begin();
Serial.print(F("Initializing filesystem..."));
#if defined(USE_SD_CARD)
if (!SD.begin(SD_CS, SD_SCK_MHZ(25))) {
Serial.println(F("SD begin() failed"));
for (;;);
}
#else
if (!flash.begin()) {
Serial.println(F("flash begin() failed"));
for (;;);
}
if (!filesys.begin(&flash)) {
Serial.println(F("filesys begin() failed"));
for (;;);
}
#endif
Serial.println(F("OK!"));
tft.fillScreen(ILI9341_BLUE);
tft.setRotation(4);
Serial.print(F("Loading image to screen..."));
stat = reader.drawBMP("/parrot.bmp", tft, 0, 0);
reader.printStatus(stat);
// (Absolute path isn't necessary on most devices, but something
// with the ESP32 SD library seems to require it.)
reader.printStatus(stat); // How'd we do?
// Query the dimensions of image 'rgbwheel.bmp' WITHOUT loading to screen:
Serial.print(F("Querying /cat.bmp image size..."));
stat = reader.bmpDimensions("/cat.bmp", &width, &height);
reader.printStatus(stat); // How'd we do?
if(stat == IMAGE_SUCCESS) { // If it worked, print image size...
Serial.print(F("Image dimensions: "));
Serial.print(width);
Serial.write('x');
Serial.println(height);
}
lcd.begin(20, 4);
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("4 lines, 20 cols");
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey) {
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Key pressed: ");
lcd.print(customKey);
}
}