forked from arduino/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'arduino/TFT_display'
- Loading branch information
Showing
29 changed files
with
3,411 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
TFT Library | ||
============ | ||
|
||
An Arduino library for the Arduino TFT LCD screen. | ||
|
||
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. | ||
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. | ||
|
||
Onboard the screen is a SD card slot, which can be used through the SD library. | ||
|
||
The TFT library relies on the SPI library for communication with the screen and SD card, and needs to be included in all sketches. | ||
|
||
https://github.com/adafruit/Adafruit-GFX-Library | ||
https://github.com/adafruit/Adafruit-ST7735-Library | ||
http://arduino.cc/en/Reference/SD | ||
http://arduino.cc/en/Reference/SPI | ||
|
||
http://arduino.cc/en/Reference/TFTLibrary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "TFT.h" | ||
|
||
#if (USB_VID == 0x2341) && (USB_PID == 0x803C) // are we building for Esplora? | ||
TFT EsploraTFT(7, 0, 1); | ||
#endif | ||
|
||
TFT::TFT(uint8_t CS, uint8_t RS, uint8_t RST) | ||
: Adafruit_ST7735(CS, RS, RST) | ||
{ | ||
// as we already know the orientation (landscape, therefore rotated), | ||
// set default width and height without need to call begin() first. | ||
_width = ST7735_TFTHEIGHT; | ||
_height = ST7735_TFTWIDTH; | ||
} | ||
|
||
void TFT::begin() { | ||
initR(INITR_REDTAB); | ||
setRotation(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
#ifndef _ARDUINO_TFT_H | ||
#define _ARDUINO_TFT_H | ||
|
||
#include "Arduino.h" | ||
#include "utility/Adafruit_GFX.h" | ||
#include "utility/Adafruit_ST7735.h" | ||
|
||
/// The Arduino LCD is a ST7735-based device. | ||
/// By default, it is mounted horizontally. | ||
/// TFT class follows the convention of other | ||
/// Arduino library classes by adding a begin() method | ||
/// to be called in the setup() routine. | ||
/// @author Enrico Gueli <[email protected]> | ||
class TFT : public Adafruit_ST7735 { | ||
public: | ||
TFT(uint8_t CS, uint8_t RS, uint8_t RST); | ||
|
||
void begin(); | ||
}; | ||
|
||
/// Esplora boards have hard-wired connections with | ||
/// the Arduino LCD if mounted on the onboard connector. | ||
#if (USB_VID == 0x2341) && (USB_PID == 0x803C) // are we building for Esplora? | ||
extern TFT EsploraTFT; | ||
#endif | ||
|
||
#endif // _ARDUINO_TFT_H |
108 changes: 108 additions & 0 deletions
108
libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
Arduino TFT Bitmap Logo example | ||
This example reads an image file from a micro-SD card | ||
and draws it on the screen, at random locations. | ||
In this sketch, the Arduino logo is read from a micro-SD card. | ||
There is a .bmp file included with this sketch. | ||
- open the sketch folder (Ctrl-K or Cmd-K) | ||
- copy the "arduino.bmp" file to a micro-SD | ||
- put the SD into the SD slot of the Arduino TFT module. | ||
This example code is in the public domain. | ||
Created 19 April 2013 by Enrico Gueli | ||
http://arduino.cc/en/Tutorial/TFTBitmapLogo | ||
*/ | ||
|
||
// include the necessary libraries | ||
#include <SPI.h> | ||
#include <SD.h> | ||
#include <TFT.h> // Arduino LCD library | ||
|
||
// pin definition for the Uno | ||
#define sd_cs 4 | ||
#define lcd_cs 10 | ||
#define dc 9 | ||
#define rst 8 | ||
|
||
// pin definition for the Leonardo | ||
//#define sd_cs 8 | ||
//#define lcd_cs 7 | ||
//#define dc 0 | ||
//#define rst 1 | ||
|
||
TFT TFTscreen = TFT(lcd_cs, dc, rst); | ||
|
||
// this variable represents the image to be drawn on screen | ||
PImage logo; | ||
|
||
|
||
void setup() { | ||
// initialize the GLCD and show a message | ||
// asking the user to open the serial line | ||
TFTscreen.begin(); | ||
TFTscreen.background(255, 255, 255); | ||
|
||
TFTscreen.stroke(0, 0, 255); | ||
TFTscreen.println(); | ||
TFTscreen.println("Arduino TFT Bitmap Example"); | ||
TFTscreen.stroke(0, 0, 0); | ||
TFTscreen.println("Open serial monitor"); | ||
TFTscreen.println("to run the sketch"); | ||
|
||
// initialize the serial port: it will be used to | ||
// print some diagnostic info | ||
Serial.begin(9600); | ||
while (!Serial) { | ||
// wait for serial line to be ready | ||
} | ||
|
||
// clear the GLCD screen before starting | ||
TFTscreen.background(255, 255, 255); | ||
|
||
// try to access the SD card. If that fails (e.g. | ||
// no card present), the setup process will stop. | ||
Serial.print("Initializing SD card..."); | ||
if (!SD.begin(sd_cs)) { | ||
Serial.println("failed!"); | ||
return; | ||
} | ||
Serial.println("OK!"); | ||
|
||
// initialize and clear the GLCD screen | ||
TFTscreen.begin(); | ||
TFTscreen.background(255, 255, 255); | ||
|
||
// now that the SD card can be access, try to load the | ||
// image file. | ||
logo = TFTscreen.loadImage("arduino.bmp"); | ||
if (!logo.isValid()) { | ||
Serial.println("error while loading arduino.bmp"); | ||
} | ||
} | ||
|
||
void loop() { | ||
// don't do anything if the image wasn't loaded correctly. | ||
if (logo.isValid() == false) { | ||
return; | ||
} | ||
|
||
Serial.println("drawing image"); | ||
|
||
// get a random location where to draw the image. | ||
// To avoid the image to be draw outside the screen, | ||
// take into account the image size. | ||
int x = random(TFTscreen.width() - logo.width()); | ||
int y = random(TFTscreen.height() - logo.height()); | ||
|
||
// draw the image to the screen | ||
TFTscreen.image(logo, x, y); | ||
|
||
// wait a little bit before drawing again | ||
delay(1500); | ||
} |
Binary file not shown.
67 changes: 67 additions & 0 deletions
67
libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
TFT Color Picker | ||
This example for the Arduino screen reads the input of | ||
potentiometers or analog sensors attached to A0, A1, | ||
and A2 and uses the values to change the screen's color. | ||
This example code is in the public domain. | ||
Created 15 April 2013 by Scott Fitzgerald | ||
http://arduino.cc/en/Tutorial/TFTColorPicker | ||
*/ | ||
|
||
// pin definition for the Uno | ||
#define cs 10 | ||
#define dc 9 | ||
#define rst 8 | ||
|
||
// pin definition for the Leonardo | ||
// #define cs 7 | ||
// #define dc 0 | ||
// #define rst 1 | ||
|
||
#include <TFT.h> // Arduino LCD library | ||
#include <SPI.h> | ||
|
||
TFT TFTscreen = TFT(cs, dc, rst); | ||
|
||
void setup() { | ||
// begin serial communication | ||
Serial.begin(9600); | ||
|
||
// initialize the display | ||
TFTscreen.begin(); | ||
|
||
// set the background to white | ||
TFTscreen.background(255, 255, 255); | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
// read the values from your sensors and scale them to 0-255 | ||
int redVal = map(analogRead(A0), 0, 1023, 0, 255); | ||
int greenVal = map(analogRead(A1), 0, 1023, 0, 255); | ||
int blueVal = map(analogRead(A2), 0, 1023, 0, 255); | ||
|
||
// draw the background based on the mapped values | ||
TFTscreen.background(redVal, greenVal, blueVal); | ||
|
||
// send the values to the serial monitor | ||
Serial.print("background("); | ||
Serial.print(redVal); | ||
Serial.print(" , "); | ||
Serial.print(greenVal); | ||
Serial.print(" , "); | ||
Serial.print(blueVal); | ||
Serial.println(")"); | ||
|
||
// wait for a moment | ||
delay(33); | ||
|
||
} | ||
|
74 changes: 74 additions & 0 deletions
74
libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
Arduino TFT text example | ||
This example demonstrates how to draw text on the | ||
TFT with an Arduino. The Arduino reads the value | ||
of an analog sensor attached to pin A0, and writes | ||
the value to the LCD screen, updating every | ||
quarter second. | ||
This example code is in the public domain | ||
Created 15 April 2013 by Scott Fitzgerald | ||
http://arduino.cc/en/Tutorial/TFTDisplayText | ||
*/ | ||
|
||
#include <TFT.h> // Arduino LCD library | ||
#include <SPI.h> | ||
|
||
// pin definition for the Uno | ||
#define cs 10 | ||
#define dc 9 | ||
#define rst 8 | ||
|
||
// pin definition for the Leonardo | ||
// #define cs 7 | ||
// #define dc 0 | ||
// #define rst 1 | ||
|
||
// create an instance of the library | ||
TFT TFTscreen = TFT(cs, dc, rst); | ||
|
||
// char array to print to the screen | ||
char sensorPrintout[4]; | ||
|
||
void setup() { | ||
|
||
// Put this line at the beginning of every sketch that uses the GLCD: | ||
TFTscreen.begin(); | ||
|
||
// clear the screen with a black background | ||
TFTscreen.background(0, 0, 0); | ||
|
||
// write the static text to the screen | ||
// set the font color to white | ||
TFTscreen.stroke(255,255,255); | ||
// set the font size | ||
TFTscreen.setTextSize(2); | ||
// write the text to the top left corner of the screen | ||
TFTscreen.text("Sensor Value :\n ",0,0); | ||
// ste the font size very large for the loop | ||
TFTscreen.setTextSize(5); | ||
} | ||
|
||
void loop() { | ||
|
||
// Read the value of the sensor on A0 | ||
String sensorVal = String(analogRead(A0)); | ||
|
||
// convert the reading to a char array | ||
sensorVal.toCharArray(sensorPrintout, 4); | ||
|
||
// set the font color | ||
TFTscreen.stroke(255,255,255); | ||
// print the sensor value | ||
TFTscreen.text(sensorPrintout, 0, 20); | ||
// wait for a moment | ||
delay(250); | ||
// erase the text you just wrote | ||
TFTscreen.stroke(0,0,0); | ||
TFTscreen.text(sensorPrintout, 0, 20); | ||
} | ||
|
Oops, something went wrong.