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
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);
42  Serial.print("MADCTL Mode: 0x");
43  Serial.println(x, HEX);
45  Serial.print("Pixel Format: 0x");
46  Serial.println(x, HEX);
48  Serial.print("Image Format: 0x");
49  Serial.println(x, HEX);
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) "));
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();
122  yield();
123  tft.fillScreen(ILI9341_RED);
124  yield();
126  yield();
128  yield();
130  yield();
131  return micros() - start;
132 }
133 
134 unsigned long testText()
135 {
137  unsigned long start = micros();
138  tft.setCursor(0, 0);
140  tft.setTextSize(1);
141  tft.println("Hello World!");
143  tft.setTextSize(2);
144  tft.println(1234.56);
146  tft.setTextSize(3);
147  tft.println(0xDEADBEEF, HEX);
148  tft.println();
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 
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();
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();
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();
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 
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 
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 
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 
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 
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 
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 
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 
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 }
unsigned long testCircles(uint8_t radius, uint16_t color)
static void loop(void)
virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
int16_t height(void) const
unsigned long testTriangles()
unsigned long testFillScreen()
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
uint16_t color565(uint8_t r, uint8_t g, uint8_t b)
void setCursor(int16_t x, int16_t y)
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
int16_t width(void) const
#define ILI9341_WHITE
#define ILI9341_MAGENTA
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
#define min(a, b)
#define ILI9341_BLACK
#define ILI9341_RDMODE
#define ILI9341_RED
uint8_t readcommand8(uint8_t reg, uint8_t index=0)
#define ILI9341_RDMADCTL
#define ILI9341_YELLOW
unsigned long testRoundRects()
#define ILI9341_RDIMGFMT
Adafruit_ILI9341 tft
#define ILI9341_RDPIXFMT
void setTextColor(uint16_t c)
static void setup()
unsigned long testText()
void setRotation(uint8_t r)
unsigned long testFilledTriangles()
unsigned long testFilledCircles(uint8_t radius, uint16_t color)
virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
#define ILI9341_BLUE
#define ILI9341_CYAN
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
#define ILI9341_GREEN
unsigned long testFilledRoundRects()
void fillScreen(uint16_t color)
static float start
unsigned long testRects(uint16_t color)
void setTextSize(uint8_t s)
#define TFT_DC
unsigned long testFilledRects(uint16_t color1, uint16_t color2)
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
static int i
Definition: DC2430A.ino:184
#define ILI9341_RDSELFDIAG
unsigned long testLines(uint16_t color)
#define TFT_CS
unsigned long testFastLines(uint16_t color1, uint16_t color2)