1. #include <Arduino.h>
    2. #include <SPI.h>
    3. #include <MCUFRIEND_kbv.h>
    4. #include <Adafruit_GFX.h> // Core graphics library
    5. #include <Adafruit_I2CDevice.h>
    6. #include <FS.h>
    7. #include <SPIFFS.h>
    8. // Assign human-readable names to some common 16-bit color values:
    9. #define BLACK 0x0000
    10. #define BLUE 0x001F
    11. #define RED 0xF800
    12. #define GREEN 0x07E0
    13. #define CYAN 0x07FF
    14. #define MAGENTA 0xF81F
    15. #define YELLOW 0xFFE0
    16. #define WHITE 0xFFFF
    17. MCUFRIEND_kbv tft;
    18. uint16_t ox=0, oy=0;
    19. int ave=0, avec=0, avet=0;
    20. ////////////////////////////////////////////////////////////////
    21. void aveg(void)
    22. {
    23. int z=0;
    24. Serial.println(ave);
    25. Serial.println(avec);
    26. avet=ave/avec;
    27. Serial.println(avet);
    28. avet=avet*32;
    29. for (int i=0; i<24; i++){
    30. for (uint16_t a=0; a<3; a++)
    31. {
    32. tft.drawLine(avet+a, z, avet+a, z+10, 0xFB21);
    33. } // thick
    34. for (uint16_t a=0; a<2; a++)
    35. {
    36. tft.drawLine(avet-a, z, avet-a, z+10, 0xFB21);} delay(100); z=z+20;
    37. }
    38. }
    39. void dchart_10x10(uint16_t nx,uint16_t ny)
    40. {
    41. ave+=nx;
    42. avec++;
    43. nx=nx*32;
    44. ny=ny*48;
    45. tft.drawCircle(nx, ny, 10, 0x0517);
    46. tft.drawCircle(nx, ny, 9, 0x0517);
    47. tft.fillCircle(nx, ny, 7, 0x0517);
    48. delay (100);
    49. ox=nx;
    50. oy=ny;
    51. }
    52. void dotchart_10x10(uint16_t nx,uint16_t ny)
    53. {
    54. ave+=nx;
    55. avec++;
    56. nx=nx*32;
    57. ny=ny*48;
    58. int plus=0;
    59. float fplus=0;
    60. int sign=0;
    61. int y=0,x=0;
    62. y=oy;
    63. x=ox;
    64. float xmines, ymines; xmines=nx-ox;
    65. ymines=ny-oy;
    66. if (ox > nx)
    67. {
    68. xmines=ox-nx;
    69. sign=1;
    70. }
    71. else
    72. sign=0;
    73. for (int a=0; a<(ny-oy); a++)
    74. {
    75. fplus+=xmines/ymines;
    76. plus=fplus;
    77. if (sign==1)
    78. tft.drawFastHLine(0, y, x-plus, 0xBFDF);
    79. else
    80. tft.drawFastHLine(0, y, x+plus, 0xBFDF);
    81. y++;
    82. delay(5);
    83. }
    84. for (uint16_t a=0; a<2; a++){
    85. tft.drawLine(ox+a, oy, nx+a, ny, 0x01E8);} // thick
    86. for (uint16_t a=0; a<2; a++){
    87. tft.drawLine(ox, oy+a, nx, ny+a, 0x01E8);}
    88. ox=nx;
    89. oy=ny;
    90. }
    91. ////////////////////////////////////////////////////////////////////
    92. void setup(void) {
    93. Serial.begin(115200);
    94. Serial.println(F("TFT LCD test"));
    95. tft.reset();
    96. uint16_t identifier = tft.readID();
    97. if(identifier == 0x9325) {
    98. Serial.println(F("Found ILI9325 LCD driver"));
    99. } else if(identifier == 0x9328) {
    100. Serial.println(F("Found ILI9328 LCD driver"));
    101. } else if(identifier == 0x4535) {
    102. Serial.println(F("Found LGDP4535 LCD driver"));
    103. }else if(identifier == 0x7575) {
    104. Serial.println(F("Found HX8347G LCD driver"));
    105. } else if(identifier == 0x9595) {
    106. Serial.println(F("Found HX8347-I LCD driver"));
    107. } else if(identifier == 0x4747) {
    108. Serial.println(F("Found HX8347-D LCD driver"));
    109. } else if(identifier == 0x8347) {
    110. Serial.println(F("Found HX8347-A LCD driver"));
    111. }else if(identifier == 0x9341) {
    112. Serial.println(F("Found ILI9341 LCD driver"));
    113. }else if(identifier == 0x7783) {
    114. Serial.println(F("Found ST7781 LCD driver"));
    115. }else if(identifier == 0x8230) {
    116. Serial.println(F("Found UC8230 LCD driver"));
    117. }else if(identifier == 0x8357) {
    118. Serial.println(F("Found HX8357D LCD driver"));
    119. } else if(identifier==0x0101){
    120. identifier=0x9341;
    121. Serial.println(F("Found 0x9341 LCD driver"));
    122. }else if(identifier==0x7793){
    123. Serial.println(F("Found ST7793 LCD driver"));
    124. }else if(identifier==0xB509){
    125. Serial.println(F("Found R61509 LCD driver"));
    126. }else if(identifier==0x9486){
    127. Serial.println(F("Found ILI9486 LCD driver"));
    128. }else if(identifier==0x9488){
    129. Serial.println(F("Found ILI9488 LCD driver"));
    130. }else
    131. {
    132. Serial.print(F("Unknown LCD driver chip: "));
    133. Serial.println(identifier, HEX);
    134. Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    135. Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
    136. Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    137. Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    138. Serial.println(F("Also if using the breakout, double-check that all wiring"));
    139. Serial.println(F("matches the tutorial."));
    140. identifier=0x9486;
    141. }
    142. tft.begin(identifier);
    143. tft.fillScreen(BLACK);
    144. unsigned long start = micros();
    145. tft.setCursor(0, 0);
    146. tft.setTextColor(RED); tft.setTextSize(1);
    147. tft.println("Hello World!");
    148. tft.println(01234.56789);
    149. tft.println(0xDEADBEEF, HEX);
    150. tft.println();
    151. tft.println();
    152. tft.setTextColor(GREEN); tft.setTextSize(2);
    153. tft.println("Hello World!");
    154. tft.println(01234.56789);
    155. tft.println(0xDEADBEEF, HEX);
    156. tft.println();
    157. tft.println();
    158. tft.setTextColor(BLUE); tft.setTextSize(3);
    159. tft.println("Hello World!");
    160. tft.println(01234.56789);
    161. tft.println(0xDEADBEEF, HEX);
    162. tft.setTextColor(WHITE); tft.setTextSize(4);
    163. tft.println("Hello!");
    164. tft.setTextColor(YELLOW); tft.setTextSize(5);
    165. tft.println("Hello!");
    166. tft.setTextColor(RED); tft.setTextSize(6);
    167. tft.println("Hello!");
    168. tft.println();
    169. tft.println();
    170. delay(1000);
    171. }
    172. void loop(void) {
    173. tft.invertDisplay(true);
    174. tft.fillScreen(0xffff);
    175. dotchart_10x10(3, 0);
    176. dotchart_10x10(2, 1);
    177. dotchart_10x10(4, 2);
    178. dotchart_10x10(4, 3);
    179. dotchart_10x10(5, 4);
    180. dotchart_10x10(3, 5);
    181. dotchart_10x10(6, 6);
    182. dotchart_10x10(7, 7);
    183. dotchart_10x10(9, 8);
    184. dotchart_10x10(8, 9);
    185. dotchart_10x10(10, 10);
    186. dchart_10x10(3, 0);
    187. dchart_10x10(2, 1);
    188. dchart_10x10(4, 2);
    189. dchart_10x10(4, 3);
    190. dchart_10x10(5, 4);
    191. dchart_10x10(3, 5);
    192. dchart_10x10(6, 6);
    193. dchart_10x10(7, 7);
    194. dchart_10x10(9, 8);
    195. dchart_10x10(8, 9);
    196. dchart_10x10(10, 10);
    197. tft.setRotation(1);
    198. tft.setTextSize(2);
    199. tft.setTextColor(0x01E8);
    200. tft.setCursor(20, 20);
    201. tft.print("Average");
    202. int dl=20;
    203. for (int i=0;i < 6;i++)
    204. {
    205. for (uint16_t a=0; a < 3; a++){
    206. tft.drawLine(dl, 40+a, dl+10, 40+a, 0xFB21);}
    207. dl+=16;
    208. }
    209. tft.setRotation(0);
    210. aveg();
    211. while(1);
    212. }