Something more like a standard RC transmitter, where the sender sends data at close intervals, even of the data is the same as what was sent last time, might be a better idea.
Ok great ideia, i will try apply your advice.
Once again, I thought the protocol was <, letter, value, >...
Sorry, i try now with only letters for my buttons...it´s working, for joystick i use only the number but is not for now.
But now i have another problem:
See my code:
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[80];
byte index;
unsigned long time=0;
unsigned long time2=0;
unsigned long time3=0;
long timeout=20;
int led = 13;
const char turn_right_On[6]="EON";
const char turn_right_Off[6]="EOF";
cons tchar turn_lft_On[6]="DON";
const char turn_lft_Off[6]="DOF";
const char front_On[6]="FON";
const char front_Off[6]="FOF";
const char back_On[6]="RON";
const char back_Off[6]="ROF";
//----------------------------------------------------------
void setup()
{
Serial.begin(9600); // opens serial port
pinMode(led,OUTPUT);
}
//-----------------------------------------------------------
void loop()
{
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
time = millis();
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 79)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
if(started== true && ended==false)
{
time2 = millis();
time3=(time2-time);
if (time3>=timeout)
{
Serial.println("timeout");
goto reset;
}
}
if(started && ended)
{
Serial.println(inData);
if (inData==turn_lft_On){
led==HIGH;
}
if (inData==turn_lft_Off){
led==LOW;
}
reset:
started = false;
ended = false;
index = 0;
inData[index] = '\0';
time=0;
time2=0;
time3=0;
}
}
I try when i receive the turn_lft_On turn led on and turn_lft_Off turn led off but nothing appears with the led...
I receive in serial comunication corrects data (in the line Serial.println(inData); i see in serial monitor DON (stored in turn_lft_On turn).
I´m thinking about a problem in data type between turn_lft_On turn and inData...