#include int IncomingByte; int intCount = 0; int LED1 = 5; int LED2 = 6; char jsonRead[200] = ""; void setup(){ Serial.begin(14400); delay(5000); Serial.println("***COM IN***"); delay(3000); Serial.println("***COMOUT***"); } void loop() { StaticJsonBuffer<200> jsonBuffer; while ( Serial.available() > 0) { IncomingByte = Serial.read(); if (IncomingByte == 10) { for (int i = 0; i < 200; i ++) { jsonRead[i] = 0; } intCount = 0; } else if (IncomingByte == 13) { JsonObject& jsonRcv = jsonBuffer.parseObject(jsonRead); if (!jsonRcv.success()) { return; } else { } const char* jsonOut1 = jsonRcv["C1"]; const char* jsonOut2 = jsonRcv["C2"]; const char* jsonOut3 = jsonRcv["C3"]; const char* jsonOut4 = jsonRcv["C4"]; int ctrl10[4]; int ctrl1[4]; int ctrl[4]; ctrl10[0] = *(jsonOut1) - 64; ctrl10[1] = *(jsonOut2) - 64; ctrl10[2] = *(jsonOut3) - 64; ctrl10[3] = *(jsonOut4) - 64; ctrl1[0] = *(jsonOut1 + 1) - 64; ctrl1[1] = *(jsonOut2 + 1) - 64; ctrl1[2] = *(jsonOut3 + 1) - 64; ctrl1[3] = *(jsonOut4 + 1) - 64; int vol[4]; int vol10[4]; int vol1[4]; vol10[0] = *(jsonOut1 + 2) - 48; vol10[1] = *(jsonOut2 + 2) - 48; vol10[2] = *(jsonOut3 + 2) - 48; vol10[3] = *(jsonOut4 + 2) - 48; vol1[0] = *(jsonOut1 + 3) - 48; vol1[1] = *(jsonOut2 + 3) - 48; vol1[2] = *(jsonOut3 + 3) - 48; vol1[3] = *(jsonOut4 + 3) - 48; for (int i = 0; i < 4; i++) { vol[i] = vol10[i] * 10 + vol1[i]; ctrl[i] = ctrl10[i] * 10 + ctrl1[i]; Control(ctrl[i], vol[i]); } } else { int intTempchar; intTempchar = IncomingByte; if (intTempchar != 0){ jsonRead[intCount] = IncomingByte; intCount ++; } } } } void Control(int ctrl, int vol) { switch (ctrl) { case 11: analogWrite(LED1, vol * 2.5); break; case 22: analogWrite(LED2, vol * 2.5); break; default: analogWrite(LED1,120); break; } }