Skip to content

Commit ee6a833

Browse files
committed
added the TFT display library
1 parent bd24067 commit ee6a833

File tree

28 files changed

+3410
-0
lines changed

28 files changed

+3410
-0
lines changed

libraries/TFT/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
TFT Library
2+
============
3+
4+
An Arduino library for the Arduino TFT LCD screen.
5+
6+
This library enables an Arduino board to communicate with an Arduino TFT LCD screen. It simplifies the process for drawing shapes, lines, images, and text to the screen.
7+
The Arduino TFT library extends the Adafruit GFX, and Adafruit ST7735 libraries that it is based on. The GFX library is responsible for the drawing routines, while the ST7735 library is specific to the screen on the Arduino GTFT. The Arduino specific additions were designed to work as similarly to the Processing API as possible.
8+
9+
Onboard the screen is a SD card slot, which can be used through the SD library.
10+
11+
The TFT library relies on the SPI library for communication with the screen and SD card, and needs to be included in all sketches.
12+
13+
https://github.com/adafruit/Adafruit-GFX-Library
14+
https://github.com/adafruit/Adafruit-ST7735-Library
15+
http://arduino.cc/en/Reference/SD
16+
http://arduino.cc/en/Reference/SPI
17+
18+
http://arduino.cc/en/Reference/TFTLibrary

libraries/TFT/TFT.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "TFT.h"
2+
3+
#if (USB_VID == 0x2341) && (USB_PID == 0x803C) // are we building for Esplora?
4+
TFT EsploraTFT(7, 0, 1);
5+
#endif
6+
7+
TFT::TFT(uint8_t CS, uint8_t RS, uint8_t RST)
8+
: Adafruit_ST7735(CS, RS, RST)
9+
{
10+
// as we already know the orientation (landscape, therefore rotated),
11+
// set default width and height without need to call begin() first.
12+
_width = ST7735_TFTHEIGHT;
13+
_height = ST7735_TFTWIDTH;
14+
}
15+
16+
void TFT::begin() {
17+
initR(INITR_REDTAB);
18+
setRotation(1);
19+
}

