I want to ideally send a few bytes of serial data from a computer to an Arduino. There has to be a better way than what I have chosen to do but my experience with serial data sent byte by byte and c++ is limited. I want to append each byte to definable variable values that are multiple bytes long. for example if the first 3 bytes of a serial stream are '3', '5', and '7' I want that to read as a single int of value 357. I am using Serial.readBytesUntil.
I have tried using Serial.readStringUntil() but I was having the same problem but converting string type to an integer. I feel like there is an easier way than what I am doing.
size_t input = Serial.readBytesUntil('\r', sentdata, sizeof(sentdata)-1);
dist[0] = sentdata[0];
dist[1] = sentdata[1];
dist[2] = sentdata[2];
dist[3] = sentdata[3];
distance = dist[0]*1000 + dist[1]*100 + dist[2]*10 + dist[3];
distance should equal any number sent from 0000 to 9999. just as an fyi this value is related to steps performed by a stepper motor.