blob: 3f9ae2404b346b47ad3116e86b8b43857223556e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
void setup()
{
Serial.begin(115200); //serial begin
}
void loop()
{
String readStr = ""; //some variables
String readVal = "";
double inVal, outVal;
if (Serial.available()){ //when serial data comes from modelica
while(Serial.available()){
char readChar = (char)Serial.read();
readStr+=readChar;
if(readChar == '\n') break;
} //read the data and store in a string
for (int i = 1; i < (readStr.length()-1); i++)
{
readVal += readStr[i];
}
inVal = readVal.toDouble(); //extract value
outVal = inVal/2;
Serial.print("1," + String(outVal) + "\n"); //send data in same format i.e. ending with \n character
delay(1);
}
}
|