libraries/TFT/TFT.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
#ifndef _ARDUINO_TFT_H
3+
#define _ARDUINO_TFT_H
4+
5+
#include "Arduino.h"
6+
#include "utility/Adafruit_GFX.h"
7+
#include "utility/Adafruit_ST7735.h"
8+
9+
/// The Arduino LCD is a ST7735-based device.
10+
/// By default, it is mounted horizontally.
11+
/// TFT class follows the convention of other
12+
/// Arduino library classes by adding a begin() method
13+
/// to be called in the setup() routine.
14+
/// @author Enrico Gueli <[email protected]>
15+
class TFT : public Adafruit_ST7735 {
16+
public:
17+
TFT(uint8_t CS, uint8_t RS, uint8_t RST);
18+
19+
void begin();
20+
};
21+
22+
/// Esplora boards have hard-wired connections with
23+
/// the Arduino LCD if mounted on the onboard connector.
24+
#if (USB_VID == 0x2341) && (USB_PID == 0x803C) // are we building for Esplora?
25+
extern TFT EsploraTFT;
26+
#endif
27+
28+
#endif // _ARDUINO_TFT_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
3+
Arduino TFT Bitmap Logo example
4+
5+
This example reads an image file from a micro-SD card
6+
and draws it on the screen, at random locations.
7+
8+
In this sketch, the Arduino logo is read from a micro-SD card.
9+
There is a .bmp file included with this sketch.
10+
- open the sketch folder (Ctrl-K or Cmd-K)
11+
- copy the "arduino.bmp" file to a micro-SD
12+
- put the SD into the SD slot of the Arduino TFT module.
13+
14+
This example code is in the public domain.
15+
16+
Created 19 April 2013 by Enrico Gueli
17+
18+
http://arduino.cc/en/Tutorial/TFTBitmapLogo
19+
20+
*/
21+
22+
// include the necessary libraries
23+
#include <SPI.h>
24+
#include <SD.h>
25+
#include <TFT.h> // Arduino LCD library
26+
27+
// pin definition for the Uno
28+
#define sd_cs 4
29+
#define lcd_cs 10
30+
#define dc 9
31+
#define rst 8
32+
33+
// pin definition for the Leonardo
34+
//#define sd_cs 8
35+
//#define lcd_cs 7
36+
//#define dc 0
37+
//#define rst 1
38+
39+
TFT TFTscreen = TFT(lcd_cs, dc, rst);
40+
41+
// this variable represents the image to be drawn on screen
42+
PImage logo;
43+
44+
45+
void setup() {
46+
// initialize the GLCD and show a message
47+
// asking the user to open the serial line
48+
TFTscreen.begin();
49+
TFTscreen.background(255, 255, 255);
50+
51+
TFTscreen.stroke(0, 0, 255);
52+
TFTscreen.println();
53+
TFTscreen.println("Arduino TFT Bitmap Example");
54+
TFTscreen.stroke(0, 0, 0);
55+
TFTscreen.println("Open serial monitor");
56+
TFTscreen.println("to run the sketch");
57+
58+
// initialize the serial port: it will be used to
59+
// print some diagnostic info
60+
Serial.begin(9600);
61+
while (!Serial) {
62+
// wait for serial line to be ready
63+
}
64+
65+
// clear the GLCD screen before starting
66+
TFTscreen.background(255, 255, 255);
67+
68+
// try to access the SD card. If that fails (e.g.
69+
// no card present), the setup process will stop.
70+
Serial.print("Initializing SD card...");
71+
if (!SD.begin(sd_cs)) {
72+
Serial.println("failed!");
73+
return;
74+
}
75+
Serial.println("OK!");
76+
77+
// initialize and clear the GLCD screen
78+
TFTscreen.begin();
79+
TFTscreen.background(255, 255, 255);
80+
81+
// now that the SD card can be access, try to load the
82+
// image file.
83+
logo = TFTscreen.loadImage("arduino.bmp");
84+
if (!logo.isValid()) {
85+
Serial.println("error while loading arduino.bmp");
86+
}
87+
}
88+
89+
void loop() {
90+
// don't do anything if the image wasn't loaded correctly.
91+
if (logo.isValid() == false) {
92+
return;
93+
}
94+
95+
Serial.println("drawing image");
96+
97+
// get a random location where to draw the image.
98+
// To avoid the image to be draw outside the screen,
99+
// take into account the image size.
100+
int x = random(TFTscreen.width() - logo.width());
101+
int y = random(TFTscreen.height() - logo.height());
102+
103+
// draw the image to the screen
104+
TFTscreen.image(logo, x, y);
105+
106+
// wait a little bit before drawing again
107+
delay(1500);
108+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
3+
TFT Color Picker
4+
5+
This example for the Arduino screen reads the input of
6+
potentiometers or analog sensors attached to A0, A1,
7+
and A2 and uses the values to change the screen's color.
8+
9+
This example code is in the public domain.
10+
11+
Created 15 April 2013 by Scott Fitzgerald
12+
13+
http://arduino.cc/en/Tutorial/TFTColorPicker
14+
15+
*/
16+
17+
// pin definition for the Uno
18+
#define cs 10
19+
#define dc 9
20+
#define rst 8
21+
22+
// pin definition for the Leonardo
23+
// #define cs 7
24+
// #define dc 0
25+
// #define rst 1
26+
27+
#include <TFT.h> // Arduino LCD library
28+
#include <SPI.h>
29+
30+
TFT TFTscreen = TFT(cs, dc, rst);
31+
32+
void setup() {
33+
// begin serial communication
34+
Serial.begin(9600);
35+
36+
// initialize the display
37+
TFTscreen.begin();
38+
39+
// set the background to white
40+
TFTscreen.background(255, 255, 255);
41+
42+
}
43+
44+
void loop() {
45+
46+
// read the values from your sensors and scale them to 0-255
47+
int redVal = map(analogRead(A0), 0, 1023, 0, 255);
48+
int greenVal = map(analogRead(A1), 0, 1023, 0, 255);
49+
int blueVal = map(analogRead(A2), 0, 1023, 0, 255);
50+
51+
// draw the background based on the mapped values
52+
TFTscreen.background(redVal, greenVal, blueVal);
53+
54+
// send the values to the serial monitor
55+
Serial.print("background(");
56+
Serial.print(redVal);
57+
Serial.print(" , ");
58+
Serial.print(greenVal);
59+
Serial.print(" , ");
60+
Serial.print(blueVal);
61+
Serial.println(")");
62+
63+
// wait for a moment
64+
delay(33);
65+
66+
}
67+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Arduino TFT text example
3+
4+
This example demonstrates how to draw text on the
5+
TFT with an Arduino. The Arduino reads the value
6+
of an analog sensor attached to pin A0, and writes
7+
the value to the LCD screen, updating every
8+
quarter second.
9+
10+
This example code is in the public domain
11+
12+
Created 15 April 2013 by Scott Fitzgerald
13+
14+
http://arduino.cc/en/Tutorial/TFTDisplayText
15+
16+
*/
17+
18+
#include <TFT.h> // Arduino LCD library
19+
#include <SPI.h>
20+
21+
// pin definition for the Uno
22+
#define cs 10
23+
#define dc 9
24+
#define rst 8
25+
26+
// pin definition for the Leonardo
27+
// #define cs 7
28+
// #define dc 0
29+
// #define rst 1
30+
31+
// create an instance of the library
32+
TFT TFTscreen = TFT(cs, dc, rst);
33+
34+
// char array to print to the screen
35+
char sensorPrintout[4];
36+
37+
void setup() {
38+
39+
// Put this line at the beginning of every sketch that uses the GLCD:
40+
TFTscreen.begin();
41+
42+
// clear the screen with a black background
43+
TFTscreen.background(0, 0, 0);
44+
45+
// write the static text to the screen
46+
// set the font color to white
47+
TFTscreen.stroke(255,255,255);
48+
// set the font size
49+
TFTscreen.setTextSize(2);
50+
// write the text to the top left corner of the screen
51+
TFTscreen.text("Sensor Value :\n ",0,0);
52+
// ste the font size very large for the loop
53+
TFTscreen.setTextSize(5);
54+
}
55+
56+
void loop() {
57+
58+
// Read the value of the sensor on A0
59+
String sensorVal = String(analogRead(A0));
60+
61+
// convert the reading to a char array
62+
sensorVal.toCharArray(sensorPrintout, 4);
63+
64+
// set the font color
65+
TFTscreen.stroke(255,255,255);
66+
// print the sensor value
67+
TFTscreen.text(sensorPrintout, 0, 20);
68+
// wait for a moment
69+
delay(250);
70+
// erase the text you just wrote
71+
TFTscreen.stroke(0,0,0);
72+
TFTscreen.text(sensorPrintout, 0, 20);
73+
}
74+

0 commit comments

Comments
 (0)