Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Stream.h>
- #define BUFSIZE 3 // Tamanho do buffer
- #define MAXCMDSIZE 96 // Tamanho maximo do comando
- // Pega os comandos vindo do software
- void GetCommand();
- char _bufLen = 0; // Tamanho do buffer armazenado
- char _cmdCount[sizeof(MAXCMDSIZE)]; // Conta o tamanho do comando
- char _cmdBuffer[BUFSIZE][MAXCMDSIZE];
- void setup() {
- _cmdCount[0] = 0; //Inicializa
- _cmdCount[1] = 0;
- //Inicia a comunicação serial
- Serial.begin(115200);
- }
- void loop() {
- if (_bufLen < (BUFSIZE - 1))
- GetCommand();
- }
- void GetCommand() {
- char serialChar; //Caractere da porta serial
- while (Serial.available() > 0 && _bufLen < BUFSIZE) {
- // Read the incoming data:
- serialChar = Serial.read();
- if (serialChar != 'n' && serialChar != 'r') {
- _cmdBuffer[_bufLen][(int)_cmdCount] = serialChar;
- // Say what you got:
- Serial.print("I received: ");
- Serial.println(_cmdBuffer[_bufLen]);
- /** ------Problem---------*/
- _cmdCount = (char[2])(1 + atoi(_cmdCount));
- }
- }
- }
- _cmdCount = (char[2])(1 + atoi(_cmdCount));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement