source: rtos_arduino/trunk/arduino_lib/libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 2.6 KB
Line 
1/*
2
3 Esplora TFT Bitmap Logos
4
5 This example for the Arduino TFT screen is for use
6 with an Arduino Esplora.
7
8 This example reads an image file from a micro-SD card
9 and draws it on the screen, at random locations.
10
11 There is a .bmp file included with this sketch.
12 - open the sketch folder (Ctrl-K or Cmd-K)
13 - copy the "arduino.bmp" file to a micro-SD
14 - put the SD into the SD slot of the Arduino LCD module.
15
16 This example code is in the public domain.
17
18 Created 19 April 2013 by Enrico Gueli
19
20 http://arduino.cc/en/Tutorial/EsploraTFTBitmapLogo
21
22 */
23
24// include the necessary libraries
25#include <Esplora.h>
26#include <SPI.h>
27#include <SD.h>
28#include <TFT.h> // Arduino LCD library
29
30// the Esplora pin connected to the chip select line for SD card
31#define SD_CS 8
32
33// this variable represents the image to be drawn on screen
34PImage logo;
35
36void setup() {
37 // initialize the GLCD and show a message
38 // asking the user to open the serial line
39 EsploraTFT.begin();
40 EsploraTFT.background(255, 255, 255);
41
42 EsploraTFT.stroke(0, 0, 255);
43 EsploraTFT.println();
44 EsploraTFT.println(F("Arduino LCD Bitmap Example"));
45 EsploraTFT.stroke(0, 0, 0);
46 EsploraTFT.println(F("Open serial monitor"));
47 EsploraTFT.println(F("to run the sketch"));
48
49 // initialize the serial port: it will be used to
50 // print some diagnostic info
51 Serial.begin(9600);
52 while (!Serial) {
53 // wait for serial monitor to be open
54 }
55
56 // try to access the SD card. If that fails (e.g.
57 // no card present), the Esplora's LED will turn red.
58 Serial.print(F("Initializing SD card..."));
59 if (!SD.begin(SD_CS)) {
60 Serial.println(F("failed!"));
61 Esplora.writeRed(255);
62 return;
63 }
64 Serial.println("OK!");
65
66 // clear the GLCD screen before starting
67 EsploraTFT.background(255, 255, 255);
68
69 // now that the SD card can be access, try to load the
70 // image file. The Esplora LED will turn green or red if
71 // the loading went OK or not.
72 Esplora.writeRGB(0, 0, 0);
73 logo = EsploraTFT.loadImage("arduino.bmp");
74 if (logo.isValid()) {
75 Esplora.writeGreen(255);
76 }
77 else
78 Esplora.writeRed(255);
79
80}
81
82void loop() {
83 // don't do anything if the image wasn't loaded correctly.
84 if (logo.isValid() == false) {
85 return;
86 }
87
88 Serial.println(F("drawing image"));
89
90 // get a random location where to draw the image.
91 // To avoid the image to be draw outside the screen,
92 // take into account the image size.
93 int x = random(EsploraTFT.width() - logo.width());
94 int y = random(EsploraTFT.height() - logo.height());
95
96 // draw the image to the screen
97 EsploraTFT.image(logo, x, y);
98
99 // wait a little bit before drawing again
100 delay(1500);
101}
Note: See TracBrowser for help on using the repository browser.