/*
  Simple "Hello World" for ILI9341 LCD

  https://wokwi.com/arduino/projects/308024602434470466
  https://wokwi.com/projects/307567201804616256
  https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
  https://www.fernandok.com/2018/05/arduino-e-display-touch-screen.html

*/

#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);

int ax = 2, ay = 10;
int bx = 5, by = 0;
int cx = 8, cy = 10;

void setup() {

  tft.begin();

  tft.setRotation(1);


  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(1);
  tft.println("Seja bem-vindo ...");
  tft.println();

  tft.setCursor(0, 10);
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(1);
  tft.println("Hello World ...");
  tft.println();

  delay(3000);

  tft.fillScreen(ILI9341_BLACK);

}

void loop() { 

  //tft.fillTriangle(110, 150, 150, 100, 190, 150, ILI9341_YELLOW);

  //delay(3000);

  //tft.drawTriangle(ax, ay, bx, by, cx, cy, ILI9341_WHITE);

  // Mover para direita
  for (int i = 0; i <= 300; i++) {

      tft.drawTriangle(ax+i, ay, bx+i, by, cx+i, cy, ILI9341_WHITE);
      delay(50);
      tft.drawTriangle(ax+i, ay, bx+i, by, cx+i, cy, ILI9341_BLACK);     

  }

  // Mover para esquerda
  for (int i = 300; i >= 0; i--) {

      tft.drawTriangle(ax+i, ay, bx+i, by, cx+i, cy, ILI9341_WHITE);
      delay(50);
      tft.drawTriangle(ax+i, ay, bx+i, by, cx+i, cy, ILI9341_BLACK);     

  }  

  // Mover para baixo
  for (int i = 0; i <= 225; i++) {

      tft.drawTriangle(ax, ay+i, bx, by+i, cx, cy+i, ILI9341_WHITE);
      delay(50);
      tft.drawTriangle(ax, ay+i, bx, by+i, cx, cy+i, ILI9341_BLACK);     

  }

  //delay(3000);

  // Mover para cima
  for (int i = 225; i >= 0; i--) {

      tft.drawTriangle(ax, ay+i, bx, by+i, cx, cy+i, ILI9341_WHITE);
      delay(50);
      tft.drawTriangle(ax, ay+i, bx, by+i, cx, cy+i, ILI9341_BLACK);     

  }  

  //delay(3000);

}