1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-04 15:24:12 +01:00
Arduino/libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino

102 lines
2.6 KiB
Arduino
Raw Normal View History

2013-05-17 12:39:31 +02:00
/*
Esplora TFT Bitmap Logos
2013-05-17 12:39:31 +02:00
This example for the Arduino TFT screen is for use
with an Arduino Esplora.
2013-05-17 12:39:31 +02:00
This example reads an image file from a micro-SD card
and draws it on the screen, at random locations.
There is a .bmp file included with this sketch.
2013-05-17 12:39:31 +02:00
- 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 LCD module.
2013-05-17 12:39:31 +02:00
This example code is in the public domain.
2013-05-17 12:39:31 +02:00
Created 19 April 2013 by Enrico Gueli
2013-05-17 12:39:31 +02:00
http://arduino.cc/en/Tutorial/EsploraTFTBitmapLogo
2013-05-17 12:39:31 +02:00
*/
2013-05-17 12:39:31 +02:00
// include the necessary libraries
#include <Esplora.h>
#include <SPI.h>
#include <SD.h>
#include <TFT.h> // Arduino LCD library
// the Esplora pin connected to the chip select line for SD card
#define SD_CS 8
// 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
EsploraTFT.begin();
EsploraTFT.background(255, 255, 255);
EsploraTFT.stroke(0, 0, 255);
EsploraTFT.println();
EsploraTFT.println(F("Arduino LCD Bitmap Example"));
2013-05-17 12:39:31 +02:00
EsploraTFT.stroke(0, 0, 0);
EsploraTFT.println(F("Open serial monitor"));
EsploraTFT.println(F("to run the sketch"));
2013-05-17 12:39:31 +02:00
// initialize the serial port: it will be used to
2013-05-17 12:39:31 +02:00
// print some diagnostic info
Serial.begin(9600);
while (!Serial) {
// wait for serial monitor to be open
}
2013-05-17 12:39:31 +02:00
// try to access the SD card. If that fails (e.g.
// no card present), the Esplora's LED will turn red.
Serial.print(F("Initializing SD card..."));
2013-05-17 12:39:31 +02:00
if (!SD.begin(SD_CS)) {
Serial.println(F("failed!"));
2013-05-17 12:39:31 +02:00
Esplora.writeRed(255);
return;
}
Serial.println("OK!");
2013-05-17 12:39:31 +02:00
// clear the GLCD screen before starting
EsploraTFT.background(255, 255, 255);
2013-05-17 12:39:31 +02:00
// now that the SD card can be access, try to load the
// image file. The Esplora LED will turn green or red if
// the loading went OK or not.
Esplora.writeRGB(0, 0, 0);
logo = EsploraTFT.loadImage("arduino.bmp");
if (logo.isValid()) {
Esplora.writeGreen(255);
}
else
Esplora.writeRed(255);
}
void loop() {
// don't do anything if the image wasn't loaded correctly.
if (logo.isValid() == false) {
return;
}
Serial.println(F("drawing image"));
2013-05-17 12:39:31 +02:00
// 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(EsploraTFT.width() - logo.width());
int y = random(EsploraTFT.height() - logo.height());
2013-05-17 12:39:31 +02:00
// draw the image to the screen
EsploraTFT.image(logo, x, y);
2013-05-17 12:39:31 +02:00
// wait a little bit before drawing again
delay(1500);
}