PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 3 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. The simpliest way to draw a Round Gauge by using the RA8875 library
  3. functions.
  4. This will draw 3 round gauges
  5. */
  6. #include <SPI.h>
  7. #include <RA8875.h>
  8. #define RA8875_RESET 9//any pin or nothing!
  9. #if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva
  10. RA8875 tft = RA8875(3);//select SPI module 3
  11. /*
  12. for module 3 (stellaris)
  13. SCLK: PD_0
  14. MOSI: PD_3
  15. MISO: PD_2
  16. SS: PD_1
  17. */
  18. #endif
  19. //gauge position x,y,radius
  20. const int gaugePos1[3] = {64, 64, 63};
  21. const int gaugePos2[3] = {gaugePos1[0] * 3 + 4 + 1, gaugePos1[1], gaugePos1[2]};
  22. const int gaugePos3[3] = {gaugePos1[0] * 5 + 8 + 1, gaugePos1[1], gaugePos1[2]};
  23. //Radians limit anglemin anglemax
  24. const int gaugeLimits1[3] = {150, 390};
  25. const int gaugeLimits2[3] = {150, 390};
  26. const int gaugeLimits3[3] = {150, 390};
  27. //value containers
  28. volatile int16_t gaugeVal1[2] = {0, -1};
  29. volatile int16_t gaugeVal2[2] = {0, -1};
  30. volatile int16_t gaugeVal3[2] = {0, -1};
  31. void setup() {
  32. tft.begin(RA8875_800x480);
  33. tft.brightness(160);
  34. drawGauge(gaugePos1, gaugeLimits1);
  35. drawGauge(gaugePos2, gaugeLimits2);
  36. drawGauge(gaugePos3, gaugeLimits3);
  37. }
  38. void loop(void) {
  39. gaugeVal1[0] = random(1023);
  40. gaugeVal2[0] = random(1023);
  41. gaugeVal3[0] = random(1023);
  42. gaugeVal1[1] = drawNeedle_(gaugeVal1, gaugePos1, gaugeLimits1, RA8875_RED);
  43. gaugeVal2[1] = drawNeedle_(gaugeVal2, gaugePos2, gaugeLimits2, RA8875_GREEN);
  44. gaugeVal3[1] = drawNeedle_(gaugeVal3, gaugePos3, gaugeLimits3, RA8875_BLUE);
  45. delay(150);
  46. }
  47. int16_t drawNeedle_(volatile int16_t val[], const int pos[], const int limits[], uint16_t color) {
  48. if (val[0] != val[1]) {
  49. uint16_t len = pos[2] / 1.35;
  50. int angleMax = limits[1] - limits[0];
  51. tft.drawLineAngle(pos[0], pos[1], map(val[1], 0, 1023, 0, angleMax), len, RA8875_BLACK, limits[0]);
  52. tft.drawLineAngle(pos[0], pos[1], map(val[0], 0, 1023, 0, angleMax), len, color, limits[0]);
  53. val[1] = val[0];
  54. }
  55. return val[1];
  56. }
  57. void drawGauge(const int pos[], const int limits[]) {
  58. tft.drawCircle(pos[0], pos[1], pos[2], RA8875_WHITE); //draw instrument container
  59. tft.drawCircle(pos[0], pos[1], pos[2] + 1, RA8875_WHITE); //draw instrument container
  60. tft.roundGaugeTicker(pos[0], pos[1], pos[2], limits[0], limits[1], 1.3, RA8875_WHITE);
  61. if (pos[2] > 15) tft.roundGaugeTicker(pos[0], pos[1], pos[2], limits[0] + 15, limits[1] - 15, 1.1, RA8875_WHITE); //draw minor ticks
  62. }