I have 2 Arduino Unos connected together with HC-12 wireless modules. One Arduino sends a string that is "s22.04e" - the "s" is the start character and the "e" is the end character. Using this sketch on the other Arduino I am able to receive that and take the "22.04" number out and save it to a float.
#include <SoftwareSerial.h>
SoftwareSerial HC12(5, 6); // HC-12 TX Pin, HC-12 RX Pin
char incomingData;
String readBuffer = "";
float val1 = 0;
float val2 = 0;
void setup() {
Serial.begin(115200); // Serial port to computer
HC12.begin(9600); // Serial port to HC12
}
void loop() {
readBuffer = "";
boolean start = false;
// Reads the incoming angle
while (HC12.available()) { // If HC-12 has data
incomingData = HC12.read(); // Store each icoming byte from HC-12
delay(5);
// Reads the data between the start "s" and end marker "e"
if (start == true) {
if (incomingData != 'e') {
readBuffer += char(incomingData); // Add each byte to ReadBuffer string variable
}
else {
start = false;
}
}
// Checks whether the received message statrs with the start marker "s"
else if ( incomingData == 's') {
start = true; // If true start reading the message
}
}
// Converts the string into integer
if (readBuffer != "") {
val1 = readBuffer.toFloat();
Serial.println(val1, 2);
}
delay(1000);
}
My question is this: How do I change the code to be able to receive 2 variables. Let's say I send "s22.04,897.62e", how do I do it so that I receive a Val1 = 22.04 and Val2 = 897.62?