// import libraries
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <math.h>
// define pins
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CLK 13
// define display: called "tft"
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
void setup() {
// intialize the display: "tft". Here, word "intialize" is translated to Uzbek: "ishga tushurmoq"
tft.begin();
Serial.begin(9600);
Serial.println(" Start!!! ");
// set Rotation: 0, 1, 2, 3. 0 - 0deg, 1 - 90deg, 2 - 180deg, 3 - 275deg
tft.setRotation(0);
}
void loop() {
// define colors
uint16_t colorPurple = tft.color565(162, 0, 255);
uint16_t colorAqua = tft.color565(0, 252, 255);
uint16_t colorWhite = tft.color565(250, 247, 253);
uint16_t colorBlack = tft.color565(9, 1, 12);
// // set color, and fill entire screen with the color
// Serial.println("Fill screen with color AQUA");
// tft.fillScreen(colorAqua);
// delay(2000);
// // create dots
// Serial.println("Make purple dots");
// uint16_t y=1;
// while (y<=320) {
// uint8_t x=(((y-1)/2+1)%3)+1;
// while (x<=240) {
// tft.drawPixel(x, y, colorPurple);
// x=x+3;
// }
// y=y+2;
// }
// delay(2000);
// // draw star with lines
// Serial.println("Draw star outline and then fill it and add backlight");
// tft.fillScreen(colorBlack); // 120, 160
// int outerPoints[5][2] = {{120, 78}, {210, 155}, {170, 270}, {70, 270}, {30, 155}};
// int innerPoints[5][2] = {{137, 155}, {150, 187}, {120, 205}, {90, 187}, {103, 155}};
// int n = 45;
// for (int t = 0; t < n; t++) {
// for (int i = 0; i < 5; i++) {
// int before = (i + 4) % 5;
// tft.drawLine(outerPoints[i][0], outerPoints[i][1], innerPoints[i][0]+round((t*(120-innerPoints[i][0]))/n), innerPoints[i][1]+round((t*(180-innerPoints[i][1]))/n), tft.color565(255/* - round((t*255)/n)*/, 198 - round((t*198)/n), 0 - round((t*0)/n)));
// tft.drawLine(outerPoints[i][0], outerPoints[i][1], innerPoints[before][0]+round((t*(120-innerPoints[before][0]))/n), innerPoints[before][1]+round((t*(180-innerPoints[before][1]))/n), tft.color565(245/* - round((t*245)/n)*/, 255 - round((t*255)/n), 0 - round((t*0)/n)));
// }
// }
// int m = 50;
// for (int t = 0; t < m; t++) {
// for (int i = 0; i < 5; i++) {
// int before = (i + 4) % 5;
// double od = abs(((120-outerPoints[i][0])/120)/((180-outerPoints[i][1])/180));
// double id = abs(((120-innerPoints[i][0])/120)/((180-innerPoints[i][1])/180));
// tft.drawLine(outerPoints[i][0]+round((outerPoints[i][0]>120)*(t*(sqrt(1/(1+(1/(od*od)))))+1)+(outerPoints[i][0]<120)*((-1)*t*(sqrt(1/(1+(1/(od*od)))))-1)), outerPoints[i][1]+round((outerPoints[i][1]>180)*(t*(sqrt(1/(1+(od*od))))+1)+(outerPoints[i][1]<180)*((-1)*t*(sqrt(1/(1+(od*od))))-1)), innerPoints[i][0]+round((innerPoints[i][0]>120)*(t*(sqrt(1/(1+(1/(id*id)))))+1)+(innerPoints[i][0]<120)*((-1)*t*(sqrt(1/(1+(1/(id*id)))))-1)), innerPoints[i][1]+round((innerPoints[i][1]>180)*(t*(sqrt(1/(1+(id*id))))+1)+(innerPoints[i][1]<180)*((-1)*t*(sqrt(1/(1+(id*id))))-1)), tft.color565((196-round((t*392)/m)>0)*(196-round((t*392)/m)), (241-round((t*300)/m)>0)*(241-round((t*300)/m)), (255 - round((t*255)/m)))); // 196,241,255
// tft.drawLine(outerPoints[i][0]+round((outerPoints[i][0]>120)*(t*(sqrt(1/(1+(1/(od*od)))))+1)+(outerPoints[i][0]<120)*((-1)*t*(sqrt(1/(1+(1/(od*od)))))-1)), outerPoints[i][1]+round((outerPoints[i][1]>180)*(t*(sqrt(1/(1+(od*od))))+1)+(outerPoints[i][1]<180)*((-1)*t*(sqrt(1/(1+(od*od))))-1)), innerPoints[before][0]+round((innerPoints[before][0]>120)*(t*(sqrt(1/(1+(1/(id*id)))))+1)+(innerPoints[before][0]<120)*((-1)*t*(sqrt(1/(1+(1/(id*id)))))-1)), innerPoints[before][1]+round((innerPoints[before][1]>180)*(t*(sqrt(1/(1+(id*id))))+1)+(innerPoints[before][1]<180)*((-1)*t*(sqrt(1/(1+(id*id))))-1)), tft.color565(((196-round((t*392)/m))>0)*(196-round((t*392)/m)), ((241-round((t*300)/m))>0)*(241 - round((t*300)/m)), (255 - round((t*255)/m))));
// }
// }
// delay(5000);
// // draw rectangle
// Serial.println("Make rectangle color gradient");
// for (int x=0; x<120; x++) {
// bool redBool=(x<=59);
// uint8_t red=round(map(redBool*(59-x), 0, 59, 0, 255));
// bool greenBool1=(x<=59);
// bool greenBool2=(x>59)*(x<118);
// uint8_t green=round(map(greenBool1*(x)+greenBool2*(118-x), 0, 59, 0, 255));
// bool blueBool=(x>59);
// uint8_t blue=round(map(blueBool*(x-59), 0, 60, 0, 255));
// uint16_t color=tft.color565(red, green, blue);
// tft.drawRect(x, x, 240-(x*2), 320-(x*2), color);
// }
// delay(5000);
// // draw filled rectangles
// Serial.println("Place filled rectangles to grid");
// uint8_t paddingmax = 7;
// uint8_t paddingmin = 4;
// uint8_t sizemax = 42;
// uint8_t sizemin = 10;
// uint8_t colormax = 120;
// uint8_t colormin = 40;
// uint8_t grmin = sizemin+(paddingmin*2);
// uint8_t grmax = sizemax+(2*paddingmax);
// bool finishedY = 0;
// uint16_t x = 0;
// bool dbl = 0;
// uint8_t h = 0;
// uint8_t l = 0;
// while (finishedY==0) {
// if (320-y>grmax+grmin) {
// h=random(grmin, grmax+1);
// } else if ((320-y)>(2*grmin)) {
// h=random(grmin, 319-y-grmin);
// } else {
// h=320-y;
// }
// if (h>(2*grmin)) {
// dbl=1;
// } else {
// dbl=0;
// }
// bool finishedX = 0;
// x=0;
// while (finishedX==0) {
// if (240-x>grmax+grmin) {
// l = random(grmin, grmax+1);
// } else if (240-x>2*grmin) {
// l = random(grmin, 239-x-grmin);
// } else {
// l = 240 - x;
// }
// if (dbl==1) {
// uint8_t h1 = grmin+random(0, h-(2*grmin)+1);
// uint8_t h2 = h-h1;
// uint8_t padding1 = random(paddingmin, paddingmax+1);
// uint8_t padding2 = random(paddingmin, paddingmax+1);
// tft.fillRect(x+padding1, y+padding1, l-(2*padding1), h1-(2*padding1), tft.color565(random(colormin, colormax+1), random(colormin, colormax+1), random(colormin, colormax+1)));
// tft.fillRect(x+padding2, y+padding2+h1, l-(2*padding2), h2-(2*padding2), tft.color565(random(colormin, colormax+1), random(colormin, colormax+1), random(colormin, colormax+1)));
// } else {
// uint8_t padding = random(paddingmin, paddingmax+1);
// tft.fillRect(x+padding, y+padding, l-(2*padding), h-(2*padding), tft.color565(random(colormin, colormax+1), random(colormin, colormax+1), random(colormin, colormax+1)));
// }
// x=x+l;
// if (x==240) {
// finishedX = 1;
// }
// }
// y=y+h;
// if (y==320) {
// finishedY = 1;
// }
// }
// delay(5000);
// draw circles
tft.fillCircle(120, 160, 64, tft.color565(120, 7, 245));
}
Loading
ili9341-cap-touch
ili9341-cap-touch