Advertisement
GaabMM88

Untitled

Aug 13th, 2024
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.68 KB | None | 0 0
  1. //
  2. const char compile_date[] = __DATE__;
  3. //Included with the name printing
  4. #include <HardwareSerial.h>
  5. #include "AiEsp32RotaryEncoder.h"
  6. #include "Arduino.h"
  7. #include "Wire.h"
  8. #include <Adafruit_NeoPixel.h>
  9.  
  10. HardwareSerial uart(2);  // Uso de la interfaz de hardware Serial2
  11.  
  12. #define ROTARY_ENCODER_A_PIN 35
  13. #define ROTARY_ENCODER_B_PIN 32
  14. #define ROTARY_ENCODER_BUTTON_PIN 33
  15. #define ROTARY_ENCODER_VCC_PIN -1 /* 27 put -1 of Rotary encoder Vcc is connected directly to 3,3V; else you can use declared output pin for powering rotary encoder */
  16. #define ROTARY_ENCODER_STEPS 4
  17. //#define muteSW
  18. //#define inputSW
  19. #define powerSW 23
  20. #define dcSenseRight 19
  21. #define dcSenseLeft 18
  22. #define acSense 5
  23.  
  24. #define relay 13
  25. #define WS2812 2
  26. #define NUMPIXELS 8
  27. Adafruit_NeoPixel pixels(NUMPIXELS, WS2812, NEO_RGB + NEO_KHZ800);
  28. int offset = 2;
  29. int digiVolume = 0, dmute = 0, lastPressed = 0, source = 0;
  30. boolean powerState = 0, lastPowerState = 0, nextionSetTimebit = 1;
  31. //boolean dcSense = 0, lastDcSense = 0;
  32. //boolean acSense = 0, lastAcSense = 0;
  33. String sReceived;
  34. //instead of changing here, rather change numbers above
  35. AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, ROTARY_ENCODER_VCC_PIN, ROTARY_ENCODER_STEPS);
  36.  
  37. void rotary_onButtonClick() {
  38.   static unsigned long lastTimePressed = 0;
  39.   //ignore multiple press in that time milliseconds
  40.   if (millis() - lastTimePressed < 500) {
  41.     return;
  42.   }
  43.   lastTimePressed = millis();
  44.   Serial.print("button pressed ");
  45.   Serial.print(millis());
  46.   Serial.println(" milliseconds after restart");
  47.   if (dmute == 0) {
  48.     uart.print("MUT:1;");
  49.   } else {
  50.     uart.print("MUT:0;");
  51.   }
  52. }
  53.  
  54. void rotary_loop() {
  55.   //dont print anything unless value changed
  56.   if (rotaryEncoder.encoderChanged()) {
  57.     Serial.print("Value: ");
  58.     Serial.println(rotaryEncoder.readEncoder());
  59.     uart.print("VOL:" + String(rotaryEncoder.readEncoder()) + ";");
  60.     digiVolume = rotaryEncoder.readEncoder();
  61.   }
  62.   if (rotaryEncoder.isEncoderButtonClicked()) {
  63.     rotary_onButtonClick();
  64.   }
  65. }
  66.  
  67. void IRAM_ATTR readEncoderISR() {
  68.   rotaryEncoder.readEncoder_ISR();
  69. }
  70.  
  71. void inputLed(int input) {
  72.   source = input;
  73.   int r = 0, g = 0, b = 0;
  74.   switch (input) {
  75.     case 0:  // WiFi
  76.       r = 49;
  77.       g = 50;
  78.       b = 51;
  79.       break;
  80.     case 1:  // Bluetooth
  81.       r = 0;
  82.       g = 0;
  83.       b = 50;
  84.       break;
  85.     case 2:  // Line-In
  86.       r = 0;
  87.       g = 50;
  88.       b = 0;
  89.       break;
  90.     case 3:  // USB-DAC
  91.       r = 50;
  92.       g = 0;
  93.       b = 0;
  94.       break;
  95.     case 4:  // OFF
  96.       r = 55;
  97.       g = 35;
  98.       b = 0;
  99.       break;
  100.   }
  101.   for(int i=0; i<NUMPIXELS; i++){
  102.   pixels.setPixelColor(i, pixels.Color(g, r, b));
  103.   pixels.show();  // Send the updated pixel colors to the hardware.
  104.   }
  105. }
  106.  
  107.  
  108. class c_NextionWrite {
  109. public:
  110.   void init(int speed, int RXN, int TXN) {
  111.     Serial1.begin(speed, SERIAL_8N1, RXN, TXN);
  112.     // Serial.printf("Serial1 - Speed: %d, RX-pin: %d, TX-pin: %d \n", speed, RX, TX);
  113.   }
  114.   void txt(String Name, String text) {
  115.     Serial1.print(Name + ".txt=\"" + text + "\"\xFF\xFF\xFF");
  116.     Serial.println(Name + ".txt=\"" + text + "\"\xFF\xFF\xFF");
  117.   }
  118.   void val(String Name, int value) {
  119.     Serial1.print(Name + ".val=" + String(value) + "\xFF\xFF\xFF");
  120.     Serial.print(Name + ".val=" + String(value) + "\xFF\xFF\xFF");
  121.   }
  122.   void pageChange(int nr) {
  123.     Serial1.print("page " + String(nr) + "\xFF\xFF\xFF");
  124.     Serial.print("page " + String(nr) + "\xFF\xFF\xFF");
  125.   }
  126.   void setPco(String name, int pco) {
  127.     Serial1.print(name + ".pco=" + String(pco) + "\xFF\xFF\xFF");
  128.     Serial.print(name + ".pco=" + String(pco) + "\xFF\xFF\xFF");
  129.   }
  130.   void timerEnable(String name, int en) {
  131.     Serial1.print(name + ".en=" + String(en) + "\xFF\xFF\xFF");
  132.   }
  133.   void vis(String name, int en) {
  134.     Serial1.print("vis " + name + "," + String(en) + "\xFF\xFF\xFF");
  135.   }
  136.   void setTime(int hour, int min, int sec){
  137.     hour = (hour + 24) % 24;
  138.     Serial1.print("rtc3=" String(hour) + "\xFF\xFF\xFF");
  139.     Serial1.print("rtc4=" String(min) + "\xFF\xFF\xFF");
  140.     Serial1.print("rtc5=" String(sec) + "\xFF\xFF\xFF");
  141.     Serial.printf("Nextion time/ hour: %d min: %d sec: %d \n", hour,min,sec);
  142.     Serial.println("--------------------");
  143.   }
  144. };
  145. c_NextionWrite nextion;
  146.  
  147. #define RXN_PIN 26  // Serial1 RX to Nextion TX
  148. #define TXN_PIN 25  // Serial1 TX to Nextion RX
  149.  
  150. #define RX_PIN 14  // Serial2 RX a Amp TX
  151. #define TX_PIN 27  // Serial2 TX a Amp RX
  152.  
  153. #define SDA 21  // I2C Thermometer, Expander, etc.
  154. #define SCL 22
  155. //#define INT ?
  156.  
  157. void setup() {
  158.   pixels.begin();  // INITIALIZE NeoPixel strip object (REQUIRED)
  159.   pinMode(relay, OUTPUT);
  160.   delay(1);
  161.   digitalWrite(relay, 0);
  162.  
  163.  
  164.   //pinMode(muteSW, INPUT);
  165.   //pinMode(inputSW, INPUT);
  166.   pinMode(powerSW, INPUT_PULLUP);
  167.   pinMode(dcSenseRight, INPUT_PULLUP);
  168.   pinMode(dcSenseLeft, INPUT_PULLUP);
  169.   pinMode(acSense, INPUT_PULLUP);
  170.   rotaryEncoder.begin();
  171.   rotaryEncoder.setup(readEncoderISR);
  172.   //set boundaries and if values should cycle or not
  173.   //in this example we will set possible values between 0 and 1000;
  174.   bool circleValues = false;
  175.   rotaryEncoder.setBoundaries(0, 100, circleValues);  //minValue, maxValue, circleValues true|false (when max go to min and vice versa)
  176.  
  177.   /*Rotary acceleration introduced 25.2.2021.
  178.    * in case range to select is huge, for example - select a value between 0 and 1000 and we want 785
  179.    * without accelerateion you need long time to get to that number
  180.    * Using acceleration, faster you turn, faster will the value raise.
  181.    * For fine tuning slow down.
  182.    */
  183.   //rotaryEncoder.disableAcceleration(); //acceleration is now enabled by default - disable if you dont need it
  184.   rotaryEncoder.setAcceleration(0);  //or set the value - larger number = more accelearation; 0 or 1 means disabled acceleration
  185.   rotaryEncoder.setEncoderValue(digiVolume);
  186.  
  187.   // put your setup code here, to run once:
  188.   Wire.begin(SDA, SCL);
  189.   Serial.begin(115200);
  190.   Serial.println("Starting..");
  191.   Serial1.begin(115200, SERIAL_8N1, RXN_PIN, TXN_PIN);
  192.   // Inicializar la comunicación UART
  193.   uart.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN);
  194.   // uart.setTimeout(2000);
  195.   delay(2000);
  196.   Serial.println("Started...");
  197.   Serial.println(compile_date);
  198.   uart.print("PMT:1;");
  199.   uart.print("BEP:0;");
  200.   uart.print("BEP;");
  201.   uart.print("PMT;");
  202.   nextion.txt("bt_text", "ESP32 now starting...");
  203.   delay(500);
  204.   nextion.vis("bt_text", 0);
  205.   delay(500);
  206.   nextion.vis("bt_text", 1);
  207.   //uart.print("SYS:REBOOT;");
  208.   //delay(3500);
  209.   uart.print("SYS:STANDBY;");
  210.   uart.print("SYS:STANDBY;");
  211.   uart.print("SYS:STANDBY;");
  212.   uart.print("SYS:STANDBY;");
  213.   Serial.println("Initial OFF");
  214.   nextion.pageChange(3);
  215.   inputLed(4);
  216. }
  217.  
  218. void loop() {
  219.  
  220.   if (digitalRead(powerSW) == 0 && lastPowerState == 1 && lastPressed + 5000 < millis()) {
  221.     Serial.println(digitalRead(powerSW));
  222.  
  223.     if (powerState == 0) {
  224.       powerState = 1;
  225.       uart.print("SYS:REBOOT;");
  226.       Serial.println("Digi REBOOT...");
  227.     } else {
  228.       powerState = 0;
  229.       uart.print("SYS:STANDBY;");
  230.       Serial.println("Digi STANDBY...");
  231.       inputLed(4);
  232.     }
  233.     lastPressed = millis();
  234.   }
  235.  
  236.   if ((digitalRead(dcSenseRight) == 0)) {
  237.     Serial.println("DC RIGHT FAIL");
  238.   }
  239.  
  240.   if ((digitalRead(dcSenseLeft) == 0)) {
  241.     Serial.println("DC LEFT FAIL");
  242.   }
  243.  
  244.   if ((digitalRead(acSense) == 0)) {
  245.     Serial.println("AC FAIL");
  246.   }
  247.  
  248.   lastPowerState = digitalRead(powerSW);  //1
  249.   rotary_loop();
  250.   // put your main code here, to run repeatedly:
  251.   while (uart.available()) {
  252.     sReceived = uart.readStringUntil('\n');
  253.     sReceived.trim();
  254.     Serial.println("uart:___|" + sReceived);
  255.     if (sReceived.startsWith("PLA:0")) {
  256.       nextion.txt("bt_text", "Szünet/Megállítva");
  257.     } else if (sReceived.startsWith("PLA:1")) {
  258.       nextion.txt("bt_text", "Lejátszás...");
  259.     } else if (sReceived.startsWith("STA:")) {
  260.       digitalWrite(relay, 1);
  261.       nextion.pageChange(0);
  262.       nextion.vis("bt_text", 0);
  263.       Serial.println("STA received");
  264.       Serial.println("Before: " + sReceived);
  265.       nextion.val("wifi", 0);
  266.       nextion.val("bluetooth", 0);
  267.       nextion.val("line_in", 0);
  268.       nextion.val("usbdac", 0);
  269.       nextion.txt("bt_text", "");
  270.       nextion.vis("bt3", 0);
  271.       nextion.vis("title", 0);
  272.       nextion.vis("elapsed", 0);
  273.       nextion.vis("vendor", 0);
  274.       // reduce4();
  275.       reduce4();
  276.       if (sReceived.startsWith("USBDAC")) {
  277.         nextion.val("usbdac", 1);
  278.         inputLed(3);
  279.         // nextion.txt("bt_text", "USBDAC");   //rem if not needed(ONLY FOR TESTING)
  280.         Serial.println("...USBADC...");
  281.       } else if (sReceived.startsWith("NET")) {
  282.         nextion.vis("title", 1);
  283.         nextion.vis("elapsed", 1);
  284.         nextion.vis("vendor", 1);
  285.         nextion.val("wifi", 1);
  286.         nextion.vis("bt_text", 1);
  287.         inputLed(0);
  288.         // nextion.txt("bt_text", "WIFI");   //rem if not needed
  289.         Serial.println("...WIFI...");
  290.       } else if (sReceived.startsWith("BT")) {
  291.         nextion.val("bluetooth", 1);
  292.         nextion.vis("bt_text", 1);
  293.         nextion.vis("bt3", 1);
  294.         inputLed(1);
  295.         // nextion.txt("bt_text", "BLUETOOTH");    //rem if not needed
  296.         Serial.println("...BLUETOOTH...");
  297.       } else if (sReceived.startsWith("LINE-IN")) {
  298.         nextion.val("line_in", 1);
  299.         inputLed(2);
  300.         // nextion.txt("bt_text", "LINE IN");    //rem if not needed
  301.         Serial.println("...LINE-IN...");
  302.       }
  303.     } else if (sReceived.startsWith("SYS:STANDBY"))  //END OF STA:
  304.     {
  305.       inputLed(4);
  306.       Serial.println("Stand by mode...");
  307.       nextion.pageChange(3);
  308.       digitalWrite(relay, 0);
  309.       nextionSetTimebit=1;
  310.     } else if (sReceived.startsWith("SRC:")) {
  311.       nextion.vis("bt_text", 0);
  312.       nextion.val("wifi", 0);
  313.       nextion.val("bluetooth", 0);
  314.       nextion.val("line_in", 0);
  315.       nextion.val("usbdac", 0);
  316.       nextion.vis("title", 0);
  317.       nextion.vis("elapsed", 0);
  318.       nextion.vis("vendor", 0);
  319.       reduce4();
  320.       if (sReceived.startsWith("USBDAC")) {
  321.         inputLed(3);
  322.         nextion.val("usbdac", 1);
  323.         // nextion.txt("bt_text", "USBDAC");   //rem if not needed
  324.         Serial.println("...USBDAC...");
  325.       } else if (sReceived.startsWith("NET")) {
  326.         inputLed(0);
  327.         nextion.val("wifi", 1);
  328.         nextion.vis("bt_text", 1);
  329.         // nextion.txt("bt_text", "WIFI");   //rem if not needed
  330.         Serial.println("...WIFI...");
  331.         nextion.vis("title", 1);
  332.         nextion.vis("elapsed", 1);
  333.         nextion.vis("vendor", 1);
  334.       } else if (sReceived.startsWith("BT")) {
  335.         inputLed(1);
  336.         nextion.val("bluetooth", 1);
  337.         nextion.vis("bt_text", 1);
  338.         // nextion.txt("bt_text", "BLUETOOTH");    //rem if not needed
  339.         Serial.println("...BLUETOOTH...");
  340.       } else if (sReceived.startsWith("LINE-IN")) {
  341.         inputLed(2);
  342.         nextion.val("line_in", 1);
  343.         // nextion.txt("bt_text", "LINE IN");    //rem if not needed
  344.         Serial.println("...LINE-IN...");
  345.       }
  346.     } else if (sReceived.startsWith("VOL:"))  //end of SRC:
  347.     {
  348.       reduce4();
  349.       int index = sReceived.indexOf(';');
  350.       sReceived = sReceived.substring(0, index);
  351.       if (sReceived == "100") {
  352.         nextion.txt("volText", "MAX");
  353.       } else if (sReceived == "0") {
  354.         nextion.txt("volText", "MIN");
  355.       } else {
  356.         Serial.println("volume:  -|:" + sReceived);
  357.         digiVolume = sReceived.toInt();
  358.         nextion.txt("volText", sReceived);
  359.       }
  360.       nextion.val("volSlide", digiVolume);
  361.       rotaryEncoder.setEncoderValue(digiVolume);
  362.     } else if (sReceived.startsWith("MUT:"))  //end of VOL:
  363.     {
  364.       reduce4();
  365.       sReceived = sReceived.substring(0, 1);
  366.       Serial.println("Mute:_____:|" + sReceived);
  367.       if (sReceived == "1") {
  368.         dmute = 1;
  369.         nextion.txt("volText", "MIN");
  370.         nextion.val("volSlide", 0);
  371.       } else if (sReceived == "0") {
  372.         dmute = 0;
  373.         nextion.txt("volText", String(digiVolume));
  374.         nextion.val("volSlide", digiVolume);
  375.       }
  376.  
  377.     } else if (sReceived.startsWith("BTC:") || sReceived.startsWith("NET:"))  //end of MUT:
  378.     {
  379.       reduce4();
  380.       sReceived = sReceived.substring(0, 1);
  381.       if (sReceived == "1") {
  382.         nextion.txt("bt_text", "CONNECTED");
  383.         uart.print("TIT;");
  384.       } else if (sReceived == "0") {
  385.         nextion.txt("bt_text", "DISCONNECTED");
  386.       }
  387.     } else if (sReceived.endsWith("SYS:ON;")) {
  388.       nextion.txt("powerOn", "STARTED");
  389.       nextion.setPco("powerOn", 34784);
  390.       Serial.println("arrived SYS:ON...");
  391.     } else if (sReceived.startsWith("TIT:")) {
  392.       reduce4();
  393.       Serial.println("Title: " + sReceived);
  394.       sReceived = sReceived.substring(0, sReceived.length() - 1);
  395.       nextion.txt("title", sReceived);
  396.       // nextion.timerEnable("tm1", 1);
  397.     } else if (sReceived.startsWith("PMT:0")) {
  398.       nextion.txt("pmt", "PMT ON");
  399.       Serial.println(sReceived);
  400.     } else if (sReceived.startsWith("PMT:1")) {
  401.       nextion.txt("pmt", "PMT OFF");
  402.       Serial.println(sReceived);
  403.     } else if (sReceived.startsWith("ELP:")) {
  404.       reduce4();
  405.       int index = sReceived.indexOf("/");
  406.       sReceived = sReceived.substring(0, index);
  407.       // Serial1.println(sReceived);
  408.       long time = sReceived.toInt();
  409.       time = time / 100;
  410.       int tenth = time % 10;
  411.       time = time / 10;
  412.       long hour = time / 3600;        
  413.       time = time - (hour * 3600);
  414.       long min = time / 60;
  415.       long sec = time - (min * 60);
  416.       // if(nextionSetTimebit==1){
  417.       //   nextion.setTime(hour,min,sec);
  418.       // }
  419.       String timeS = "Time: ";
  420.       if (hour < 10) timeS += "0";
  421.       timeS += String(hour) + ":";
  422.       if (min < 10) timeS += "0";
  423.       timeS += String(min) + ":";
  424.       if (sec < 10) timeS += "0";
  425.       timeS += String(sec) + "." + String(tenth);
  426.  
  427.       // sReceived = String(hour) + ":" + String(min) + ":" + String(sec);
  428.       // Serial.println("ELP:.....|" + timeS);
  429.       if (time > 0) nextion.txt("elapsed", timeS);
  430.     } else if (sReceived.startsWith("BAS:")) {
  431.       // Serial.println("BASS BEFORE substring....|" + sReceived);
  432.       reduce4();
  433.       sReceived = sReceived.substring(0, sReceived.length() - 1);
  434.       // Serial.println("BASS STILL STRING:.....|" + sReceived);
  435.       int bass = sReceived.toInt();
  436.       // Serial.println("BASS INT:....|" + String(bass));
  437.       nextion.val("nbass", bass);
  438.       if (bass < 0) {
  439.         bass = 11 - abs(bass);
  440.       } else {
  441.         bass = bass + 11;
  442.       }
  443.       // Serial.println("BASS AFTERCALC....|"+String(bass));
  444.       nextion.val("hbass", bass);
  445.       // Serial.println("BASS:.....|" + String(bass));
  446.     } else if (sReceived.startsWith("TRE:")) {
  447.       reduce4();
  448.       sReceived = sReceived.substring(0, sReceived.length() - 1);
  449.       int treb = sReceived.toInt();
  450.       Serial.println("TREB INT VALUE:...|" + String(treb));
  451.       nextion.val("ntreb", treb);
  452.       if (treb < 0) {
  453.         treb = 11 - abs(treb);
  454.       } else {
  455.         treb = treb + 11;
  456.       }
  457.       nextion.val("htreb", treb);
  458.     } else if (sReceived.startsWith("VBS:")) {
  459.       reduce4();
  460.       sReceived = sReceived.substring(0, sReceived.length() - 1);
  461.       if (sReceived == "1") {
  462.         nextion.val("vbs", 1);
  463.         nextion.txt("t3", "ON");
  464.       } else {
  465.         nextion.val("vbs", 0);
  466.         nextion.txt("t3", "OFF");
  467.       }
  468.     } else if (sReceived.startsWith("VST:")) {
  469.       reduce4();
  470.       // write something to nextion SETUP (1) page
  471.       nextion.val("nVolStep", sReceived.toInt());
  472.       nextion.val("hVolStep", sReceived.toInt());
  473.     } else if (sReceived.startsWith("NAM:")) {
  474.       reduce4();
  475.       sReceived = sReceived.substring(0, sReceived.length() - 1);
  476.       String dname, Nname;
  477.       int h = 16, sz = 0, dsz = 0;
  478.       if (sReceived.length() > 0) {
  479.         for (int i = 0; i <= sReceived.length() - 1; i = i + 1) {
  480.           dname = sReceived.substring(i, i + 1);
  481.           if (dname.toInt() >= 0 && dname.toInt() <= 9) {
  482.             sz = dname.toInt();
  483.             // Serial.println(dname);
  484.           }
  485.           if (dname == "A") sz = 10;
  486.           if (dname == "B") sz = 11;
  487.           if (dname == "C") sz = 12;
  488.           if (dname == "D") sz = 13;
  489.           if (dname == "E") sz = 14;
  490.           if (dname == "F") sz = 15;
  491.           // sz += sz * h;
  492.           if (h == 0) {
  493.             dsz += sz;
  494.             Serial.printf("%i. sz=%i\n", i, dsz);
  495.  
  496.             // Serial.printf("%i, | ", dsz);
  497.             Nname += char(dsz);
  498.             dsz = 0;
  499.           } else {
  500.             dsz = sz * 16;
  501.           }
  502.           h = 16 - h;
  503.         }
  504.         Serial.println(Nname);
  505.         nextion.txt("NAME", Nname);
  506.       }
  507.     } else if (sReceived.startsWith("IPA:")) {
  508.       reduce4();
  509.       sReceived = sReceived.substring(0, sReceived.length() - 1);  //removing ";"
  510.       nextion.txt("page1.t5", sReceived);
  511.     } else if (sReceived.startsWith("TME:")) {
  512.  
  513.       String dc = sReceived.substring(21, 23);
  514.       String nc = sReceived;
  515.       int hour = dc.toInt();
  516.       if (hour % 2) {
  517.         dc = " ";
  518.       } else {
  519.         dc = ":";
  520.       }
  521.       // Serial.println("Second: "+dc);
  522.       String st = sReceived.substring(15, 17);
  523.       hour = st.toInt();
  524.  
  525.       // Serial.printf("Hour: %i\n",hour);
  526.  
  527.       hour = hour + offset;  //1+(-4)=-3 , -3+24=21 % 24 = 21 /// 22+(-4)=18 , 18+24=42 , 42 % 24 = 18
  528.       hour = (hour + 24) % 24;
  529.       if (hour < 10) {
  530.         sReceived = "0" + String(hour) + dc + sReceived.substring(18, 20);
  531.       } else {
  532.         sReceived = String(hour) + dc + sReceived.substring(18, 20);
  533.       }
  534.       Serial.println(sReceived);
  535.       nextion.txt("t6", sReceived);
  536.       dc = nc.substring(4,8);
  537.       Serial.println(dc);
  538.       Serial.println(nextionSetTimebit);
  539.       if(dc!="2000"&& nextionSetTimebit==1){
  540.         dc=nc.substring(15,17);
  541.         int hour = dc.toInt();
  542.         dc=nc.substring(18,20);
  543.         int min = dc.toInt();
  544.         dc=nc.substring(21,23);
  545.         int sec = dc.toInt();
  546.         nextion.setTime(hour,min,sec);
  547.         nextionSetTimebit=0;
  548.       }
  549.  
  550.     } else if (sReceived.startsWith("VND:")) {
  551.       reduce4();
  552.       sReceived = sReceived.substring(0, sReceived.length() - 1);  //removing ";"
  553.       nextion.txt("vVendor", sReceived);
  554.     }
  555.  
  556.  
  557.     sReceived = "";
  558.   }  //end of uart
  559.  
  560.  
  561.  
  562.   while (Serial1.available()) {
  563.     String nReceived = Serial1.readStringUntil(';');
  564.     Serial.println("Serial1:__|" + nReceived + ";");
  565.  
  566.     uart.print(nReceived + ";");
  567.   }
  568. }
  569. void reduce4() {
  570.   sReceived = sReceived.substring(4);
  571. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement