Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <Stream.h>
  2.  
  3. #define BUFSIZE 3 // Tamanho do buffer
  4. #define MAXCMDSIZE 96 // Tamanho maximo do comando
  5.  
  6. // Pega os comandos vindo do software
  7. void GetCommand();
  8.  
  9. char _bufLen = 0; // Tamanho do buffer armazenado
  10. char _cmdCount[sizeof(MAXCMDSIZE)]; // Conta o tamanho do comando
  11. char _cmdBuffer[BUFSIZE][MAXCMDSIZE];
  12.  
  13. void setup() {
  14. _cmdCount[0] = 0; //Inicializa
  15. _cmdCount[1] = 0;
  16. //Inicia a comunicação serial
  17. Serial.begin(115200);
  18. }
  19.  
  20. void loop() {
  21. if (_bufLen < (BUFSIZE - 1))
  22. GetCommand();
  23. }
  24.  
  25. void GetCommand() {
  26. char serialChar; //Caractere da porta serial
  27. while (Serial.available() > 0 && _bufLen < BUFSIZE) {
  28.  
  29. // Read the incoming data:
  30. serialChar = Serial.read();
  31. if (serialChar != 'n' && serialChar != 'r') {
  32. _cmdBuffer[_bufLen][(int)_cmdCount] = serialChar;
  33.  
  34. // Say what you got:
  35. Serial.print("I received: ");
  36. Serial.println(_cmdBuffer[_bufLen]);
  37. /** ------Problem---------*/
  38. _cmdCount = (char[2])(1 + atoi(_cmdCount));
  39. }
  40. }
  41. }
  42.  
  43. _cmdCount = (char[2])(1 + atoi(_cmdCount));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement