#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Thread.h"
#include <ThreadController.h>
#define BTN_PIN 21
#define TFT_DC 9
#define TFT_CS 10
#define TFT_MOSI 26
#define TFT_SCK 13
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC,TFT_MOSI,TFT_SCK);
ThreadController controll = ThreadController();
Thread animationThread = Thread();
int posX_anim = 0;
int posXMin_anim = 5;
int posXMax_anim = 315;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(BTN_PIN, INPUT_PULLUP);
tft.begin();
tft.setRotation(1);
tft.setCursor(26, 100);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("MR SMILE");
tft.setCursor(10, 140);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(1.5);
tft.println("SUBSCRIBE");
Serial.println("Hello, ESP32-S2!");
Serial.print("TFT Width: ");
Serial.print(tft.width());
Serial.print(" / TFT Height: ");
Serial.println(tft.height());
posXMax_anim = tft.width() - 25;
posX_anim = posXMin_anim;
tft.fillRect(posX_anim, tft.height() - 20, 20, 10, ILI9341_WHITE);
// Configure myThread
animationThread.onRun(animationCallback);
animationThread.setInterval(25);
// Adds both threads to the controller
controll.add(&animationThread);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(BTN_PIN) == LOW) {
//Serial.print("BTN_PIN IS PRESSED");
controll.run();
}
//delay(10); // this speeds up the simulation
}
// callback for myThread
void animationCallback(){
//Serial.print("COOL! I'm running on: ");
//Serial.println(millis());
int animStep=5;
if(posX_anim + animStep < posXMax_anim){
posX_anim += animStep;
tft.fillRect(posX_anim, tft.height() - 20, 20, 10, ILI9341_WHITE);
Serial.print("posX_anim: ");
Serial.println(posX_anim);
}
}