Hardware
Brief characteristics of TFT shield:
- Size 3.5 " diagonal,
- Resolution 320x240,
- Number of colors 65536 (16-bit),
- Resistive touch screen (XPT2046 controller),
- 5 buttons,
- RTC IC DS1307 with 3V lithium battery CR1220,
- Slot for connecting a micro SD card,
- 4-pin (2.54 mm) connector for connecting the Bluetooth module HC-05 (-06),
- 20-pin (2.54 mm) connector for camera (OV7670).
Software
At the moment, the following library functions are implemented for working with graphics: drawing points, lines, circles, rectangles.The most popular library from Adafruit Industries was adapted for working with fonts. Additionally, work with the touch screen and buttons is implemented.Demo sketch to demonstrate the work with graphics and fonts:
#include <YATFT.h> // Hardware-specific library
#include <Adafruit_GFX.h> // Include Adafruit-GFX library
#include <Fonts/FreeSerif9pt7b.h> // Include Adafruit fonts
#include <Fonts/FreeSerifItalic24pt7b.h>
#include <Fonts/FreeSans24pt7b.h>
YATFT tft(0);
uint32_t total_time;
uint16_t Color[4] = {BRIGHTBLUE, BRIGHTGREEN, BRIGHTRED, BRIGHTYELLOW};
uint16_t Gray[7] = {GRAY0, GRAY1, GRAY2, GRAY3, GRAY4, GRAY5, GRAY6};
/*************************************************************************************************/
void ClearScreen (void)
{
tft.SetColor(BLACK); // Set fone color
tft.ClearDevice(); // Fill all screen
}
void setup()
{
Serial.begin(115200); // initialize the serial port
Serial.println("Arduino TFT_shield Example 1!");
tft.begin(); // initialize the display
}
void loop()
{
uint16_t x, y, x2, y2, mask_gray;
uint16_t i;
ClearScreen();
// Fonts
Serial.print("1) View Fonts (");
total_time = millis();
tft.SetColor(BRIGHTBLUE);
tft.SetFont(NULL);
tft.OutTextXY(5, 5, "Demonstration of work with the TFT display.");
tft.SetColor(BRIGHTGREEN);
tft.SetFont(&FreeSerif9pt7b);
tft.OutTextXY(5, 20, "The example uses fonts from Adafruit.");
tft.SetFont(&FreeSerifItalic24pt7b);
tft.SetColor(BRIGHTCYAN);
tft.OutTextXY(5, 45, "3,5''");
tft.SetColor(BRIGHTRED);
tft.OutTextXY(90, 45, "QVGA");
tft.SetColor(BRIGHTMAGENTA);
tft.OutTextXY(230, 45, "disp.");
tft.SetColor(BRIGHTYELLOW);
tft.SetFont(&FreeSans24pt7b);
tft.OutTextXY(5, 100, "A R D U I N O + T F T");
tft.SetFont(NULL);
for (i = 0; i < 7; i++)
{
tft.SetColor(Gray[i]);
tft.OutTextXY(5, 170+10*i, "Demonstration of work with the TFT display.");
}
total_time = millis() - total_time;
Serial.print(total_time);
Serial.println(" ms)");
delay(3000);
ClearScreen();
// Circle
Serial.print("2) Draw circle (");
total_time = millis();
tft.SetColor(BRIGHTRED);
for (i = 10; i < GetMaxY()>>1; i += 10) {
tft.DrawCirc(GetMaxX()>>1, GetMaxY()>>1, i);
}
total_time = millis() - total_time;
Serial.print(total_time);
Serial.println(" ms)");
delay(1000);
// DrawFillCircle & DrawFillRect
Serial.print("3) Draw FillCircle and FillRect (");
total_time = millis();
tft.SetColor(BRIGHTRED);
tft.DrawFillCirc(GetMaxX()>>1,GetMaxY()>>1,110);
tft.SetColor(BRIGHTCYAN);
tft.DrawFillRect(GetMaxX()/2-77,GetMaxY()/2-77, GetMaxX()/2+77,GetMaxY()/2+77);
tft.SetColor(BRIGHTGREEN);
tft.DrawFillCirc(GetMaxX()>>1,GetMaxY()>>1,77);
tft.SetColor(BRIGHTMAGENTA);
tft.DrawFillRect(GetMaxX()/2-54,GetMaxY()/2-54, GetMaxX()/2+54,GetMaxY()/2+54);
tft.SetColor(BRIGHTBLUE);
tft.DrawFillCirc(GetMaxX()>>1,GetMaxY()>>1,54);
tft.SetColor(BRIGHTYELLOW);
tft.DrawFillRect(GetMaxX()/2-37,GetMaxY()/2-37, GetMaxX()/2+37,GetMaxY()/2+37);
total_time = millis() - total_time;
Serial.print(total_time);
Serial.println(" ms)");
delay(1000);
ClearScreen();
// Arc
Serial.print("4) Draw Arc (");
total_time = millis();
ClearScreen();
tft.SetColor(BRIGHTBLUE);
tft.DrawArc((GetMaxX()>>1)-60,(GetMaxY()>>1)-60,(GetMaxX()>>1)+60,(GetMaxY()>>1)+60,20,30,0xFF);
tft.SetColor(BRIGHTGREEN);
...
Read more »