Im trying to get my project to report some variables, but only when asked for them.
Im new with programming and not that bright with code so please help me..
I want to send a letter, say "v", and get ("voltage reading " (Value)) in return, witch i kinda get..
But when the arduino replies, it also triggers its own incomming commands, so that example would also trigger a few of my other triggers, repeatively if the trigger letter re-occurs..
i tried the Serial.flush command, but that seems to lock me out instead...
The code im running is MUCH more than merely the below included code snippet, but i figure the snippet should cover all essentials..
My code snippet:
// serial troubleshooting segment
Serial.flush();
if (Serial.available() > 0) { // checks if incomming serial
char input = Serial.read(); // saves serial input
if (input > 0x7F){
input = 0x00;
}
if ( input = 0x74){ // asci for "t", sets troubleshoot mode ON.
Serial.print("OK, Got: ");
Serial.println(input);
Serial.println("Turning ON Troubleshoot mode");
SerialTroubleshoot = 1;}
I've never seen the stuff I print get received by the Arduino that sent it. Either it's wired wrong (tx and rx shorted), or the computer is echoing it.
xarvox:
I want to send a letter, say "v", and get ("voltage reading " (Value)) in return, witch i kinda get..
But when the arduino replies, it also triggers its own incomming commands, so that example would also trigger a few of my other triggers, repeatively if the trigger letter re-occurs..
If the data from the Arduino is to cause other actions on the PC then you need a program on your PC that can do that.
Also look at Serial Input Basics for simple reliable ways to receive data. Make the PC program conform to one of the systems. The 3rd example would be the most reliable.
Serial.flush() is for outgoing Arduino data - it waits until all the outgoing data has been sent.