#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include "point.h"
#define SIZE 50
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
/* Define 4 Points for the Rectangle*/
Point P1;
Point P2;
Point P3;
Point P4;
void setup() {
tft.begin();
tft.setRotation(1);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(2);
}
Point operator+(Point& inputPoint1, Point& inputPoint2)
{
Point temp;
temp.set_x(inputPoint1.get_x() + inputPoint2.get_x());
temp.set_y(inputPoint1.get_y() + inputPoint2.get_y());
return temp;
}
void draw_line_points(Point& startPoint, Point& endPoint)
{
tft.drawLine(
startPoint.get_x(),startPoint.get_y(),
endPoint.get_x(),endPoint.get_y(),
ILI9341_BLACK );
}
void loop() {
std::cout<<"width: "<<tft.width()<<std::endl;
int cx = tft.width() / 2;
std::cout<<cx<<std::endl;
std::cout<<"height: "<<tft.height()<<std::endl;
int cy = tft.height() / 2;
std::cout<<cy<<std::endl;
tft.fillScreen(ILI9341_WHITE);
tft.setCursor(0,0);
P1.set_x(cx);
P1.set_y(cy);
P2.set_x(cx + SIZE);
P2.set_y(cy);
P3.set_x(cx +SIZE);
P3.set_y(cy +SIZE);
P4.set_x(cx );
P4.set_y(cy+SIZE);
draw_line_points(P1, P2);
delay(100);
draw_line_points(P2, P3);
delay(100);
draw_line_points(P3, P4);
delay(100);
draw_line_points(P4, P1);
delay(100);
delay(1000);
if(P1 < P2)
{
tft.drawLine(
P1.get_x(), P1.get_y(),
P3.get_x(), P3.get_y(),
ILI9341_RED );
}
delay(1000);
}