PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

64 lines
2.2KB

  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_CS 10
  9. #define RA8875_RESET 9//any pin or nothing!
  10. RA8875 tft = RA8875(RA8875_CS, RA8875_RESET);
  11. //gauge position x,y,radius
  12. const int gaugePos1[3] = {64, 64, 63};
  13. const int gaugePos2[3] = {gaugePos1[0] * 3 + 4 + 1, gaugePos1[1], gaugePos1[2]};
  14. const int gaugePos3[3] = {gaugePos1[0] * 5 + 8 + 1, gaugePos1[1], gaugePos1[2]};
  15. //Radians limit anglemin anglemax
  16. const int gaugeLimits1[3] = {150, 390};
  17. const int gaugeLimits2[3] = {150, 390};
  18. const int gaugeLimits3[3] = {150, 390};
  19. //value containers
  20. volatile int16_t gaugeVal1[2] = {0, -1};
  21. volatile int16_t gaugeVal2[2] = {0, -1};
  22. volatile int16_t gaugeVal3[2] = {0, -1};
  23. void setup() {
  24. tft.begin(RA8875_800x480);
  25. tft.brightness(160);
  26. drawGauge(gaugePos1, gaugeLimits1);
  27. drawGauge(gaugePos2, gaugeLimits2);
  28. drawGauge(gaugePos3, gaugeLimits3);
  29. }
  30. void loop(void) {
  31. gaugeVal1[0] = random(1023);
  32. gaugeVal2[0] = random(1023);
  33. gaugeVal3[0] = random(1023);
  34. gaugeVal1[1] = drawNeedle_(gaugeVal1, gaugePos1, gaugeLimits1, RA8875_RED);
  35. gaugeVal2[1] = drawNeedle_(gaugeVal2, gaugePos2, gaugeLimits2, RA8875_GREEN);
  36. gaugeVal3[1] = drawNeedle_(gaugeVal3, gaugePos3, gaugeLimits3, RA8875_BLUE);
  37. delay(150);
  38. }
  39. int16_t drawNeedle_(volatile int16_t val[], const int pos[], const int limits[], uint16_t color) {
  40. if (val[0] != val[1]) {
  41. uint16_t len = pos[2] / 1.35;
  42. int angleMax = limits[1] - limits[0];
  43. tft.drawLineAngle(pos[0], pos[1], map(val[1], 0, 1023, 0, angleMax), len, RA8875_BLACK, limits[0]);
  44. tft.drawLineAngle(pos[0], pos[1], map(val[0], 0, 1023, 0, angleMax), len, color, limits[0]);
  45. val[1] = val[0];
  46. }
  47. return val[1];
  48. }
  49. void drawGauge(const int pos[], const int limits[]) {
  50. tft.drawCircle(pos[0], pos[1], pos[2], RA8875_WHITE); //draw instrument container
  51. tft.drawCircle(pos[0], pos[1], pos[2] + 1, RA8875_WHITE); //draw instrument container
  52. tft.roundGaugeTicker(pos[0], pos[1], pos[2], limits[0], limits[1], 1.3, RA8875_WHITE);
  53. 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
  54. }