Cool video but gimme dat ole time religion! https://www.youtube.com/watch?v=cVYaEyaYvCo
See if you can get bottle rockets where you live.
And that I should put quotes around the 1024??
You would read "1024" as 4 separate characters. Each digit comes in s-l-o-w-l-y compared to Arduino speed
. You need to check that all the digits come in (perhaps at least 1) and that not too many digits come in (at most 4?) and that a separator byte follows the digits (maybe a comma or linefeed or space, you decide) and that nothing but digits and separator come in (because the world is not perfect, errors happen).
You can read the characters into a char array (C string please, not
C++ String!) and add a terminating zero then use atoi() to turn that into a number or.....
You can set an int to zero and as you get each digit (checking limits, etc as above) multiply the int x 10 then add the ASCII digit you read minus '0' (so '0' - '0' = 0 to '9' - '0' = 9).
How it works:
byte digit; // I will read serial bytes into this
int total = 0; // I will build the result in this
// I read '1' from serial into digit
total *= 10; // multiplies total * 10 and stores that into total, first time is 0 x 10 = 0
total += digit - '0'; // total now = 1
// I loop around, checking for digits and not over-length and with the rest, "024" total becomes;
// 1 x 10 + '0' - '0' = 10 + 0 = 10
// 10 x 10 + '2' - '0' = 100 + 2 = 102
// 102 x 10 + '4' - '0' = 1020 + 4 = 1024
If I read the separator after 1 or more digits I leave the loop and my result is in total.
If anything is wrong, I leave the loop with a variable set indicating error and result is bad.
Is that enough for you to code with? You can go either way.
For me, code is like the old puzzle games we had before hand calculators and PC's were around.
It can be a lot of fun and challenge, but once you add deadlines the fun and games are over.