| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

graphicstest.ino
Go to the documentation of this file.
1 /***************************************************
2 This is our GFX example for the Adafruit ILI9341 Breakout and Shield
3 ----> http://www.adafruit.com/products/1651
4
5 Check out the links above for our tutorials and wiring diagrams
6 These displays use SPI to communicate, 4 or 5 pins are required to
7 interface (RST is optional)
8 Adafruit invests time and resources providing this open source code,
9 please support Adafruit and open-source hardware by purchasing
10 products from Adafruit!
11
12 Written by Limor Fried/Ladyada for Adafruit Industries.
13 MIT license, all text above must be included in any redistribution
14 ****************************************************/
15
16
17 #include "SPI.h"
18 #include "Adafruit_GFX.h"
19 #include "Adafruit_ILI9341.h"
20
21 // For the Adafruit shield, these are the default.
22 #define TFT_DC 9
23 #define TFT_CS 10
24
25 // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
26 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
27 // If using the breakout, change pins as desired
28 //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
29
30 void setup()
31 {
32 Serial.begin(9600);
33 Serial.println("ILI9341 Test!");
34
35 tft.begin();
36
37 // read diagnostics (optional but can help debug problems)
38 uint8_t x = tft.readcommand8(ILI9341_RDMODE);
39 Serial.print("Display Power Mode: 0x");
40 Serial.println(x, HEX);
41 x = tft.readcommand8(ILI9341_RDMADCTL);
42 Serial.print("MADCTL Mode: 0x");
43 Serial.println(x, HEX);
44 x = tft.readcommand8(ILI9341_RDPIXFMT);
45 Serial.print("Pixel Format: 0x");
46 Serial.println(x, HEX);
47 x = tft.readcommand8(ILI9341_RDIMGFMT);
48 Serial.print("Image Format: 0x");
49 Serial.println(x, HEX);
50 x = tft.readcommand8(ILI9341_RDSELFDIAG);
51 Serial.print("Self Diagnostic: 0x");
52 Serial.println(x, HEX);
53
54 Serial.println(F("Benchmark Time (microseconds)"));
55 delay(10);
56 Serial.print(F("Screen fill "));
57 Serial.println(testFillScreen());
58 delay(500);
59
60 Serial.print(F("Text "));
61 Serial.println(testText());
62 delay(3000);
63
64 Serial.print(F("Lines "));
65 Serial.println(testLines(ILI9341_CYAN));
66 delay(500);
67
68 Serial.print(F("Horiz/Vert Lines "));
69 Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
70 delay(500);
71
72 Serial.print(F("Rectangles (outline) "));
73 Serial.println(testRects(ILI9341_GREEN));
74 delay(500);
75
76 Serial.print(F("Rectangles (filled) "));
77 Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
78 delay(500);
79
80 Serial.print(F("Circles (filled) "));
81 Serial.println(testFilledCircles(10, ILI9341_MAGENTA));
82
83 Serial.print(F("Circles (outline) "));
84 Serial.println(testCircles(10, ILI9341_WHITE));
85 delay(500);
86
87 Serial.print(F("Triangles (outline) "));
88 Serial.println(testTriangles());
89 delay(500);
90
91 Serial.print(F("Triangles (filled) "));
92 Serial.println(testFilledTriangles());
93 delay(500);
94
95 Serial.print(F("Rounded rects (outline) "));
96 Serial.println(testRoundRects());
97 delay(500);
98
99 Serial.print(F("Rounded rects (filled) "));
100 Serial.println(testFilledRoundRects());
101 delay(500);
102
103 Serial.println(F("Done!"));
104
105 }
106
107
108 void loop(void)
109 {
110 for (uint8_t rotation=0; rotation<4; rotation++)
111 {
112 tft.setRotation(rotation);
113 testText();
114 delay(1000);
115 }
116 }
117
118 unsigned long testFillScreen()
119 {
120 unsigned long start = micros();
121 tft.fillScreen(ILI9341_BLACK);
122 yield();
123 tft.fillScreen(ILI9341_RED);
124 yield();
125 tft.fillScreen(ILI9341_GREEN);
126 yield();
127 tft.fillScreen(ILI9341_BLUE);
128 yield();
129 tft.fillScreen(ILI9341_BLACK);
130 yield();
131 return micros() - start;
132 }
133
134 unsigned long testText()
135 {
136 tft.fillScreen(ILI9341_BLACK);
137 unsigned long start = micros();
138 tft.setCursor(0, 0);
139 tft.setTextColor(ILI9341_WHITE);
140 tft.setTextSize(1);
141 tft.println("Hello World!");
142 tft.setTextColor(ILI9341_YELLOW);
143 tft.setTextSize(2);
144 tft.println(1234.56);
145 tft.setTextColor(ILI9341_RED);
146 tft.setTextSize(3);
147 tft.println(0xDEADBEEF, HEX);
148 tft.println();
149 tft.setTextColor(ILI9341_GREEN);
150 tft.setTextSize(5);
151 tft.println("Groop");
152 tft.setTextSize(2);
153 tft.println("I implore thee,");
154 tft.setTextSize(1);
155 tft.println("my foonting turlingdromes.");
156 tft.println("And hooptiously drangle me");
157 tft.println("with crinkly bindlewurdles,");
158 tft.println("Or I will rend thee");
159 tft.println("in the gobberwarts");
160 tft.println("with my blurglecruncheon,");
161 tft.println("see if I don't!");
162 return micros() - start;
163 }
164
165 unsigned long testLines(uint16_t color)
166 {
167 unsigned long start, t;
168 int x1, y1, x2, y2,
169 w = tft.width(),
170 h = tft.height();
171
172 tft.fillScreen(ILI9341_BLACK);
173 yield();
174
175 x1 = y1 = 0;
176 y2 = h - 1;
177 start = micros();
178 for (x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
179 x2 = w - 1;
180 for (y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
181 t = micros() - start; // fillScreen doesn't count against timing
182
183 yield();
184 tft.fillScreen(ILI9341_BLACK);
185 yield();
186
187 x1 = w - 1;
188 y1 = 0;
189 y2 = h - 1;
190 start = micros();
191 for (x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
192 x2 = 0;
193 for (y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
194 t += micros() - start;
195
196 yield();
197 tft.fillScreen(ILI9341_BLACK);
198 yield();
199
200 x1 = 0;
201 y1 = h - 1;
202 y2 = 0;
203 start = micros();
204 for (x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
205 x2 = w - 1;
206 for (y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
207 t += micros() - start;
208
209 yield();
210 tft.fillScreen(ILI9341_BLACK);
211 yield();
212
213 x1 = w - 1;
214 y1 = h - 1;
215 y2 = 0;
216 start = micros();
217 for (x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
218 x2 = 0;
219 for (y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
220
221 yield();
222 return micros() - start;
223 }
224
225 unsigned long testFastLines(uint16_t color1, uint16_t color2)
226 {
227 unsigned long start;
228 int x, y, w = tft.width(), h = tft.height();
229
230 tft.fillScreen(ILI9341_BLACK);
231 start = micros();
232 for (y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
233 for (x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
234
235 return micros() - start;
236 }
237
238 unsigned long testRects(uint16_t color)
239 {
240 unsigned long start;
241 int n, i, i2,
242 cx = tft.width() / 2,
243 cy = tft.height() / 2;
244
245 tft.fillScreen(ILI9341_BLACK);
246 n = min(tft.width(), tft.height());
247 start = micros();
248 for (i=2; i<n; i+=6)
249 {
250 i2 = i / 2;
251 tft.drawRect(cx-i2, cy-i2, i, i, color);
252 }
253
254 return micros() - start;
255 }
256
257 unsigned long testFilledRects(uint16_t color1, uint16_t color2)
258 {
259 unsigned long start, t = 0;
260 int n, i, i2,
261 cx = tft.width() / 2 - 1,
262 cy = tft.height() / 2 - 1;
263
264 tft.fillScreen(ILI9341_BLACK);
265 n = min(tft.width(), tft.height());
266 for (i=n; i>0; i-=6)
267 {
268 i2 = i / 2;
269 start = micros();
270 tft.fillRect(cx-i2, cy-i2, i, i, color1);
271 t += micros() - start;
272 // Outlines are not included in timing results
273 tft.drawRect(cx-i2, cy-i2, i, i, color2);
274 yield();
275 }
276
277 return t;
278 }
279
280 unsigned long testFilledCircles(uint8_t radius, uint16_t color)
281 {
282 unsigned long start;
283 int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
284
285 tft.fillScreen(ILI9341_BLACK);
286 start = micros();
287 for (x=radius; x<w; x+=r2)
288 {
289 for (y=radius; y<h; y+=r2)
290 {
291 tft.fillCircle(x, y, radius, color);
292 }
293 }
294
295 return micros() - start;
296 }
297
298 unsigned long testCircles(uint8_t radius, uint16_t color)
299 {
300 unsigned long start;
301 int x, y, r2 = radius * 2,
302 w = tft.width() + radius,
303 h = tft.height() + radius;
304
305 // Screen is not cleared for this one -- this is
306 // intentional and does not affect the reported time.
307 start = micros();
308 for (x=0; x<w; x+=r2)
309 {
310 for (y=0; y<h; y+=r2)
311 {
312 tft.drawCircle(x, y, radius, color);
313 }
314 }
315
316 return micros() - start;
317 }
318
319 unsigned long testTriangles()
320 {
321 unsigned long start;
322 int n, i, cx = tft.width() / 2 - 1,
323 cy = tft.height() / 2 - 1;
324
325 tft.fillScreen(ILI9341_BLACK);
326 n = min(cx, cy);
327 start = micros();
328 for (i=0; i<n; i+=5)
329 {
330 tft.drawTriangle(
331 cx , cy - i, // peak
332 cx - i, cy + i, // bottom left
333 cx + i, cy + i, // bottom right
334 tft.color565(i, i, i));
335 }
336
337 return micros() - start;
338 }
339
340 unsigned long testFilledTriangles()
341 {
342 unsigned long start, t = 0;
343 int i, cx = tft.width() / 2 - 1,
344 cy = tft.height() / 2 - 1;
345
346 tft.fillScreen(ILI9341_BLACK);
347 start = micros();
348 for (i=min(cx,cy); i>10; i-=5)
349 {
350 start = micros();
351 tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
352 tft.color565(0, i*10, i*10));
353 t += micros() - start;
354 tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
355 tft.color565(i*10, i*10, 0));
356 yield();
357 }
358
359 return t;
360 }
361
362 unsigned long testRoundRects()
363 {
364 unsigned long start;
365 int w, i, i2,
366 cx = tft.width() / 2 - 1,
367 cy = tft.height() / 2 - 1;
368
369 tft.fillScreen(ILI9341_BLACK);
370 w = min(tft.width(), tft.height());
371 start = micros();
372 for (i=0; i<w; i+=6)
373 {
374 i2 = i / 2;
375 tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
376 }
377
378 return micros() - start;
379 }
380
381 unsigned long testFilledRoundRects()
382 {
383 unsigned long start;
384 int i, i2,
385 cx = tft.width() / 2 - 1,
386 cy = tft.height() / 2 - 1;
387
388 tft.fillScreen(ILI9341_BLACK);
389 start = micros();
390 for (i=min(tft.width(), tft.height()); i>20; i-=6)
391 {
392 i2 = i / 2;
393 tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
394 yield();
395 }
396
397 return micros() - start;
398 }
testCircles
unsigned long testCircles(uint8_t radius, uint16_t color)
Definition: graphicstest.ino:298
loop
static void loop(void)
Definition: graphicstest.ino:108
Adafruit_GFX::drawRect
virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Definition: Adafruit_GFX.cpp:264
Adafruit_GFX::height
int16_t height(void) const
Definition: Adafruit_GFX.cpp:1025
testTriangles
unsigned long testTriangles()
Definition: graphicstest.ino:319
testFillScreen
unsigned long testFillScreen()
Definition: graphicstest.ino:118
Adafruit_GFX::fillRoundRect
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
Definition: Adafruit_GFX.cpp:319
Adafruit_GFX::drawRoundRect
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
Definition: Adafruit_GFX.cpp:303
Adafruit_GFX::drawTriangle
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Definition: Adafruit_GFX.cpp:331
Adafruit_ILI9341::color565
uint16_t color565(uint8_t r, uint8_t g, uint8_t b)
Definition: Adafruit_ILI9341.cpp:599
Adafruit_GFX::setCursor
void setCursor(int16_t x, int16_t y)
Definition: Adafruit_GFX.cpp:709
Adafruit_GFX::fillTriangle
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Definition: Adafruit_GFX.cpp:340
Adafruit_GFX::width
int16_t width(void) const
Definition: Adafruit_GFX.cpp:1020
Adafruit_ILI9341::begin
void begin(void)
Definition: Adafruit_ILI9341.cpp:219
ILI9341_WHITE
#define ILI9341_WHITE
Definition: Adafruit_ILI9341.h:113
ILI9341_MAGENTA
#define ILI9341_MAGENTA
Definition: Adafruit_ILI9341.h:111
Adafruit_ILI9341::drawFastHLine
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Definition: Adafruit_ILI9341.cpp:521
min
#define min(a, b)
Definition: Adafruit_GFX.cpp:66
ILI9341_BLACK
#define ILI9341_BLACK
Definition: Adafruit_ILI9341.h:98
ILI9341_RDMODE
#define ILI9341_RDMODE
Definition: Adafruit_ILI9341.h:50
ILI9341_RED
#define ILI9341_RED
Definition: Adafruit_ILI9341.h:110
Adafruit_ILI9341::readcommand8
uint8_t readcommand8(uint8_t reg, uint8_t index=0)
Definition: Adafruit_ILI9341.cpp:708
ILI9341_RDMADCTL
#define ILI9341_RDMADCTL
Definition: Adafruit_ILI9341.h:51
ILI9341_YELLOW
#define ILI9341_YELLOW
Definition: Adafruit_ILI9341.h:112
testRoundRects
unsigned long testRoundRects()
Definition: graphicstest.ino:362
ILI9341_RDIMGFMT
#define ILI9341_RDIMGFMT
Definition: Adafruit_ILI9341.h:53
Adafruit_GFX.h
tft
Adafruit_ILI9341 tft
Definition: graphicstest.ino:26
ILI9341_RDPIXFMT
#define ILI9341_RDPIXFMT
Definition: Adafruit_ILI9341.h:52
Adafruit_GFX::setTextColor
void setTextColor(uint16_t c)
Definition: Adafruit_GFX.cpp:730
setup
static void setup()
Definition: graphicstest.ino:30
testText
unsigned long testText()
Definition: graphicstest.ino:134
Adafruit_ILI9341::setRotation
void setRotation(uint8_t r)
Definition: Adafruit_ILI9341.cpp:613
testFilledTriangles
unsigned long testFilledTriangles()
Definition: graphicstest.ino:340
testFilledCircles
unsigned long testFilledCircles(uint8_t radius, uint16_t color)
Definition: graphicstest.ino:280
Adafruit_GFX::drawLine
virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Definition: Adafruit_GFX.cpp:212
Adafruit_GFX::drawCircle
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Definition: Adafruit_GFX.cpp:88
ILI9341_BLUE
#define ILI9341_BLUE
Definition: Adafruit_ILI9341.h:107
ILI9341_CYAN
#define ILI9341_CYAN
Definition: Adafruit_ILI9341.h:109
Adafruit_ILI9341::drawFastVLine
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Definition: Adafruit_ILI9341.cpp:482
Adafruit_GFX::fillCircle
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Definition: Adafruit_GFX.cpp:168
ILI9341_GREEN
#define ILI9341_GREEN
Definition: Adafruit_ILI9341.h:108
testFilledRoundRects
unsigned long testFilledRoundRects()
Definition: graphicstest.ino:381
x
int32_t x
Definition: LTC2492_Thermocouple_Meter.ino:119
Adafruit_ILI9341::fillScreen
void fillScreen(uint16_t color)
Definition: Adafruit_ILI9341.cpp:552
start
static float start
Definition: Audio_Spectrum_Analyzer.ino:19
testRects
unsigned long testRects(uint16_t color)
Definition: graphicstest.ino:238
Adafruit_GFX::setTextSize
void setTextSize(uint8_t s)
Definition: Adafruit_GFX.cpp:725
TFT_DC
#define TFT_DC
Definition: graphicstest.ino:22
testFilledRects
unsigned long testFilledRects(uint16_t color1, uint16_t color2)
Definition: graphicstest.ino:257
Adafruit_ILI9341::fillRect
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Definition: Adafruit_ILI9341.cpp:558
i
static int i
Definition: DC2430A.ino:184
ILI9341_RDSELFDIAG
#define ILI9341_RDSELFDIAG
Definition: Adafruit_ILI9341.h:54
Adafruit_ILI9341.h
Adafruit_ILI9341
Definition: Adafruit_ILI9341.h:118
testLines
unsigned long testLines(uint16_t color)
Definition: graphicstest.ino:165
TFT_CS
#define TFT_CS
Definition: graphicstest.ino:23
testFastLines
unsigned long testFastLines(uint16_t color1, uint16_t color2)
Definition: graphicstest.ino:225