#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define RAD 30
#define STEPX 10
#define STEPY 20
// For the Adafruit shield, these are the default.
#define TFT_DC D2
#define TFT_CS SS
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(SS,16,17);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
Serial.printf("MISO %d,MOSi %d,SCK %d,SS %d \n", MISO, MOSI, SCK, SS);
Serial.println("ILI9341 Test!");
SPI.setFrequency(80E6);
tft.begin();
// read diagnostics (optional but can help debug problems)
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
Serial.print("Display Power Mode: 0x");
Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDMADCTL);
Serial.print("MADCTL Mode: 0x");
Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDPIXFMT);
Serial.print("Pixel Format: 0x");
Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDIMGFMT);
Serial.print("Image Format: 0x");
Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDSELFDIAG);
Serial.print("Self Diagnostic: 0x");
Serial.println(x, HEX);
Serial.println(F("Done!"));
// Serial.println("Done!", SP);
tft.fillScreen(ILI9341_BLACK);
tft.setRotation(3);
tft.setCursor(160, 120);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.println("HI THERE !");
tft.setCursor(160, 130);
tft.setTextSize(1);
tft.println("HTMLGFX");
tft.println();
delay(500);
tft.setCursor(160, 140);
tft.println("by liderwally");
delay(500);
tft.fillScreen(ILI9341_BLUE);
}
int counterx = 50;
int countery = 50;
bool dirx = true;
bool diry = true;
void loop(void) {
tft.fillCircle(counterx, countery, RAD, ILI9341_GREEN);
tft.drawCircle(counterx, countery, 30, ILI9341_CYAN);
delay(250);
tft.fillCircle(counterx, countery, 30, ILI9341_BLUE);
if (counterx < RAD || counterx > (320 - RAD)) {
dirx = !dirx;
}
if (countery < RAD || countery > (240 - RAD)) {
diry = !diry;
}
Serial.printf(" CounterX : %d , CounterY : %d \n", counterx, countery);
if (dirx) {
counterx = STEPX + counterx;
} else {
counterx = counterx - STEPX;
}
if (diry) {
countery = countery + STEPY;
} else {
countery = countery - STEPY;
}
}