Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  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 "ILI9341_t3.h"
  19.  
  20. // For the Adafruit shield, these are the default.
  21. #define TFT_DC 9
  22. #define TFT_CS 10
  23.  
  24. // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
  25. ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
  26.  
  27. void setup() {
  28. tft.begin();
  29. tft.fillScreen(ILI9341_BLACK);
  30. tft.setTextColor(ILI9341_YELLOW);
  31. tft.setTextSize(2);
  32. tft.println("Waiting for Arduino Serial Monitor...");
  33.  
  34. Serial.begin(9600);
  35. while (!Serial) ; // wait for Arduino Serial Monitor
  36. Serial.println("ILI9341 Test!");
  37.  
  38. // read diagnostics (optional but can help debug problems)
  39. uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  40. Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  41. x = tft.readcommand8(ILI9341_RDMADCTL);
  42. Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  43. x = tft.readcommand8(ILI9341_RDPIXFMT);
  44. Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  45. x = tft.readcommand8(ILI9341_RDIMGFMT);
  46. Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  47. x = tft.readcommand8(ILI9341_RDSELFDIAG);
  48. Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
  49.  
  50. Serial.println(F("Benchmark Time (microseconds)"));
  51.  
  52. Serial.print(F("Screen fill "));
  53. Serial.println(testFillScreen());
  54. delay(200);
  55.  
  56. Serial.print(F("Text "));
  57. Serial.println(testText());
  58. delay(600);
  59.  
  60. Serial.print(F("Lines "));
  61. Serial.println(testLines(ILI9341_CYAN));
  62. delay(200);
  63.  
  64. Serial.print(F("Horiz/Vert Lines "));
  65. Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
  66. delay(200);
  67.  
  68. Serial.print(F("Rectangles (outline) "));
  69. Serial.println(testRects(ILI9341_GREEN));
  70. delay(200);
  71.  
  72. Serial.print(F("Rectangles (filled) "));
  73. Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
  74. delay(200);
  75.  
  76. Serial.print(F("Circles (filled) "));
  77. Serial.println(testFilledCircles(10, ILI9341_MAGENTA));
  78.  
  79. Serial.print(F("Circles (outline) "));
  80. Serial.println(testCircles(10, ILI9341_WHITE));
  81. delay(200);
  82.  
  83. Serial.print(F("Triangles (outline) "));
  84. Serial.println(testTriangles());
  85. delay(200);
  86.  
  87. Serial.print(F("Triangles (filled) "));
  88. Serial.println(testFilledTriangles());
  89. delay(200);
  90.  
  91. Serial.print(F("Rounded rects (outline) "));
  92. Serial.println(testRoundRects());
  93. delay(200);
  94.  
  95. Serial.print(F("Rounded rects (filled) "));
  96. Serial.println(testFilledRoundRects());
  97. delay(200);
  98.  
  99. Serial.println(F("Done!"));
  100.  
  101. }
  102.  
  103.  
  104. void loop(void) {
  105. for(uint8_t rotation=0; rotation<4; rotation++) {
  106. tft.setRotation(rotation);
  107. testText();
  108. delay(1000);
  109. }
  110. }
  111.  
  112. unsigned long testFillScreen() {
  113. unsigned long start = micros();
  114. tft.fillScreen(ILI9341_BLACK);
  115. tft.fillScreen(ILI9341_RED);
  116. tft.fillScreen(ILI9341_GREEN);
  117. tft.fillScreen(ILI9341_BLUE);
  118. tft.fillScreen(ILI9341_BLACK);
  119. return micros() - start;
  120. }
  121.  
  122. unsigned long testText() {
  123. tft.fillScreen(ILI9341_BLACK);
  124. unsigned long start = micros();
  125. tft.setCursor(0, 0);
  126. tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1);
  127. tft.println("Hello World!");
  128. tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
  129. tft.println(1234.56);
  130. tft.setTextColor(ILI9341_RED); tft.setTextSize(3);
  131. tft.println(0xDEADBEEF, HEX);
  132. tft.println();
  133. tft.setTextColor(ILI9341_GREEN);
  134. tft.setTextSize(5);
  135. tft.println("Groop");
  136. tft.setTextSize(2);
  137. tft.println("I implore thee,");
  138. tft.setTextSize(1);
  139. tft.println("my foonting turlingdromes.");
  140. tft.println("And hooptiously drangle me");
  141. tft.println("with crinkly bindlewurdles,");
  142. tft.println("Or I will rend thee");
  143. tft.println("in the gobberwarts");
  144. tft.println("with my blurglecruncheon,");
  145. tft.println("see if I don't!");
  146. return micros() - start;
  147. }
  148.  
  149. unsigned long testLines(uint16_t color) {
  150. unsigned long start, t;
  151. int x1, y1, x2, y2,
  152. w = tft.width(),
  153. h = tft.height();
  154.  
  155. tft.fillScreen(ILI9341_BLACK);
  156.  
  157. x1 = y1 = 0;
  158. y2 = h - 1;
  159. start = micros();
  160. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  161. x2 = w - 1;
  162. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  163. t = micros() - start; // fillScreen doesn't count against timing
  164.  
  165. tft.fillScreen(ILI9341_BLACK);
  166.  
  167. x1 = w - 1;
  168. y1 = 0;
  169. y2 = h - 1;
  170. start = micros();
  171. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  172. x2 = 0;
  173. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  174. t += micros() - start;
  175.  
  176. tft.fillScreen(ILI9341_BLACK);
  177.  
  178. x1 = 0;
  179. y1 = h - 1;
  180. y2 = 0;
  181. start = micros();
  182. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  183. x2 = w - 1;
  184. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  185. t += micros() - start;
  186.  
  187. tft.fillScreen(ILI9341_BLACK);
  188.  
  189. x1 = w - 1;
  190. y1 = h - 1;
  191. y2 = 0;
  192. start = micros();
  193. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  194. x2 = 0;
  195. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  196.  
  197. return micros() - start;
  198. }
  199.  
  200. unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  201. unsigned long start;
  202. int x, y, w = tft.width(), h = tft.height();
  203.  
  204. tft.fillScreen(ILI9341_BLACK);
  205. start = micros();
  206. for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  207. for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
  208.  
  209. return micros() - start;
  210. }
  211.  
  212. unsigned long testRects(uint16_t color) {
  213. unsigned long start;
  214. int n, i, i2,
  215. cx = tft.width() / 2,
  216. cy = tft.height() / 2;
  217.  
  218. tft.fillScreen(ILI9341_BLACK);
  219. n = min(tft.width(), tft.height());
  220. start = micros();
  221. for(i=2; i<n; i+=6) {
  222. i2 = i / 2;
  223. tft.drawRect(cx-i2, cy-i2, i, i, color);
  224. }
  225.  
  226. return micros() - start;
  227. }
  228.  
  229. unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  230. unsigned long start, t = 0;
  231. int n, i, i2,
  232. cx = tft.width() / 2 - 1,
  233. cy = tft.height() / 2 - 1;
  234.  
  235. tft.fillScreen(ILI9341_BLACK);
  236. n = min(tft.width(), tft.height()) - 1;
  237. for(i=n; i>0; i-=6) {
  238. i2 = i / 2;
  239. start = micros();
  240. tft.fillRect(cx-i2, cy-i2, i, i, color1);
  241. t += micros() - start;
  242. // Outlines are not included in timing results
  243. tft.drawRect(cx-i2, cy-i2, i, i, color2);
  244. }
  245.  
  246. return t;
  247. }
  248.  
  249. unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  250. unsigned long start;
  251. int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
  252.  
  253. tft.fillScreen(ILI9341_BLACK);
  254. start = micros();
  255. for(x=radius; x<w; x+=r2) {
  256. for(y=radius; y<h; y+=r2) {
  257. tft.fillCircle(x, y, radius, color);
  258. }
  259. }
  260.  
  261. return micros() - start;
  262. }
  263.  
  264. unsigned long testCircles(uint8_t radius, uint16_t color) {
  265. unsigned long start;
  266. int x, y, r2 = radius * 2,
  267. w = tft.width() + radius,
  268. h = tft.height() + radius;
  269.  
  270. // Screen is not cleared for this one -- this is
  271. // intentional and does not affect the reported time.
  272. start = micros();
  273. for(x=0; x<w; x+=r2) {
  274. for(y=0; y<h; y+=r2) {
  275. tft.drawCircle(x, y, radius, color);
  276. }
  277. }
  278.  
  279. return micros() - start;
  280. }
  281.  
  282. unsigned long testTriangles() {
  283. unsigned long start;
  284. int n, i, cx = tft.width() / 2 - 1,
  285. cy = tft.height() / 2 - 1;
  286.  
  287. tft.fillScreen(ILI9341_BLACK);
  288. n = min(cx, cy);
  289. start = micros();
  290. for(i=0; i<n; i+=5) {
  291. tft.drawTriangle(
  292. cx , cy - i, // peak
  293. cx - i, cy + i, // bottom left
  294. cx + i, cy + i, // bottom right
  295. tft.color565(0, 0, i));
  296. }
  297.  
  298. return micros() - start;
  299. }
  300.  
  301. unsigned long testFilledTriangles() {
  302. unsigned long start, t = 0;
  303. int i, cx = tft.width() / 2 - 1,
  304. cy = tft.height() / 2 - 1;
  305.  
  306. tft.fillScreen(ILI9341_BLACK);
  307. start = micros();
  308. for(i=min(cx,cy); i>10; i-=5) {
  309. start = micros();
  310. tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  311. tft.color565(0, i, i));
  312. t += micros() - start;
  313. tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  314. tft.color565(i, i, 0));
  315. }
  316.  
  317. return t;
  318. }
  319.  
  320. unsigned long testRoundRects() {
  321. unsigned long start;
  322. int w, i, i2,
  323. cx = tft.width() / 2 - 1,
  324. cy = tft.height() / 2 - 1;
  325.  
  326. tft.fillScreen(ILI9341_BLACK);
  327. w = min(tft.width(), tft.height()) - 1;
  328. start = micros();
  329. for(i=0; i<w; i+=6) {
  330. i2 = i / 2;
  331. tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  332. }
  333.  
  334. return micros() - start;
  335. }
  336.  
  337. unsigned long testFilledRoundRects() {
  338. unsigned long start;
  339. int i, i2,
  340. cx = tft.width() / 2 - 1,
  341. cy = tft.height() / 2 - 1;
  342.  
  343. tft.fillScreen(ILI9341_BLACK);
  344. start = micros();
  345. for(i=min(tft.width(), tft.height()) - 1; i>20; i-=6) {
  346. i2 = i / 2;
  347. tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  348. }
  349.  
  350. return micros() - start;
  351. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement