Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BMP_FILENAME "/octocat2.bmp" // 456x240@16bit
- #define GIF_FILENAME "/joel2.gif"
- #include <HardwareSerial.h>
- #include <Arduino_GFX_Library.h>
- #define GFX_BL 5 // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
- #if defined(DISPLAY_DEV_KIT)
- Arduino_GFX *gfx = create_default_Arduino_GFX();
- #else /* !defined(DISPLAY_DEV_KIT) */
- Arduino_DataBus *bus = new Arduino_ESP32SPI(5 /* DC */, 22 /* CS */, 18 /* SCK */, 23 /* MOSI */, GFX_NOT_DEFINED /* MISO */, VSPI /* spi_num */);
- Arduino_GFX *gfx = new Arduino_GC9A01( bus, 4 /* RST */, 0 /* rotation */, true /* IPS */);
- #endif /* !defined(DISPLAY_DEV_KIT) */
- #if defined(ESP32)
- #include <FFat.h>
- #include <LittleFS.h>
- #include <SPIFFS.h>
- #include <SD.h>
- #endif
- float boostPressure;
- int boostMax = 0;
- int boostMax2 = boostMax;
- int boostMin = 0;
- //int boostMin1 = 0;
- int ypos = 128;
- int adcval = 0;
- int adcval2 = 0;
- int atmo = 0;
- // int offset = 1177; // low pressure calibration
- int offset = 1191; // low pressure calibration
- int span = 3685.5; // high pressure calibration
- unsigned long startMillis;
- unsigned long currentMillis;
- const unsigned long period = 100;
- unsigned long startMillis2;
- unsigned long currentMillis2;
- const unsigned long period2 = 1000;
- long myTimer = 0;
- long myTimeout = 15000;
- #define wert1 4095 //b
- #define wert2 0 //c
- #define temp1 -40 //Grad Celsius/10 //d
- #define temp2 130 //Grad Celsius/10 //e
- #define Black 0x0000 /* 0, 0, 0 */
- #define Navy 0x000F /* 0, 0, 128 */
- #define DarkGreen 0x03E0 /* 0, 128, 0 */
- #define DarkCyan 0x03EF /* 0, 128, 128 */
- #define Maroon 0x7800 /* 128, 0, 0 */
- #define Purple 0x780F /* 128, 0, 128 */
- #define Olive 0x7BE0 /* 128, 128, 0 */
- #define LightGrey 0xC618 /* 192, 192, 192 */
- #define DarkGrey 0x7BEF /* 128, 128, 128 */
- #define Red 0xF800 /* 0, 0, 255 */
- #define Green 0x07E0 /* 0, 255, 0 */
- #define Cyan 0x07FF /* 0, 255, 255 */
- #define Blue 0x001F /* 255, 0, 0 */
- #define Magenta 0xF81F /* 255, 0, 255 */
- #define Yellow 0xFFE0 /* 255, 255, 0 */
- #define White 0xFFFF /* 255, 255, 255 */
- #define Orange 0xFD20 /* 255, 165, 0 */
- #define GreenYellow 0xAFE5 /* 173, 255, 47 */
- #define Not 0xAC27 /* 4, 40, 71 */
- #define Pink 0xF81F
- #include "gif.h"
- #include "bmp.h"
- void display_meter(float scale, int analogval, uint16_t color )
- {
- const int outerpoint = 76; // outer triangle point, distance form center
- const int innerpoint = 58;// inner triangle point, distance form center
- const int trianglewidth = 3; // width of triangle in center, in degree
- const int centerx = 120;
- const int centery = 120;
- byte x0 = 120;
- byte y0 = 120;
- // float angle = (PI / 4095) * (analogval - 80); // map analog in 0,1023, to 0.00,3.14
- float angle = (PI / 257) * (analogval + 68); // map analog in 0,1023, to 0.00,3.14
- // outer triangle point
- int xout = centerx - outerpoint * cos (angle);
- int yout = centery - outerpoint * sin (angle);
- //inner triangle points
- int xinner1 = x0 + innerpoint * cos (angle + trianglewidth);
- int yinner1 = y0 + innerpoint * sin (angle + trianglewidth);
- int xinner2 = centerx + innerpoint * cos (angle - trianglewidth);
- int yinner2 = centery + innerpoint * sin (angle - trianglewidth);
- gfx->fillTriangle(xout, yout, xinner1, yinner1, xinner2, yinner2, color);
- }
- void display_meter2(float scale, int analogval, uint16_t color )
- {
- const int outerpoint = 76; // outer triangle point, distance form center
- const int innerpoint = 58;// inner triangle point, distance form center
- const int trianglewidth = 3; // width of triangle in center, in degree
- const int centerx = 120;
- const int centery = 120;
- byte x0 = 120;
- byte y0 = 120;
- float angle = (PI / 257) * (analogval + 68); // map analog in 0,1023, to 0.00,3.14
- int xout = centerx - outerpoint * cos (angle);
- int yout = centery - outerpoint * sin (angle);
- //inner triangle points
- int xinner1 = x0 + innerpoint * cos (angle + trianglewidth);
- int yinner1 = y0 + innerpoint * sin (angle + trianglewidth);
- int xinner2 = centerx + innerpoint * cos (angle - trianglewidth);
- int yinner2 = centery + innerpoint * sin (angle - trianglewidth);
- gfx->fillTriangle(xout, yout, xinner1, yinner1, xinner2, yinner2, color);
- }
- HardwareSerial Sender(1); // Define a Serial port instance called 'Sender' using serial port 1
- #define Sender_Txd_pin 17
- #define Sender_Rxd_pin 16
- void setup()
- {
- Serial.begin(115200);
- Sender.begin(115200, SERIAL_8N1, Sender_Txd_pin, Sender_Rxd_pin); // Define and start Sender serial port
- gfx->begin();
- gif();
- //bmp();
- }
- void loop() {
- float testvalue = 50;
- Sender.print(testvalue);
- maxboost();
- tempSensor();
- currentMillis = millis();
- if (currentMillis - startMillis >= period) {
- startMillis = currentMillis;
- readSensorData();
- display_meter(0, adcval, Black); //remove old line
- if (adcval > 1)
- display_meter(0, adcval - 1, Black); //remove old line
- display_meter(0, adcval + 1, Black); //remove old line
- display_meter(0, adcval - 2, Black); //remove old line
- display_meter(0, adcval + 2, Black); //remove old line
- adcval = boostPressure; //get new adcval
- display_meter(0, adcval, White); //draw new white line
- if (adcval > 1)display_meter(0, adcval - 1, White); //draw new white line
- display_meter(0, adcval + 1, White); //draw new white line
- int x21 = 0;
- if (boostPressure < 0) x21 = 86;
- else if (x21 = 98);
- if (boostPressure >= 0 ) gfx->setTextSize(2); gfx->setCursor(86, 95); gfx->setTextColor(0x0000); gfx->print("-");
- char cstr[6];
- dtostrf((float)boostPressure / 100.1 , 1, 2, cstr);
- gfx->setTextColor(White, Black );
- gfx->setCursor(x21, 95);
- gfx->setTextSize(2);
- gfx->print(cstr);
- dtostrf((float)boostMax / 100.1, 1, 2, cstr);
- gfx->setCursor(100, 135);
- gfx->print(cstr);
- }
- }
- void readSensorData(void) {
- float absolutePressure = ((analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15)) / 10);
- boostPressure = ((absolutePressure - offset) * 3 / 2511.5) * 100.1;
- if (boostPressure > boostMax) boostMax = boostPressure;
- if (boostPressure < boostMin) boostMin = boostPressure;
- }
- void maxboost(void) {
- if (boostMax > 100) {
- adcval2 = boostMax; //get new adcval
- display_meter2(0, adcval2, Red); //draw new white line
- if (adcval2 > 1)
- display_meter2(0, adcval2 - 1, Red); //draw new white line
- display_meter2(0, adcval2 + 1, Red); //draw new white line
- }
- if (boostPressure < boostMax); {
- if (millis() > myTimeout + myTimer ) {
- myTimer = 0;
- myTimer = millis();
- display_meter2(0, adcval2, Black); //remove old line
- if (adcval2 > 1)
- display_meter2(0, adcval2 - 1, Black); //remove old line
- display_meter2(0, adcval2 + 1, Black); //remove old line
- display_meter2(0, adcval2 - 2, Black); //remove old line
- display_meter2(0, adcval2 + 2, Black); //remove old line
- boostMax = 0;
- }
- }
- }
- void tempSensor (void) {
- currentMillis2 = millis();
- if (currentMillis2 - startMillis2 >= period2) {
- startMillis2 = currentMillis2;
- int temp;
- int tempOut;
- int analogValue = analogRead(13);
- analogValue = map(analogValue, wert1, wert2, temp1, temp2);
- temp = analogValue * 100.1;
- tempOut = temp / 100.1;
- Serial.print("Temperatur: ");
- Serial.println((tempOut), 1);
- Serial.print(" Messwert: ");
- Serial.println(analogRead(13));
- gfx->setTextColor(White, Black );
- gfx->setCursor(100, 190);
- gfx->setTextSize(2);
- gfx->print((tempOut), 1); gfx->setTextSize(1); gfx->print("o"); gfx->setTextSize(2); gfx->print("C");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement