Advertisement
PrintService3D

Ladedruck Waveshare 1.28

Aug 13th, 2022 (edited)
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 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. void setup() {
  31.  
  32. //  Serial.begin(9600)
  33.   tft.begin();
  34.   tft.fillScreen(GC9A01A_BLACK);
  35.     startMillis = millis();
  36.        
  37.  
  38. }
  39.  
  40. void loop() {
  41.     currentMillis = millis();
  42.   if (currentMillis - startMillis >= period) {
  43.     readSensorData();
  44.  
  45.     startMillis = currentMillis;
  46.   }
  47.     tft.setTextColor(GC9A01A_MAGENTA,GC9A01A_BLACK );
  48.     tft.setCursor(240 - ypos, 140);
  49.     tft.setTextSize(3);
  50.        
  51.     char cstr[6];
  52.     dtostrf((float)boostPressure / 100  , 1, 2, cstr);
  53.    
  54.  
  55.     tft.print(cstr);
  56.     tft.setCursor(50, 140);
  57.     tft.print("NOW");
  58.     tft.setCursor(120,80);
  59.    
  60.     dtostrf((float)boostMax / 100  , 1, 2, cstr);
  61.    
  62.     tft.print(cstr);
  63.     tft.setCursor(50, 80);
  64.     tft.print("MAX");
  65.  
  66. }
  67.  
  68.  
  69. float normaliseSensorData(int m) {
  70.  
  71.   return (m - 104) / 0.1638;
  72. }
  73.  
  74.  
  75. void readSensorData(void) {
  76.   float absolutePressure = normaliseSensorData(analogRead(A7));
  77.  
  78.   boostPressure = (absolutePressure - 830) / 14.504 ;
  79.  
  80.  
  81.   if (boostPressure > boostMax) boostMax = boostPressure;
  82.   if (boostPressure < boostMin) boostMin = boostPressure;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement