Add value to recieving data

Hello Community.

I seek your help to add the value "20" to every measure coming from a wireless ultrasonic sensor.

This might be a noob question, but I am having a lot of trouble getting it right, so all help is appreciated!

#include <SoftwareSerial.h>
#include <U8glib.h>

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data
boolean newData = false;
long distance1;

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI

SoftwareSerial HC12(5, 4); // HC-12 TX Pin, HC-12 RX Pin


void setup()
{
  Serial.begin(19200);             // Serial port to computer
  HC12.begin(19200);               // Serial port to HC12
  u8g.begin();
}

void loop() {
    recvWithEndMarker();
    showNewData();
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;
   
    while (HC12.available() > 0 && newData == false) {
        rc = HC12.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.println(receivedChars);  
    u8g.firstPage();
    do
     {
  u8g.setFont(u8g_font_fur30);
  u8g.setPrintPos(0, 63);
  u8g.print(receivedChars);
  u8g.print("cm");
  newData = false;
     }
     while (u8g.nextPage());
}

}

When you say add "20" do you mean if you get a string like "1234" you want to turn it into "1254" or something else ? Do you want the result as a string or as an integer ?

lass5216:
I seek your help to add the value "20" to every measure coming from a wireless ultrasonic sensor.

Please provide some examples of the actual data that is received.

If you need to convert the incoming text to a number then have a look at the parse example in Serial Input Basics

...R

Hello UkheliBob,

I am sending data from an ultrasonic sensor going into a HC12 433 radio transmitter.

In the receiving end, I have an OLED display and a receiving HC12.

I want the distance data shown on the OLED display to have the value 20 added.

So if the display is receiving 120cm, I want it to show 140cm.

I have tried and succeeded with adding the value in the transmitter part of the setup, but that reduces my close range of the sensor. So it has to be on the receiving end the change is made.

Thank you!

All the best, Lasse.

use atoi on your received chars to get an int. Add twenty to it and then print that.