Hi,
I have a char array called 'receivedChars'. The first character is ascii capital 'R' and the next 4 characters are numbers, a sensor reading.
How can remove the 'R' and convert the numbers to a string?
Here is my code so far. In the void showNewData() I tried converting the char array to a string and using the String remove method() but it doesn't seem to work.
Many thanks
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}
void loop() {
recvWithEndMarker();
showNewData();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\r';
char rc;
// if (Serial.available() > 0) {
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
//Serial.print("This just in ... ");
String s = receivedChars;
s.remove(0, 0);
Serial.println(s);
newData = false;
}
}