#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#include <SD.h>
#define TFT_SCK 18
#define TFT_MOSI 23
#define TFT_MISO 19
#define TFT_CS 22
#define TFT_DC 21
#define TFT_RESET 17
#define SD_CS_PIN 5
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RESET);
#define MY_GRAY 0x7BEF
void setup() {
Serial.begin(9600);
tft.begin();
tft.fillScreen(MY_GRAY);
delay(100);
//tft.setRotation(2); // Adjust rotation as needed
int keyX = 5;
int whiteKeyY = 5;
int blackKeyY = 20;
// Draw white keys
for (int i = 0; i < 14; i++) {
tft.fillRect(keyX, whiteKeyY, 100, 20, ILI9341_WHITE);
whiteKeyY += 12*2; // Add a 13-pixel space between each white key
}
// Draw black keys
for (int i = 0; i < 13; i++) {
if (i != 2 && i != 6 && i != 9) {
tft.fillRect(50 + keyX, blackKeyY, 50, 20, ILI9341_BLACK);
}
blackKeyY += 12*2;
}
tft.setRotation(3);
tft.setCursor(0, 30);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(4);
tft.println("Piano");
tft.setCursor(140, 30);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(4);
tft.println("by");
tft.setCursor(200, 30);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(4);
tft.println("ROGER");
tft.setRotation(0);
if (!SD.begin(SD_CS_PIN)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized successfully!");
// Open the text file
File file = SD.open("/example.txt");
// Check if the file opened successfully
if (!file) {
Serial.println("Failed to open file for reading!");
return;
}
// Read from the file until there's nothing else in it
while (file.available()) {
// Read a line from the file and print it to the serial monitor
Serial.write(file.read());
}
// Close the file
file.close();
}
void loop() {
tft.fillRect(5,5,50,20,ILI9341_RED);
delay(175);
tft.fillRect(5,5,50,20,ILI9341_WHITE);
tft.fillRect(5,29,50,20,ILI9341_RED);
delay(500);
tft.fillRect(5,29,50,20,ILI9341_WHITE);
tft.fillRect(55, 20, 50, 20,ILI9341_RED );
delay(100);
tft.fillRect(55, 20, 50, 20, ILI9341_BLACK );
tft.fillRect(5,53,50,20,ILI9341_RED);
delay(250);
tft.fillRect(5,53,50,20,ILI9341_WHITE);
tft.fillRect(55, 48, 50, 20,ILI9341_RED );
delay(250);
tft.fillRect(55, 48, 50, 20, ILI9341_BLACK);
}