#include <Adafruit_GFX.h> // Hardware-specific library
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_CS 10 // TFT CS pin
#define TFT_DC 9 // TFT DC pin
#define TFT_RST 8 // TFT reset
//MCUFRIEND_kbv tft;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void SetText(uint8_t X, uint8_t Y, String Text, uint16_t Color);
String GetScrolledText(String S, uint8_t Position);
char Buffer[40];
String OldText;
uint8_t Counter = 0;
uint8_t ScrollSpeed = 1; // Adjust this value to control the scrolling speed
void setup()
{
Serial.begin(9600);
tft.begin();
tft.setRotation(4); // Horizontal display
tft.fillScreen(ILI9341_BLACK); // Black background
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(5);
tft.setTextWrap(false);
}
void loop()
{
uint16_t Zeit;
String text;
Zeit = millis() / 10;
sprintf(Buffer, "ARVIND PATIL, INDIA %d -", Zeit);
text = Buffer;
if (Counter >= text.length() * 6) // Multiply by 6 to control scrolling distance
Counter = 0;
Serial.print("Counter ");
Serial.println(Counter);
SetText(Counter, 6, OldText, ILI9341_CYAN);
text = GetScrolledText(text, Counter);
SetText(Counter, 6, text, ILI9341_RED);
OldText = text;
Counter += ScrollSpeed;
delay(50); // Adjust this delay for smoother scrolling (lower value) or slower scrolling (higher value)
}
String GetScrolledText(String S, uint8_t Position)
{
String t = "";
for (uint8_t i = 0; i < S.length(); i++)
{
t += S.charAt((Position + i) % S.length());
}
Serial.println(t);
return t;
}
void SetText(uint8_t X, uint8_t Y, String Text, uint16_t Color)
{
tft.setTextColor(Color, ILI9341_BLACK); // Black is Background
tft.setCursor(10, 150);
tft.print(Text);
}