Paso 5: El código
#define PIN_LED 5
bool g_PktFristFlag = false;
bool g_PktRecvFlag = false;
char g_LedState = false;
unsigned int g_RecvCount = 0;
char g_RecvBuff [80];
void setup() {}
Pon tu código de instalación, para ejecutar una vez:
pinMode (PIN_LED, salida);
digitalWrite (PIN_LED, bajo);
Serial.Begin(115200);
}
void loop() {}
Pon tu código principal, para ejecutar varias veces:
ledSet();
}
void serialEvent() {}
mientras (Serial.available()) {}
char a inChar = Serial.read();
Si (inChar == '\r') {}
g_PktFristFlag = true;
}
else if (inChar == '\n') {}
Si (g_PktFristFlag) {}
g_RecvBuff [g_RecvCount] = '\0';
g_PktRecvFlag = true;
}
}
Else {}
g_RecvBuff [g_RecvCount ++] = inChar;
}
}
}
void ledSet() {}
{if(g_PktRecvFlag)}
g_PktRecvFlag = false;
g_PktFristFlag = false;
ReadCommand();
g_RecvCount = 0;
}
}
void ReadCommand() {}
char * pString = (char *) & g_RecvBuff [0];
char * masterStr = "";
unsigned int masterNum;
Si (0 == strncmp (pString, "SET_LED", 7)) {}
g_LedState =! g_LedState;
Si (g_LedState) {}
digitalWrite (PIN_LED, alto);
}
Else {}
digitalWrite (PIN_LED, bajo);
}
}
}