PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

83 lines
2.1KB

  1. #include <SPI.h>
  2. #include <Adafruit_GFX.h>
  3. #include <TFT_ILI9163C.h>
  4. // Color definitions
  5. #define BLACK 0x0000
  6. #define BLUE 0x001F
  7. #define RED 0xF800
  8. #define GREEN 0x07E0
  9. #define CYAN 0x07FF
  10. #define MAGENTA 0xF81F
  11. #define YELLOW 0xFFE0
  12. #define WHITE 0xFFFF
  13. #define NBINS 12
  14. const uint8_t bar_Width = 3;
  15. uint32_t avrg_TmrF = 0;
  16. uint16_t t_b[NBINS];
  17. uint16_t datax_[NBINS];
  18. /*
  19. Teensy3.x and Arduino's
  20. You are using 4 wire SPI here, so:
  21. MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  22. MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  23. SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  24. the rest of pin below:
  25. */
  26. #define __CS 10
  27. #define __DC 9
  28. /*
  29. Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
  30. Arduino's 8 bit: any
  31. DUE: check arduino site
  32. If you do not use reset, tie it to +3V3
  33. */
  34. TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
  35. void setup(void) {
  36. Serial.begin(38400);
  37. //while(!Serial);
  38. tft.begin();
  39. tft.setRotation(1);
  40. tft.fillScreen(BLACK);
  41. tft.setTextWrap(true);
  42. tft.setTextColor(WHITE, BLACK);
  43. tft.setCursor(0,0);
  44. }
  45. void loop(){
  46. for (int i=0;i<NBINS;i++){
  47. datax_[i] = random(0,1024);
  48. }
  49. //Print_Data();
  50. verticalBarGraphs(datax_,5,127,0);
  51. delay(50);
  52. }
  53. void verticalBarGraphs(uint16_t datax[],uint8_t barWidth,uint8_t barHeight,uint8_t vOrigin){//3,12,64,10
  54. uint8_t startX;
  55. uint16_t color;
  56. uint8_t dataToWidth;
  57. uint8_t div;
  58. for (uint8_t i = 1; i <= NBINS-1; i++) {
  59. startX = (i * 11);
  60. //tft.drawRect((startX-1),vOrigin,barWidth,barHeight,WHITE);//container
  61. dataToWidth = map(datax[i],0,1024,(barHeight-2),0);
  62. uint8_t b = map(datax[i],0,1024,255,0);
  63. uint8_t g = map(datax[i],0,1024,128,0);
  64. uint8_t r = map(datax[i],0,1024,0,255);
  65. div = (barHeight-2)/10;
  66. color = ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3);
  67. tft.fillRect(startX,(vOrigin+1),(bar_Width+3),dataToWidth,BLACK);//mask ok
  68. tft.fillRect(startX,(dataToWidth+vOrigin)+1,(bar_Width+3),((barHeight-2)-dataToWidth),color);//fillRect(X,Y,width,height,color)
  69. }
  70. }