From 344071b848433bcc4a3a894579cf510617c02ce6 Mon Sep 17 00:00:00 2001 From: Zhaoliang <zhz03@g.ucla.edu> Date: Fri, 15 Oct 2021 01:34:55 -0700 Subject: [PATCH] upload the master code to change the PID value --- .../simple_test/ESP32_master/ESP32_master.ino | 62 ++++++------------- 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/Code/ESP32_communication/simple_test/ESP32_master/ESP32_master.ino b/Code/ESP32_communication/simple_test/ESP32_master/ESP32_master.ino index d06a0bb..de148c2 100644 --- a/Code/ESP32_communication/simple_test/ESP32_master/ESP32_master.ino +++ b/Code/ESP32_communication/simple_test/ESP32_master/ESP32_master.ino @@ -7,10 +7,13 @@ //------------------------------------------------------------------------------------- uint8_t RxMACaddress[] = {0xC4, 0xDD, 0x57, 0x9E, 0x91, 0x74}; String strdata = ""; +String valdata = ""; +int count = 0; //------------------------------------------------------------------------------------- typedef struct TxStruct { - int potVal; + String StrD; + double ValD; }TxStruct; TxStruct sentData; //------------------------------------------------------------------------------------- @@ -56,17 +59,29 @@ void loop() delay(500); */ strdata += char(inChar); - + delay(10); + count +=1; + if (count == 3){ + sentData.StrD = strdata; + Serial.println(sentData.StrD); + } + if (isDigit(inChar) || inChar == '.'){ + valdata += char(inChar); + } + if (inChar == '\n'){ - sentData.potVal = strdata.toInt(); - Serial.println(sentData.potVal); + sentData.ValD = valdata.toDouble(); + Serial.println(sentData.ValD); esp_err_t result = esp_now_send(RxMACaddress, (uint8_t *) &sentData, sizeof(sentData)); + // esp_now_send(RxMACaddress, (uint8_t *) &sentData, sizeof(sentData)); //------------------------------------------------------------------------------------- if (result == ESP_OK) Serial.println("Sent with success"); else Serial.println("Error sending the data"); //------------------------------------------------------------------------------------- delay(500); strdata = ""; + valdata = ""; + count = 0; } } @@ -74,42 +89,3 @@ void loop() //------------------------------------------------------------------------------------- } - - -/* - * String inString = ""; // string to hold input - -void setup() { - // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only - } - - // send an intro: - Serial.println("\n\nString toInt():"); - Serial.println(); -} - -void loop() { - // Read serial input: - while (Serial.available() > 0) { - int inChar = Serial.read(); - if (isDigit(inChar)) { - // convert the incoming byte to a char and add it to the string: - inString += (char)inChar; - } - // if you get a newline, print the string, then the string's value: - if (inChar == '\n') { - Serial.print("Value:"); - Serial.println(inString.toInt()); - Serial.print("String: "); - Serial.println(inString); - // clear the string for new input: - inString = ""; - } - } -} - - * / - */ -- GitLab