From 162261e54ff83b591fef394a8f606b394d3057fa Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Wed, 20 May 2020 19:54:05 +0200 Subject: [PATCH] Receiving serial data / commands is working --- arduino-mixer.ino | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/arduino-mixer.ino b/arduino-mixer.ino index 729fabe..9360aff 100644 --- a/arduino-mixer.ino +++ b/arduino-mixer.ino @@ -152,7 +152,6 @@ void drawName(String name) { } // Check for button input -// TODO: Add rotary encoder support void checkInput(unsigned long time) { long newPosition = encoder.read(); if (newPosition != position) { @@ -200,7 +199,8 @@ char receivedChars[numChars]; char tempChars[numChars]; char command[numChars] = {0}; -int data = 0; +char data[numChars] = {0}; +int intData = 0; boolean newData = false; @@ -211,15 +211,20 @@ void processData() { strcpy(tempChars, receivedChars); + char * strtokIndx; - - char * strtokIndx; // this is used by strtok() as an index - - strtokIndx = strtok(tempChars,","); // get the first part - the string - strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC + strtokIndx = strtok(tempChars,","); + strcpy(command, strtokIndx); + Serial.print("Command: "); + Serial.println(command); - strtokIndx = strtok(NULL, ","); // this continues where the previous call left off - integerFromPC = atoi(strtokIndx); // convert this part to an integer + strtokIndx = strtok(NULL, ","); + if (atoi(strtokIndx) > 0) // Integer data + { + intData = atoi(strtokIndx); + } else { // String data + strcpy(data, strtokIndx); + } newData = false; } @@ -255,6 +260,8 @@ void checkSerial() { recvInProgress = true; } } + + processData(); } // Init arduino