for (uint16_t a=0; a<5; a++)
{ tft.drawLine(xi+a, yi, xj+a, yj, t);}
for (uint16_t a=0; a<5; a++)
{ tft.drawLine(xi, yi+a, xj, yj+a, t);}
These three blocks of code draw lines like the previous code with 5-pixel thickness.
tft.fillRect(x,y,w,h,t);
//fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t t)
tft.drawRect(x,y,w,h,t);
//drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t t)
tft.fillRoundRect(x,y,w,h,r,t);
//fillRoundRect (int16_t x, int16_t y, int16_t w, int16_t h, uint8_t R , uint16_t t)
tft.drawRoundRect(x,y,w,h,r,t);
//drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t R , uint16_t t)
fillRect function draws a filled rectangle in x and y location. w is width, h is height and t is color of the rextangle
drawRect function draws a rectangle in x and y location with w width and h height and t color.
fillRoundRect function draws a filled Rectangle with r radius round corners in x and y location and w width and h height and t color.
drawRoundRect function draws a Rectangle with r radius round corners in x and y location and w width and h height and t color.
Drawing Circles
tft.drawCircle(x,y,r,t); //drawCircle(int16_t x, int16_t y, int16_t r, uint16_t t)
tft.fillCircle(x,y,r,t); //fillCircle(int16_t x, int16_t y, int16_t r, uint16_t t)
drawCircle function draws a circle in x and y location and r radius and t color.
fillCircle function draws a filled circle in x and y location and r radius and t color.
for (int p = 0; p < 4000; p++)
{ j = 120 * (sin(PI * p / 2000));
i = 120 * (cos(PI * p / 2000));
j2 = 60 * (sin(PI * p / 2000));
i2 = 60 * (cos(PI * p / 2000));
tft.drawLine(i2 + 160, j2 + 160, i + 160, j + 160, col[n]);
}
By this code, you can draw an Arc. change the “for” between 0 and 4000.
Drawing Triangles
tft.drawTriangle(x1,y1,x2,y2,x3,y3,t);
//drawTriangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3,// uint16_t t)
tft.fillTriangle(x1,y1,x2,y2,x3,y3,t);
//fillTriangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3,// uint16_t t)
drawTriangle function draws a triangle with three corner location x, y and z, and t color.
fillTriangle function draws a filled triangle with three corner location x, y and z, and t color.
Displaying Text
tft.setCursor(x,y); //setCursor(int16_t x, int16_t y)
This code sets the cursor position to of x and y
tft.setTextColor(t); //setTextColor(uint16_t t)
tft.setTextColor(t,b); //setTextColor(uint16_t t, uint16_t b)
The first line sets the color of the text. Next line sets the color of text and its background.
tft.setTextSize(s); //setTextSize(uint8_t s)
This code sets the size of text by s. s is a number between 1 and 5.
tft.write(c); //write(uint8_t c)
This code displays a character.
tft.println("www.Electropeak.com");
tft.print("www.Electropeak.com");
The first function displays a string and moves the cursor to the next line.
The second function just displays the string.
showmsgXY(x,y,sz,&FreeSans9pt7b,"www.Electropeak.com");
//void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
{ uint16_t x1, y1;
uint16_t wid, ht;
tft.setFont(f);
tft.setCursor(x, y);
tft.setTextColor(0x0000);
tft.setTextSize(sz);
tft.print(msg);
}
This function changes the font of the text. You should add this function and font libraries.
for (int j = 0; j < 20; j++) {
tft.setCursor(145, 290);
int color = tft.color565(r -= 12, g -= 12, b -= 12);
tft.setTextColor(color);
tft.print("www.Electropeak.com");
delay(30);
}
This function can fade your text. You should add it to your code.
Rotating the Screen
tft.setRotation(r); //setRotation(uint8_t r)
This code rotates the screen. 0=0, 1=90, 2=180, 3=270.
Inverting Screen Colors
tft.invertDisplay(i); //invertDisplay(boolean i)
This code inverts the colors of the screen.
tft.color565(r,g,b); //uint16_t color565(uint8_t r, uint8_t g, uint8_t b)
This code give RGB code and get UTFT color code.
- 1
- 2
前往页