/*
Simple "Hello World" for ILI9341 LCD
https://wokwi.com/arduino/projects/308024602434470466
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void centerHorizontal(const String &buf, uint16_t x, uint16_t y){
int16_t x1, y1;
static uint16_t size[2] = {0, 0};
tft.getTextBounds(buf, 0, 0, &x1, &y1, &size[0], &size[1]); //calc width of new string
tft.setCursor(x - size[0] / 2, y);
tft.print(buf);
}
void centerHorizontalExt(const String &buf, uint16_t x, uint16_t y, uint8_t size, uint16_t color){
tft.setTextColor(color);
tft.setTextSize(size);
centerHorizontal(buf, x, y);
}
void setup() {
tft.begin();
centerHorizontalExt("H Center", 120,20, 1, ILI9341_RED);
centerHorizontalExt("H Center", 120,60, 2, ILI9341_GREEN);
centerHorizontalExt("H Center", 120,120, 3, ILI9341_BLUE);
centerHorizontalExt("H Center", 120,180, 4, ILI9341_PURPLE);
// Meme reference: https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
}
void loop() { }