Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SPI.h"
- #include "Adafruit_GFX.h"
- #include "Adafruit_GC9A01A.h"
- #define TFT_DC 7
- #define TFT_CS 10
- // Hardware SPI on Feather or other boards
- Adafruit_GC9A01A tft(TFT_CS, TFT_DC);
- int boostPressure;
- int boostMax = 0;
- int boostMax1 = 2500;
- int boostMin = 0;
- int boostMin1 = 0;
- int ypos = 128;
- unsigned long startMillis;
- unsigned long currentMillis;
- const unsigned long period = 100;
- const int sensorHistoryLength = 128;
- int sensorHistory[sensorHistoryLength];
- int sensorHistoryPos = sensorHistoryLength - 1;
- #define DISPLAY_BACKLIGHT A9 // Pin for backlight control (-1 for none)
- #define BACKLIGHT 1
- void setup() {
- // Serial.begin(9600)
- tft.begin();
- tft.fillScreen(GC9A01A_BLACK);
- startMillis = millis();
- }
- void loop() {
- currentMillis = millis();
- if (currentMillis - startMillis >= period) {
- readSensorData();
- startMillis = currentMillis;
- }
- tft.setTextColor(GC9A01A_MAGENTA,GC9A01A_BLACK );
- tft.setCursor(240 - ypos, 140);
- tft.setTextSize(3);
- char cstr[6];
- dtostrf((float)boostPressure / 100 , 1, 2, cstr);
- tft.print(cstr);
- tft.setCursor(50, 140);
- tft.print("NOW");
- tft.setCursor(120,80);
- dtostrf((float)boostMax / 100 , 1, 2, cstr);
- tft.print(cstr);
- tft.setCursor(50, 80);
- tft.print("MAX");
- }
- float normaliseSensorData(int m) {
- return (m - 104) / 0.1638;
- }
- void readSensorData(void) {
- float absolutePressure = normaliseSensorData(analogRead(A7));
- boostPressure = (absolutePressure - 830) / 14.504 ;
- if (boostPressure > boostMax) boostMax = boostPressure;
- if (boostPressure < boostMin) boostMin = boostPressure;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement