#include "Adafruit_GFX.h" // Adafruit graphics
#include "Adafruit_ILI9341.h" // ILI9341 screen controller
// pi
#define TFT_DC 2
#define TFT_CS 15
#define left 21
#define right 22
#define down 25
#define up 27
Adafruit_ILI9341 tft=Adafruit_ILI9341(TFT_CS, TFT_DC); // hardware SPI
int x,y;
String text;
void setup()
{
pinMode(left,INPUT);
pinMode(right,INPUT);
pinMode(down,INPUT);
pinMode(up, INPUT);
Serial.begin(115200);
while(!Serial.available()){
}
text=Serial.readStringUntil('\n');
tft.begin();
tft.setRotation(1); // horizontal display
tft.setTextWrap(false);
tft.setTextSize(3);
x=((tft.width()-text.length())/2)-70;
y=(tft.height()/2);
tft.setCursor(x,y);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_CYAN);
tft.print(text);
}
void scrollLeft(){
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(x,y);
tft.print(text);
tft.setTextColor(ILI9341_CYAN);
x-=10;
if(x<0)
x=tft.width();
tft.setCursor(x,y);
tft.print(text);
}
void scrollRight(){
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(x,y);
tft.print(text);
tft.setTextColor(ILI9341_CYAN);
x+=10;
if(x>tft.width())
x=0;
tft.setCursor(x,y);
tft.print(text);
}
void scrollDown(){
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(x,y);
tft.print(text);
tft.setTextColor(ILI9341_CYAN);
y+=10;
if(y>tft.height())
y=0;
tft.setCursor(x,y);
tft.print(text);
}
void scrollUp(){
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(x,y);
tft.print(text);
tft.setTextColor(ILI9341_CYAN);
y-=10;
if(y<0)
y=tft.height();
tft.setCursor(x,y);
tft.print(text);
}
void loop()
{
delay(10);
if(digitalRead(left)){
Serial.println("left");
scrollLeft();
}
if(digitalRead(right)){
Serial.println("right");
scrollRight();
}
if(digitalRead(down)){
Serial.println("down");
scrollDown();
}
if(digitalRead(up)){
Serial.println("up");
scrollUp();
}
delay(100);
}