Advertisement
PrintService3D

Ladedruck V3

Aug 14th, 2022
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.66 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 = 100;
  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 = 50; // 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.  
  45. }
  46. void Text(float scale) {
  47.  
  48.   tft.setTextColor(GC9A01A_MAGENTA, GC9A01A_BLACK );
  49.   tft.setCursor(180, 140);
  50.   tft.setTextSize(2);
  51.  
  52.   char cstr[6];
  53.   dtostrf((float)boostPressure / 100  , 1, 2, cstr);
  54.  
  55.  
  56.   tft.print(cstr);
  57.   tft.setCursor(50, 140);
  58.   //tft.print("NOW");
  59.  
  60.   tft.setCursor(180, 160);
  61.  
  62.   dtostrf((float)boostMax / 100  , 1, 2, cstr);
  63.  
  64.  
  65.   tft.print(cstr);
  66.   //tft.setCursor(50, 80);
  67.   //tft.print("MAX");
  68.  
  69. }
  70.  
  71.  
  72.  
  73. void setup() {
  74.  
  75.   //  Serial.begin(9600)
  76.   tft.begin();
  77.   tft.fillScreen(GC9A01A_BLACK);
  78.   startMillis = millis();
  79.  
  80.   tft.drawLine(119, 20, 119, 40, GC9A01A_GREEN);
  81.   tft.drawLine(120, 20, 120, 40, GC9A01A_GREEN);
  82.   tft.drawLine(121, 20, 121, 40, GC9A01A_GREEN);
  83.  
  84.   tft.drawLine(20, 119, 40, 119, GC9A01A_GREEN);
  85.   tft.drawLine(20, 120, 40, 120, GC9A01A_GREEN);
  86.   tft.drawLine(20, 121, 40, 121, GC9A01A_GREEN);
  87.  
  88.   tft.drawLine(119, 220, 119, 200, GC9A01A_GREEN);
  89.   tft.drawLine(120, 220, 120, 200, GC9A01A_GREEN);
  90.   tft.drawLine(121, 220, 121, 200, GC9A01A_GREEN);
  91.  
  92.   tft.drawLine(200, 119, 220, 119, GC9A01A_GREEN);
  93.   tft.drawLine(200, 120, 220, 120, GC9A01A_GREEN);
  94.   tft.drawLine(200, 121, 220, 121, GC9A01A_GREEN);
  95.  
  96.   tft.drawLine(80, 189, 70, 206, GC9A01A_GREEN);
  97.   tft.drawLine(80, 190, 70, 207, GC9A01A_GREEN);
  98.   tft.drawLine(80, 191, 70, 208, GC9A01A_GREEN);
  99.  
  100.   tft.drawLine(34, 169, 51, 159, GC9A01A_GREEN);
  101.   tft.drawLine(34, 170, 51, 160, GC9A01A_GREEN);
  102.   tft.drawLine(34, 171, 51, 161, GC9A01A_GREEN);
  103.  
  104.   tft.drawLine(34, 69, 51, 79, GC9A01A_GREEN);
  105.   tft.drawLine(34, 70, 51, 80, GC9A01A_GREEN);
  106.   tft.drawLine(34, 71, 51, 81, GC9A01A_GREEN);
  107.  
  108.   tft.drawLine(70, 33, 80, 50, GC9A01A_GREEN);
  109.   tft.drawLine(70, 34, 80, 51, GC9A01A_GREEN);
  110.   tft.drawLine(70, 35, 80, 52, GC9A01A_GREEN);
  111.  
  112.   tft.drawLine(160, 50, 170, 33, GC9A01A_GREEN);
  113.   tft.drawLine(160, 51, 170, 34, GC9A01A_GREEN);
  114.   tft.drawLine(160, 52, 170, 35, GC9A01A_GREEN);
  115.  
  116.   tft.drawLine(189, 79, 207, 69, GC9A01A_GREEN);
  117.   tft.drawLine(189, 80, 207, 70, GC9A01A_GREEN);
  118.   tft.drawLine(189, 81, 207, 71, GC9A01A_GREEN);
  119.  
  120.  
  121.  
  122.  
  123.  
  124.   tft.drawLine(94, 216, 97, 207, GC9A01A_YELLOW);
  125.   tft.drawLine(95, 216, 98, 207, GC9A01A_YELLOW);
  126.  
  127.   tft.drawLine(49, 191, 56, 183, GC9A01A_YELLOW);
  128.   tft.drawLine(50, 191, 57, 184, GC9A01A_YELLOW);
  129.  
  130.   tft.drawLine(23, 146, 33, 143, GC9A01A_YELLOW);
  131.   tft.drawLine(24, 146, 34, 143, GC9A01A_YELLOW);
  132.  
  133.   tft.drawLine(23, 94, 33, 96, GC9A01A_YELLOW);
  134.   tft.drawLine(24, 94, 34, 96, GC9A01A_YELLOW);
  135.  
  136.   tft.drawLine(49, 49, 56, 56, GC9A01A_YELLOW);
  137.   tft.drawLine(50, 49, 57, 56, GC9A01A_YELLOW);
  138.  
  139.   tft.drawLine(94, 23, 96, 33, GC9A01A_YELLOW);
  140.   tft.drawLine(95, 23, 97, 34, GC9A01A_YELLOW);
  141.  
  142.   tft.drawLine(145, 23, 143, 33, GC9A01A_YELLOW);
  143.   tft.drawLine(146, 23, 144, 34, GC9A01A_YELLOW);
  144.  
  145.   tft.drawLine(190, 49, 183, 56, GC9A01A_YELLOW);
  146.   tft.drawLine(191, 50, 184, 57, GC9A01A_YELLOW);
  147.  
  148.   tft.drawLine(206, 96, 216, 94, GC9A01A_YELLOW);
  149.   tft.drawLine(206, 97, 216, 95, GC9A01A_YELLOW);
  150.  
  151.  
  152. }
  153.  
  154. void loop() {
  155.  
  156.  
  157.   currentMillis = millis();
  158.   if (currentMillis - startMillis >= period) {
  159.     readSensorData();
  160.    
  161.   display_meter(0);
  162.   Text(0);
  163.  
  164.     startMillis = currentMillis;
  165.   }
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.   float normaliseSensorData(int m) {
  176.  
  177.     return (m - 104) / 0.1638;
  178.   }
  179.  
  180.  
  181.   void readSensorData(void) {
  182.     float absolutePressure = normaliseSensorData(analogRead(A7));
  183.  
  184.     boostPressure = (absolutePressure - 830) / 14.504 ;
  185.  
  186.  
  187.     if (boostPressure > boostMax) boostMax = boostPressure;
  188.     if (boostPressure < boostMin) boostMin = boostPressure;
  189.   }
  190.  
  191.  
  192.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement