I am trying to be able to send data to the serial monitor like this for example : 135,210
And have the Serial monitor send it back to me.
How come this code wont work?
int cnt = 0;
void setup() {
Serial.begin(9600);
}
int integerValue=0;
char storedData[2];
// Max value is 65535
char incomingByte;
void loop() {
if (Serial.available() > 0) { // something came across serial
integerValue = 0; // throw away previous integerValue
while(1) { // force into a loop until 'n' is received
incomingByte = Serial.read();
if (incomingByte == '\n') break;
if (incomingByte == ','){
cnt++;
break;
} // exit the while(1), we're done receiving
if (incomingByte == -1) continue; // if no characters are in the buffer read() returns -1
integerValue *= 10; // shift left 1 decimal place
// convert ASCII to integer, add, and shift left 1 decimal place
integerValue = ((incomingByte - 48) + integerValue);
}
storedData[cnt] = integerValue;
for (int i=0; i<2; i++){
Serial.println(storedData*);*
I am trying to be able to send data to the serial monitor like this for example : 135,210
And have the Serial monitor send it back to me.
How come this code wont work?
The serial monitor is not designed to receive data from a sender and then echo back to the sender what was received. Do you actually want to send something to the arduino from the serial monitor and have the arduino send it back to the serial monitor?