1. 在这个模板中,我们添加了将转换后的图像转换为代码,然后使用两个黑色和白色弧来创建卷的指针。下载. h 文件并将其添加到 Arduino 草图的文件夹中。
    2. #include “Adafruit_GFX.h”
    3. #include “MCUFRIEND_kbv.h”
    4. MCUFRIEND_kbv tft;
    5. #include “Volume.h”
    6. #define BLACK 0x0000
    7. int a = 0,b = 4000,c = 1000,d = 3000;
    8. int s=2000;
    9. int j, j2;
    10. int i, i2;
    11. int White;
    12. void setup()
    13. {
    14. Serial.begin(9600);
    15. uint16_t ID = tft.readID();
    16. tft.begin(ID);
    17. tft.invertDisplay(true);
    18. tft.setRotation(1);
    19. }
    20. void loop(void)
    21. {
    22. tft.invertDisplay(true);
    23. tft.fillScreen(BLACK);
    24. tft.drawRGBBitmap(0, 0, test, 480, 320);
    25. White = tft.color565(255, 255, 255);
    26. while(1){
    27. if (a 《 s) {
    28. j = 14 (sin(PI a / 2000));
    29. i = 14 (cos(PI a / 2000));
    30. j2 = 1 (sin(PI a / 2000));
    31. i2 = 1 (cos(PI a / 2000));
    32. tft.drawLine(i2 + 62, j2 + 240, i + 62, j + 240, White);
    33. j = 14 (sin(PI (a-300) / 2000));
    34. i = 14 (cos(PI (a-300) / 2000));
    35. j2 = 1 (sin(PI (a-300) / 2000));
    36. i2 = 1 (cos(PI (a-300) / 2000));
    37. tft.drawLine(i2 + 62, j2 + 240, i + 62, j + 240, 0x0000);
    38. tft.fillRect(50, 285, 30, 30, 0x0000);
    39. tft.setTextSize(2);
    40. tft.setTextColor(0xffff);
    41. tft.setCursor(50, 285);
    42. tft.print(a / 40); tft.print(“%”);
    43. a++;
    44. }
    45. if (b 《 s) {
    46. j = 14 (sin(PI b / 2000));
    47. i = 14 (cos(PI b / 2000));
    48. j2 = 1 (sin(PI b / 2000));
    49. i2 = 1 (cos(PI b / 2000));
    50. tft.drawLine(i2 + 180, j2 + 240, i + 180, j + 240, White);
    51. j = 14 (sin(PI (b-300) / 2000));
    52. i = 14 (cos(PI (b-300) / 2000));
    53. j2 = 1 (sin(PI (b-300) / 2000));
    54. i2 = 1 (cos(PI (b-300) / 2000));
    55. tft.drawLine(i2 + 180, j2 + 240, i + 180, j + 240, 0x0000);
    56. tft.fillRect(168, 285, 30, 30, 0x0000);
    57. tft.setTextSize(2);
    58. tft.setTextColor(0xffff);
    59. tft.setCursor(168, 285);
    60. tft.print(b / 40); tft.print(“%”);
    61. b++;}
    62. if (c 《 s) {
    63. j = 14 (sin(PI c / 2000));
    64. i = 14 (cos(PI c / 2000));
    65. j2 = 1 (sin(PI c / 2000));
    66. i2 = 1 (cos(PI c / 2000));
    67. tft.drawLine(i2 + 297, j2 + 240, i + 297, j + 240, White);
    68. j = 14 (sin(PI (c-300) / 2000));
    69. i = 14 (cos(PI (c-300) / 2000));
    70. j2 = 1 (sin(PI (c-300) / 2000));
    71. i2 = 1 (cos(PI (c-300) / 2000));
    72. tft.drawLine(i2 + 297, j2 + 240, i + 297, j + 240, 0x0000);
    73. tft.fillRect(286, 285, 30, 30, 0x0000);
    74. tft.setTextSize(2);
    75. tft.setTextColor(0xffff);
    76. tft.setCursor(286, 285);
    77. tft.print(c / 40); tft.print(“%”);
    78. c++;}
    79. if (d 《 s) {j = 14 (sin(PI d / 2000)); i = 14 (cos(PI d / 2000)); j2 = 1 (sin(PI d / 2000)); i2 = 1 (cos(PI d / 2000)); tft.drawLine(i2 + 414, j2 + 240, i + 414, j + 240, White); j = 14 (sin(PI (d-300) / 2000)); i = 14 (cos(PI (d-300) / 2000)); j2 = 1 (sin(PI (d-300) / 2000)); i2 = 1 (cos(PI (d-300) / 2000)); tft.drawLine(i2 + 414, j2 + 240, i + 414, j + 240, 0x0000); tft.fillRect(402, 285, 30, 30, 0x0000); tft.setTextSize(2); tft.setTextColor(0xffff); tft.setCursor(402, 285); tft.print(d / 40); tft.print(“%”); d++;} if (a 》 s) {
    80. j = 14 (sin(PI a / 2000));
    81. i = 14 (cos(PI a / 2000));
    82. j2 = 1 (sin(PI a / 2000));
    83. i2 = 1 (cos(PI a / 2000));
    84. tft.drawLine(i2 + 62, j2 + 240, i + 62, j + 240, White);
    85. j = 14 (sin(PI (a+300) / 2000));
    86. i = 14 (cos(PI (a+300) / 2000));
    87. j2 = 1 (sin(PI (a+300) / 2000));
    88. i2 = 1 (cos(PI (a+300) / 2000));
    89. tft.drawLine(i2 + 62, j2 + 240, i + 62, j + 240, 0x0000);
    90. tft.fillRect(50, 285, 30, 30, 0x0000);
    91. tft.setTextSize(2);
    92. tft.setTextColor(0xffff);
    93. tft.setCursor(50, 285);
    94. tft.print(a / 40); tft.print(“%”);
    95. a--;}
    96. if (b 》 s) {
    97. j = 14 (sin(PI b / 2000));
    98. i = 14 (cos(PI b / 2000));
    99. j2 = 1 (sin(PI b / 2000));
    100. i2 = 1 (cos(PI b / 2000));
    101. tft.drawLine(i2 + 180, j2 + 240, i + 180, j + 240, White);
    102. j = 14 (sin(PI (b+300) / 2000));
    103. i = 14 (cos(PI (b+300) / 2000));
    104. j2 = 1 (sin(PI (b+300) / 2000));
    105. i2 = 1 (cos(PI (b+300) / 2000));
    106. tft.drawLine(i2 + 180, j2 + 240, i + 180, j + 240, 0x0000);
    107. tft.fillRect(168, 285, 30, 30, 0x0000);
    108. tft.setTextSize(2);
    109. tft.setTextColor(0xffff);
    110. tft.setCursor(168, 285);
    111. tft.print(b / 40); tft.print(“%”);
    112. b--;}
    113. if (c 》 s) {
    114. j = 14 (sin(PI c / 2000));
    115. i = 14 (cos(PI c / 2000));
    116. j2 = 1 (sin(PI c / 2000));
    117. i2 = 1 (cos(PI c / 2000));
    118. tft.drawLine(i2 + 297, j2 + 240, i + 297, j + 240, White);
    119. j = 14 (sin(PI (c+300) / 2000));
    120. i = 14 (cos(PI (c+300) / 2000));
    121. j2 = 1 (sin(PI (c+300) / 2000));
    122. i2 = 1 (cos(PI (c+300) / 2000));
    123. tft.drawLine(i2 + 297, j2 + 240, i + 297, j + 240, 0x0000);
    124. tft.fillRect(286, 285, 30, 30, 0x0000);
    125. tft.setTextSize(2);
    126. tft.setTextColor(0xffff);
    127. tft.setCursor(286, 285);
    128. tft.print(c / 40); tft.print(“%”);
    129. c--;}
    130. if (d 》 s) {
    131. j = 14 (sin(PI d / 2000));
    132. i = 14 (cos(PI d / 2000));
    133. j2 = 1 (sin(PI d / 2000));
    134. i2 = 1 (cos(PI d / 2000));
    135. tft.drawLine(i2 + 414, j2 + 240, i + 414, j + 240, White);
    136. j = 14 (sin(PI (d+300) / 2000));
    137. i = 14 (cos(PI (d+300) / 2000));
    138. j2 = 1 (sin(PI (d+300) / 2000));
    139. i2 = 1 (cos(PI (d+300) / 2000));
    140. tft.drawLine(i2 + 414, j2 + 240, i + 414, j + 240, 0x0000);
    141. tft.fillRect(402, 285, 30, 30, 0x0000);
    142. tft.setTextSize(2);
    143. tft.setTextColor(0xffff);
    144. tft.setCursor(402, 285);
    145. tft.print(d / 40); tft.print(“%”);
    146. d--;}
    147. }
    148. }