0% found this document useful (0 votes)
1 views2 pages

Pluscode

The document contains an Arduino sketch that reads two floating-point numbers from the serial input. It processes the input by separating the numbers based on a space character and converts them from strings to floats. Finally, it prints the individual numbers and their sum to the serial output.

Uploaded by

a2228997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Pluscode

The document contains an Arduino sketch that reads two floating-point numbers from the serial input. It processes the input by separating the numbers based on a space character and converts them from strings to floats. Finally, it prints the individual numbers and their sum to the serial output.

Uploaded by

a2228997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <isostream>

int m=0;
char str1[20] = " ";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}

void loop() {
// put your main code here, to run repeatedly:
float data1 = 0;
float data2 = 0;
m = 0;
float n;
if (Serial.available()) {
str1[20] = Serial.readString();
for(int i = 0;i <= 20;i++){
if(str1[i] == " "){
m = 1;
}
else if(m == 0){
if(str1[i] == "0"){
data1 = data1*10;
}
else if(str1[i] == "1"){
data1 = data1*10 + 1;
}
else if(str1[i] == "2"){
data1 = data1*10 + 2;
}
else if(str1[i] == "3"){
data1 = data1*10 + 3;
}
else if(str1[i] == "4"){
data1 = data1*10 + 4;
}
else if(str1[i] == "5"){
data1 = data1*10 + 5;
}
else if(str1[i] == "6"){
data1 = data1*10 + 6;
}
else if(str1[i] == "7"){
data1 = data1*10 + 7;
}
else if(str1[i] == "8"){
data1 = data1*10 + 8;
}
else if(str1[i] == "9"){
data1 = data1*10 + 9;
}
}
else if(m == 1){
if(str1[i] == "0"){
data2 = data2*10;
}
else if(str1[i] == "1"){
data2 = data2*10 + 1;
}
else if(str1[i] == "2"){
data2 = data2*10 + 2;
}
else if(str1[i] == "3"){
data2 = data2*10 + 3;
}
else if(str1[i] == "4"){
data2 = data2*10 + 4;
}
else if(str1[i] == "5"){
data2 = data2*10 + 5;
}
else if(str1[i] == "6"){
data2 = data2*10 + 6;
}
else if(str1[i] == "7"){
data2 = data2*10 + 7;
}
else if(str1[i] == "8"){
data2 = data2*10 + 8;
}
else if(str1[i] == "9"){
data2 = data2*10 + 9;
}
}
}
Serial.printf(" %f\n",data1);
Serial.printf(" %f\n",data2);
Serial.printf(" %f\n",data1 + data2);
}
}

You might also like