I have the following code that calls a function when a<3. What i want to do and i can't find the solution is to call this function when receiving a string value from c#.
How is C# communicating with the Arduino? By writing to the Arduino’s serial port ?
If so, your loop has to check if there is anything in the serial buffer an if so call the required function. Look at Serial.available() and Serial.read().
Start by saying how the C# is communicating with the Arduino and what data it is transferring (if any).
Post your C# code. I am anyway curious to see it.
The way you have structured your C++ code at the moment, tempvalue() will be called on every loop() iteration because the condition a<3 will always be true as the value of a is always 2.
I will post the code in a while. As concerning the a value i was changing it to test it that is why it looks like that. I will be removed anyway because i want to cal that function only if it gets a string value from c# rather than that if loop with the a variable.
I am waiting for the c# code from a friend of mine because we are working on a group project. Once we run it I will update the post. Thanks for the help!
May I suggest that you don't use single character variable names. It is impossible to do a search to find all the instances because every similar character will be included.
Long meaningful variable and function names generally make a program much easier to understand and less likely to have silly mistakes.
AntonisPlb:
This is my updated code. I am printing the Tc at the showNewData function when there is connection between c# and arduino.
If there is anything that need to be improved or changed please let me know
As written there is, of course, no test for what has been received nor any method of knowing that the message received is complete and the showNewData() function will be called for every new character
AntonisPlb:
This is my updated code. I am printing the Tc at the showNewData function when there is connection between c# and arduino.
Your system will be much more reliable if you use start- and end-markers for your messages so that the Arduino can be sure it has received the full message.
I had the impression from your Original Post that you want to receive a message containing several characters so I don't understand why you have chosen the recvOneChar() function.