Advertisement
PrintService3D

Displayproblem

Aug 14th, 2022
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.18 KB | None | 0 0
  1. #include "SPI.h"
  2. #include "Adafruit_GFX.h"
  3. #include "Adafruit_GC9A01A.h"
  4. #define TFT_DC 7
  5. #define TFT_CS 10
  6.  
  7. // Hardware SPI on Feather or other boards
  8. Adafruit_GC9A01A tft(TFT_CS, TFT_DC);
  9.  
  10. int boostPressure;
  11. int boostMax = 0;
  12. int boostMax1 = 2500;
  13. int boostMin = 0;
  14. int boostMin1 = 0;
  15. int ypos = 128;
  16.  
  17.  
  18. unsigned long startMillis;
  19. unsigned long currentMillis;
  20. const unsigned long period = 50;
  21.  
  22. const int sensorHistoryLength = 128;
  23. int sensorHistory[sensorHistoryLength];
  24. int sensorHistoryPos = sensorHistoryLength - 1;
  25.  
  26. #define DISPLAY_BACKLIGHT  A9 // Pin for backlight control (-1 for none)
  27. #define BACKLIGHT    1
  28.  
  29.  
  30.  
  31. void display_meter(float scale) {
  32.  
  33.   float angle  = (PI / 1023) * analogRead(A7);   // map analog in 0,1023, to 0.00,3.14
  34.   int length = 60; // line height Ratio of Screen 0-64
  35.  
  36.  
  37.   const byte x0 = 120;                                    // x0 Line Start 0-128
  38.   const byte y0 = 120;                                    // y0 Line Start 0-64
  39.  
  40.   byte x1 = x0 - length * cos (angle);
  41.   byte y1 = y0 - length * sin (angle);
  42.  
  43. tft.drawLine(  x0,   y0,   x1,   y1,   GC9A01A_GREEN); // write to screen
  44. //tft.drawLine(  x0+1,   y0+1,   x1+1,   y1+1,   GC9A01A_BLACK); // write to screen
  45. //tft.drawLine(  x0+2,   y0+2,   x1+2,   y1+2,   GC9A01A_BLACK); // write to screen
  46. //tft.drawLine(  x0+3,   y0+3,   x1+3,   y1+3,   GC9A01A_BLACK); // write to screen
  47.  
  48. //tft.drawLine(  x0-1,   y0-1,   x1-1,   y1-1,   GC9A01A_BLACK); // write to screen
  49. //tft.drawLine(  x0-2,   y0-2,   x1-2,   y1-2,   GC9A01A_BLACK); // write to screen
  50. //tft.drawLine(  x0-3,   y0-3,   x1-3,   y1-3,   GC9A01A_BLACK); // write to screen
  51.  
  52.  
  53.  
  54. }
  55. void Text(float scale) {
  56.  
  57.   tft.setTextColor(GC9A01A_MAGENTA, GC9A01A_BLACK );
  58.   tft.setCursor(180, 140);
  59.   tft.setTextSize(2);
  60.  
  61.   char cstr[6];
  62.   dtostrf((float)boostPressure / 100  , 1, 2, cstr);
  63.  
  64.  
  65.   tft.print(analogRead(A7));
  66.   tft.setCursor(50, 140);
  67.   //tft.print("NOW");
  68.  
  69.   tft.setCursor(180, 160);
  70.  
  71.   dtostrf((float)boostMax / 100  , 1, 2, cstr);
  72.  
  73.  
  74.   tft.print(cstr);
  75.   //tft.setCursor(50, 80);
  76.   //tft.print("MAX");
  77.  
  78. }
  79.  
  80.  
  81.  
  82. void setup() {
  83.  
  84.   //  Serial.begin(9600)
  85.   tft.begin();
  86.   tft.fillScreen(GC9A01A_BLACK);
  87.   startMillis = millis();
  88.  
  89.   tft.drawLine(119, 20, 119, 40, GC9A01A_GREEN);
  90.   tft.drawLine(120, 20, 120, 40, GC9A01A_GREEN);
  91.   tft.drawLine(121, 20, 121, 40, GC9A01A_GREEN);
  92.  
  93.   tft.drawLine(20, 119, 40, 119, GC9A01A_GREEN);
  94.   tft.drawLine(20, 120, 40, 120, GC9A01A_GREEN);
  95.   tft.drawLine(20, 121, 40, 121, GC9A01A_GREEN);
  96.  
  97.   tft.drawLine(119, 220, 119, 200, GC9A01A_GREEN);
  98.   tft.drawLine(120, 220, 120, 200, GC9A01A_GREEN);
  99.   tft.drawLine(121, 220, 121, 200, GC9A01A_GREEN);
  100.  
  101.   tft.drawLine(200, 119, 220, 119, GC9A01A_GREEN);
  102.   tft.drawLine(200, 120, 220, 120, GC9A01A_GREEN);
  103.   tft.drawLine(200, 121, 220, 121, GC9A01A_GREEN);
  104.  
  105.   tft.drawLine(80, 189, 70, 206, GC9A01A_GREEN);
  106.   tft.drawLine(80, 190, 70, 207, GC9A01A_GREEN);
  107.   tft.drawLine(80, 191, 70, 208, GC9A01A_GREEN);
  108.  
  109.   tft.drawLine(34, 169, 51, 159, GC9A01A_GREEN);
  110.   tft.drawLine(34, 170, 51, 160, GC9A01A_GREEN);
  111.   tft.drawLine(34, 171, 51, 161, GC9A01A_GREEN);
  112.  
  113.   tft.drawLine(34, 69, 51, 79, GC9A01A_GREEN);
  114.   tft.drawLine(34, 70, 51, 80, GC9A01A_GREEN);
  115.   tft.drawLine(34, 71, 51, 81, GC9A01A_GREEN);
  116.  
  117.   tft.drawLine(70, 33, 80, 50, GC9A01A_GREEN);
  118.   tft.drawLine(70, 34, 80, 51, GC9A01A_GREEN);
  119.   tft.drawLine(70, 35, 80, 52, GC9A01A_GREEN);
  120.  
  121.   tft.drawLine(160, 50, 170, 33, GC9A01A_GREEN);
  122.   tft.drawLine(160, 51, 170, 34, GC9A01A_GREEN);
  123.   tft.drawLine(160, 52, 170, 35, GC9A01A_GREEN);
  124.  
  125.   tft.drawLine(189, 79, 207, 69, GC9A01A_GREEN);
  126.   tft.drawLine(189, 80, 207, 70, GC9A01A_GREEN);
  127.   tft.drawLine(189, 81, 207, 71, GC9A01A_GREEN);
  128.  
  129.  
  130.  
  131.  
  132.  
  133.   tft.drawLine(94, 216, 97, 207, GC9A01A_YELLOW);
  134.   tft.drawLine(95, 216, 98, 207, GC9A01A_YELLOW);
  135.  
  136.   tft.drawLine(49, 191, 56, 183, GC9A01A_YELLOW);
  137.   tft.drawLine(50, 191, 57, 184, GC9A01A_YELLOW);
  138.  
  139.   tft.drawLine(23, 146, 33, 143, GC9A01A_YELLOW);
  140.   tft.drawLine(24, 146, 34, 143, GC9A01A_YELLOW);
  141.  
  142.   tft.drawLine(23, 94, 33, 96, GC9A01A_YELLOW);
  143.   tft.drawLine(24, 94, 34, 96, GC9A01A_YELLOW);
  144.  
  145.   tft.drawLine(49, 49, 56, 56, GC9A01A_YELLOW);
  146.   tft.drawLine(50, 49, 57, 56, GC9A01A_YELLOW);
  147.  
  148.   tft.drawLine(94, 23, 96, 33, GC9A01A_YELLOW);
  149.   tft.drawLine(95, 23, 97, 34, GC9A01A_YELLOW);
  150.  
  151.   tft.drawLine(145, 23, 143, 33, GC9A01A_YELLOW);
  152.   tft.drawLine(146, 23, 144, 34, GC9A01A_YELLOW);
  153.  
  154.   tft.drawLine(190, 49, 183, 56, GC9A01A_YELLOW);
  155.   tft.drawLine(191, 50, 184, 57, GC9A01A_YELLOW);
  156.  
  157.   tft.drawLine(206, 96, 216, 94, GC9A01A_YELLOW);
  158.   tft.drawLine(206, 97, 216, 95, GC9A01A_YELLOW);
  159.  
  160.  
  161. }
  162.  
  163. void loop() {
  164.  
  165.  
  166.   currentMillis = millis();
  167.   if (currentMillis - startMillis >= period) {
  168.     readSensorData();
  169.    
  170.   display_meter(0);
  171.   Text(0);
  172.  
  173.     startMillis = currentMillis;
  174.   }
  175. }
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.   float normaliseSensorData(int m) {
  185.  
  186.     return (m - 104) / 0.1638;
  187.   }
  188.  
  189.  
  190.   void readSensorData(void) {
  191.     float absolutePressure = normaliseSensorData(analogRead(A7));
  192.  
  193.     boostPressure = (absolutePressure - 830) / 14.504 ;
  194.  
  195.  
  196.     if (boostPressure > boostMax) boostMax = boostPressure;
  197.     if (boostPressure < boostMin) boostMin = boostPressure;
  198.   }
  199.  
  200.  
  201.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement