// #include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "MCUFRIEND_kbv.h"
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// 565 COLOR
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x03E0 // 0000 0.011 111.0 0000
#define LTGREEN 0x07E0 // 0000 0.111 111.0 0000
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define DKGREY 0x4208 // 0100 0.010 000.0 1000
#define GREY 0x8410 // 1000 0.100 000.1 0000
#define LTGREY 0xC618 // 1100 0.110 000.1 1000
Adafruit_GFX_Button STARTx;
Adafruit_GFX_Button MODE_A;
Adafruit_GFX_Button MODE_B;
Adafruit_GFX_Button CUSTOM;
void setup() {
Serial.begin(9600);
Serial.println("Hello, ILI9341!");
tft.begin();
tft.setRotation(0); // 0 vertical / 1 horizontal
// appleiie();
c64();
// setupDisplay();
// changeTextSize();
// changeTextColor();
// extendedASCII();
}
void loop() { }
void extendedASCII() {
int j = 0;
for (int i = 127; i < 288; i++) {
if (i < 100)
tft.print(" ");
if (i < 10)
tft.print(" ");
tft.print(i);
tft.print("=");
if (i == 266) // linefeed
tft.print(" ");
else
tft.print(char(i));
if (j++ == 5) {
j = 0;
tft.print("\n");
} else {
tft.print(" ");
}
}
}
void changeTextColor() {
// https://forum.arduino.cc/t/all-colors-are-blue/1224764/4
// tft.setTextColor(0xf800); // 565 red
// tft.setTextColor(0x001f); // 565 blue
// tft.setTextColor(0x0780); // 565 green
tft.setTextColor(0xffff); // 565 white
tft.setCursor(0, 0);
tft.setTextSize(2);
tft.print("setTextColor(0xffff)");
tft.setCursor(20, 0);
tft.setTextSize(2);
for (long i = 0; i < 0x1f; i++) {
for (long j = 0; j < 0x3f; j++) {
for (long k = 0; k < 0x1f; k++) {
tft.setCursor(0, 20);
tft.setTextColor(i << 11 & j << 5 && k);
tft.print("setTextColor()");
}
}
}
}
void changeTextSize() {
tft.setCursor(0, 0);
tft.setTextSize(1);
tft.print("setTextSize(1)");
tft.setCursor(0, 25);
tft.setTextSize(2);
tft.print("Size = 2");
tft.setCursor(0, 75);
tft.setTextSize(3);
tft.print("Size = 3");
tft.setCursor(0, 150);
tft.setTextSize(4);
tft.print("Size = 4");
tft.setCursor(0, 250);
tft.setTextSize(5);
tft.print("Size = 5");
}
void setupDisplay() {
STARTx.initButton(&tft, 60, 205, 100, 70, WHITE, BLUE, BLACK, "START", 2);
STARTx.drawButton(true);
MODE_A.initButton(&tft, 60, 285, 100, 70, WHITE, RED, BLACK, "A", 2);
MODE_A.drawButton(true);
MODE_B.initButton(&tft, 175, 285, 100, 70, WHITE, GREEN, BLACK, "B", 2);
MODE_B.drawButton(true);
CUSTOM.initButton(&tft, 175, 205, 100, 70, WHITE, YELLOW, BLACK, "CUST", 2);
CUSTOM.drawButton(true);
}
void c64() {
tft.fillScreen(BLUE);
tft.setTextColor(CYAN);
tft.println(" **** COMMODORE 64 BASIC V2 ****");
tft.println(" 64k RAM SYSTEM 38911 BASIC BYTES FREE");
tft.println("\n");
tft.println("10 FOR A = 127 TO 288 STEP 1");
tft.println("20 PRINT A; TAB(2)");
tft.println("30 PRINT \"=\" ");
tft.println("40 PRINT CHR$(A)");
tft.println("50 NEXT");
tft.println("\n");
}
void appleiie() {
tft.fillScreen(0x4208); // dark grey 0100 0.010 000.0 1000
tft.setTextColor(LTGREEN);
tft.println("\n APPLE ][e\n");
tft.println(" 10 FOR A = 127 TO 288 STEP 1");
tft.println(" 20 PRINT A; TAB(2)");
tft.println(" 30 PRINT \"=\" ");
tft.println(" 40 PRINT CHR$(A)");
tft.println(" 50 NEXT");
tft.println("\n");
}