Hi guys,
I am currently controlling a stepper motor with a potentiometer as part of a project and am expanding it to be able to control from a PC. I will be sending a value equivilent to the pot value (ie upto 1024) but cannot get the value to store properly, I can read each byte into its own variable and spit them out 1 by 1 but cant convert them to an int, ie if I send 743 I can store the 7, 4 and 3 seperatly but cant merge them into a int to pass 743 to the delay.
Here is another way of saying the same thing.
The ASCII codes for the digits 0 through 9 is 48 through 57. When the character '0' is received it actually has a value of 48. The character '1' has the value 49 etc. You can verify this if you add the following to your sketch:
Serial.print("I received: ");
Serial.print(SerialSpeed1, BYTE);
Serial.print(” this has an ASCII value of “);
Serial.print(SerialSpeed1,DEC);
So to convert from the character '0' (which has a value of 48) to its numeric value you need to subtract '0' which is the same as 48.
I am new to Arduino and have been experimenting a bit by making little sketches.
I made sketch which displays a number on a 7 segment display (single digit) received over serial.
I created a function with all the combinations of the numbers in it and call the function once Serial.available > 0.
By using Serial.print(x) I could see that 0 was printed as 48 etc.. but using (x,BYTE) displayed the inputted digit.
i tried using int(x) to convert to int as per reference material ut it did not work.
Now I need to expand this to be able to show a 3 digit no. on 3 x 7 segments using multiplexing! :-?
may not always work - you're testing to see if there is at least one character available, then reading three.
If the second and third characters haven't arrived yet, then "Serial.read" will return -1.