You are on page 1of 3

// include the necessary libraries

#include <SPI.h>
#include <SD.h>
#include <TFT.h> // Hardware-specific library

// pin definition for the Uno


#define SD_CS 11
#define LCD_CS 10
#define DC 9
#define RESET 8

// pin definition for the Leonardo


// #define SD_CS 8
// #define LCD_CS 7
// #define DC 0
// #define RESET 1

TFT myScreen = TFT(LCD_CS, DC, RESET);

// this variable represents the image to be drawn on screen


PImage image;

void setup() {
// initialize the serial port
Serial.begin(9600);
while (!Serial) {
// wait for serial line to be ready
// needed for the Leonardo
}

// try to access the SD card


Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS)) {
Serial.println("failed!");
return;
}
Serial.println("OK!");

// initialize and clear the GLCD screen


myScreen.begin();
myScreen.background(255, 255, 255);

// load the image from the SD card


image = myScreen.loadImage("arduino.bmp");

// check if the image loaded properly


if (image.isValid() != true) {
Serial.println("error while loading arduino.bmp");
}

//write the image on screen


myScreen.image(image, 0, 0);
}

void loop(){
// nothing happening here
}
For the Esplora :

// include the necessary libraries


#include <SPI.h>
#include <SD.h>
#include <TFT.h> // Hardware-specific library
#include <Esplora.h>

// SD Chip Select pin


#define SD_CS 8

// this variable represents the image to be drawn on screen


PImage image;

void setup() {
// initialize the serial port
Serial.begin(9600);
while (!Serial) {
// wait for serial line to be ready
}

// try to access the SD card


Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS)) {
Serial.println("failed!");
return;
}
Serial.println("OK!");

// initialize and clear the GLCD screen


EsploraTFT.begin();
EsploraTFT.background(255, 255, 255);

// load the image from the SD card


image = EsploraTFT.loadImage("arduino.bmp");

// check if the image loaded properly


if (image.isValid() != true) {
Serial.println("error while loading arduino.bmp");
}

//write the image on screen


EsploraTFT.image(image, 0, 0);
}

void loop(){
// nothing happening here
}
[Get Code]
Next steps
Now that you have tested the basic functionality of the screen, see the TFT library
pages for information about the library's API and additional examples. See the
hardware page for more information about the screen's components. It's also
recommended to visit the Adafruit graphics library page for additional information
on functions not covered.

The text of the Arduino getting started guide is licensed under a Creative Commons
Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the
public domain.

NEWSLETTER
Enter your email to sign up

You might also like