Advertisement
PrintService3D

Sender

Oct 17th, 2022
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.29 KB | None | 0 0
  1. #define BMP_FILENAME "/octocat2.bmp" // 456x240@16bit
  2. #define GIF_FILENAME "/joel2.gif"
  3.  
  4. #include <HardwareSerial.h>
  5. #include <Arduino_GFX_Library.h>
  6.  
  7. #define GFX_BL 5 // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
  8.  
  9.  
  10. #if defined(DISPLAY_DEV_KIT)
  11. Arduino_GFX *gfx = create_default_Arduino_GFX();
  12. #else /* !defined(DISPLAY_DEV_KIT) */
  13.  
  14. Arduino_DataBus *bus = new Arduino_ESP32SPI(5 /* DC */, 22 /* CS */, 18 /* SCK */, 23 /* MOSI */, GFX_NOT_DEFINED /* MISO */, VSPI /* spi_num */);
  15.  
  16. Arduino_GFX *gfx = new Arduino_GC9A01(  bus, 4 /* RST */, 0 /* rotation */, true /* IPS */);
  17.  
  18. #endif /* !defined(DISPLAY_DEV_KIT) */
  19.  
  20.   #if defined(ESP32)
  21.   #include <FFat.h>
  22.   #include <LittleFS.h>
  23.   #include <SPIFFS.h>
  24.   #include <SD.h>
  25.   #endif
  26.  
  27. float boostPressure;
  28. int boostMax      =     0;
  29. int boostMax2     = boostMax;
  30. int boostMin      =     0;
  31. //int boostMin1     =    0;
  32. int ypos          =   128;
  33. int adcval        =     0;
  34. int adcval2        =     0;
  35. int atmo          =     0;
  36.  
  37. // int offset = 1177; // low pressure calibration
  38.  
  39. int offset = 1191; // low pressure calibration
  40.  
  41.  
  42. int span = 3685.5; // high pressure calibration
  43.  
  44. unsigned long startMillis;
  45. unsigned long currentMillis;
  46. const unsigned long period = 100;
  47.  
  48. unsigned long startMillis2;
  49. unsigned long currentMillis2;
  50. const unsigned long period2 = 1000;
  51.  
  52. long myTimer = 0;
  53. long myTimeout = 15000;
  54.  
  55.  
  56. #define wert1 4095                        //b
  57. #define wert2 0                           //c
  58. #define temp1 -40   //Grad Celsius/10     //d
  59. #define temp2 130 //Grad Celsius/10       //e
  60.  
  61. #define Black           0x0000      /*   0,   0,   0 */
  62. #define Navy            0x000F      /*   0,   0, 128 */
  63. #define DarkGreen       0x03E0      /*   0, 128,   0 */
  64. #define DarkCyan        0x03EF      /*   0, 128, 128 */
  65. #define Maroon          0x7800      /* 128,   0,   0 */
  66. #define Purple          0x780F      /* 128,   0, 128 */
  67. #define Olive           0x7BE0      /* 128, 128,   0 */
  68. #define LightGrey       0xC618      /* 192, 192, 192 */
  69. #define DarkGrey        0x7BEF      /* 128, 128, 128 */
  70. #define Red             0xF800      /*   0,   0, 255 */
  71. #define Green           0x07E0      /*   0, 255,   0 */
  72. #define Cyan            0x07FF      /*   0, 255, 255 */
  73. #define Blue            0x001F      /* 255,   0,   0 */
  74. #define Magenta         0xF81F      /* 255,   0, 255 */
  75. #define Yellow          0xFFE0      /* 255, 255,   0 */
  76. #define White           0xFFFF      /* 255, 255, 255 */
  77. #define Orange          0xFD20      /* 255, 165,   0 */
  78. #define GreenYellow     0xAFE5      /* 173, 255,  47 */
  79. #define Not             0xAC27      /*   4,  40,  71 */
  80. #define Pink            0xF81F
  81.  
  82.  
  83. #include "gif.h"
  84.  
  85. #include "bmp.h"
  86.  
  87. void display_meter(float scale, int analogval, uint16_t color )
  88. {
  89.   const int outerpoint = 76; // outer triangle point, distance form center
  90.   const int innerpoint = 58;// inner triangle point, distance form center
  91.   const int trianglewidth = 3; // width of triangle in center, in degree
  92.   const int centerx = 120;
  93.   const int centery = 120;
  94.   byte x0 = 120;
  95.   byte y0 = 120;
  96.  
  97.  
  98.   //  float angle  = (PI / 4095) * (analogval - 80); // map analog in 0,1023, to 0.00,3.14
  99.   float angle  = (PI / 257) * (analogval + 68); // map analog in 0,1023, to 0.00,3.14
  100.  
  101.  
  102.   // outer triangle point
  103.   int xout = centerx - outerpoint * cos (angle);
  104.   int yout = centery - outerpoint * sin (angle);
  105.  
  106.   //inner triangle points
  107.   int xinner1 = x0 + innerpoint * cos (angle + trianglewidth);
  108.   int yinner1 = y0 + innerpoint * sin (angle + trianglewidth);
  109.  
  110.   int xinner2 = centerx + innerpoint * cos (angle - trianglewidth);
  111.   int yinner2 = centery + innerpoint * sin (angle - trianglewidth);
  112.  
  113.   gfx->fillTriangle(xout, yout, xinner1, yinner1, xinner2, yinner2, color);
  114. }
  115.  
  116. void display_meter2(float scale, int analogval, uint16_t color )
  117. {
  118.   const int outerpoint = 76; // outer triangle point, distance form center
  119.   const int innerpoint = 58;// inner triangle point, distance form center
  120.   const int trianglewidth = 3; // width of triangle in center, in degree
  121.   const int centerx = 120;
  122.   const int centery = 120;
  123.   byte x0 = 120;
  124.   byte y0 = 120;
  125.  
  126.   float angle  = (PI / 257) * (analogval + 68); // map analog in 0,1023, to 0.00,3.14
  127.   int xout = centerx - outerpoint * cos (angle);
  128.   int yout = centery - outerpoint * sin (angle);
  129.  
  130.   //inner triangle points
  131.   int xinner1 = x0 + innerpoint * cos (angle + trianglewidth);
  132.   int yinner1 = y0 + innerpoint * sin (angle + trianglewidth);
  133.  
  134.   int xinner2 = centerx + innerpoint * cos (angle - trianglewidth);
  135.   int yinner2 = centery + innerpoint * sin (angle - trianglewidth);
  136.  
  137.   gfx->fillTriangle(xout, yout, xinner1, yinner1, xinner2, yinner2, color);
  138. }
  139.  
  140.  
  141. HardwareSerial Sender(1);   // Define a Serial port instance called 'Sender' using serial port 1
  142.  
  143. #define Sender_Txd_pin 17
  144. #define Sender_Rxd_pin 16
  145.  
  146.  
  147. void setup()
  148. {
  149.   Serial.begin(115200);
  150.     Sender.begin(115200, SERIAL_8N1, Sender_Txd_pin, Sender_Rxd_pin); // Define and start Sender serial port
  151.   gfx->begin();
  152.  
  153.   gif();
  154.   //bmp();
  155.  
  156.  
  157. }
  158. void loop() {
  159.  
  160. float testvalue = 50;
  161.  Sender.print(testvalue);
  162.   maxboost();
  163.   tempSensor();
  164.  
  165.  
  166.   currentMillis = millis();
  167.   if (currentMillis - startMillis >= period) {
  168.     startMillis = currentMillis;
  169.     readSensorData();
  170.  
  171.     display_meter(0, adcval, Black); //remove old line
  172.     if (adcval > 1)
  173.       display_meter(0, adcval - 1, Black); //remove old line
  174.     display_meter(0, adcval + 1, Black); //remove old line
  175.     display_meter(0, adcval - 2, Black); //remove old line
  176.     display_meter(0, adcval + 2, Black); //remove old line
  177.  
  178.     adcval = boostPressure; //get new adcval
  179.     display_meter(0, adcval, White); //draw new white line
  180.     if (adcval > 1)display_meter(0, adcval - 1, White); //draw new white line
  181.     display_meter(0, adcval + 1, White); //draw new white line
  182.  
  183.  
  184.  
  185.  
  186.     int x21 = 0;
  187.  
  188.  
  189.  
  190.     if (boostPressure <  0) x21 = 86;
  191.     else if (x21 = 98);
  192.  
  193.     if (boostPressure >= 0 )    gfx->setTextSize(2); gfx->setCursor(86, 95); gfx->setTextColor(0x0000); gfx->print("-");
  194.  
  195.     char cstr[6];
  196.     dtostrf((float)boostPressure / 100.1 , 1, 2, cstr);
  197.  
  198.     gfx->setTextColor(White, Black );
  199.     gfx->setCursor(x21, 95);
  200.     gfx->setTextSize(2);
  201.     gfx->print(cstr);
  202.  
  203.     dtostrf((float)boostMax / 100.1, 1, 2, cstr);
  204.  
  205.     gfx->setCursor(100, 135);
  206.     gfx->print(cstr);
  207.  
  208.  
  209.   }
  210. }
  211.  
  212.  
  213. void readSensorData(void) {
  214.  
  215.   float absolutePressure = ((analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15) + analogRead(15)) / 10);
  216.   boostPressure = ((absolutePressure - offset) * 3 / 2511.5) * 100.1;
  217.  
  218.   if (boostPressure > boostMax) boostMax = boostPressure;
  219.   if (boostPressure < boostMin) boostMin = boostPressure;
  220.  
  221. }
  222. void maxboost(void) {
  223.  
  224.   if (boostMax > 100) {
  225.     adcval2 = boostMax; //get new adcval
  226.     display_meter2(0, adcval2, Red); //draw new white line
  227.     if (adcval2 > 1)
  228.       display_meter2(0, adcval2 - 1, Red); //draw new white line
  229.     display_meter2(0, adcval2 + 1, Red); //draw new white line
  230.   }
  231.   if (boostPressure < boostMax); {
  232.     if (millis() > myTimeout + myTimer ) {
  233.       myTimer = 0;
  234.       myTimer = millis();
  235.       display_meter2(0, adcval2, Black); //remove old line
  236.       if (adcval2 > 1)
  237.         display_meter2(0, adcval2 - 1, Black); //remove old line
  238.       display_meter2(0, adcval2 + 1, Black); //remove old line
  239.       display_meter2(0, adcval2 - 2, Black); //remove old line
  240.       display_meter2(0, adcval2 + 2, Black); //remove old line
  241.       boostMax = 0;
  242.     }
  243.   }
  244. }
  245.  
  246. void tempSensor (void) {
  247.  
  248.   currentMillis2 = millis();
  249.   if (currentMillis2 - startMillis2 >= period2) {
  250.     startMillis2 = currentMillis2;
  251.     int temp;
  252.     int tempOut;
  253.     int analogValue = analogRead(13);
  254.     analogValue = map(analogValue, wert1, wert2, temp1, temp2);
  255.    
  256.     temp = analogValue * 100.1;
  257.     tempOut = temp / 100.1;
  258.  
  259.     Serial.print("Temperatur: ");
  260.     Serial.println((tempOut), 1);
  261.     Serial.print(" Messwert: ");
  262.     Serial.println(analogRead(13));
  263.  
  264.  
  265.     gfx->setTextColor(White, Black );
  266.     gfx->setCursor(100, 190);
  267.     gfx->setTextSize(2);
  268.     gfx->print((tempOut), 1); gfx->setTextSize(1); gfx->print("o"); gfx->setTextSize(2); gfx->print("C");
  269.   }
  270. }
  271.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement