String data=""; //used to receive serial messages void setup() { Serial.begin(9600); } void loop() { delay(100); } void serialEvent() { data=""; while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the data: if (inChar == (char)10) { break; //break message on newline } data += inChar; } //data should be ready now. What should we do with it? if (data=="hello") { Serial.println("tts.speak&&hi there"); } //Analog Read - Pin # else if (data.startsWith("ar.")) { String strPin = data.substring(3); int whatPin = atoi(strPin.c_str()); int v = analogRead (whatPin); Serial.println("VC.TriggerEvent&&Analog.Pin&&"+strPin+"&&"+v); } //DigitalWrite HIGH - Pin # else if (data.startsWith("dw.high.")) { String strPin = data.substring(8); int whatPin = atoi(strPin.c_str()); pinMode(whatPin, OUTPUT); digitalWrite (whatPin,HIGH); } //DigitalWrite LOW - Pin # else if (data.startsWith("dw.low.")) { String strPin = data.substring(7); int whatPin = atoi(strPin.c_str()); pinMode(whatPin, OUTPUT); digitalWrite (whatPin,LOW); } //unknown command else { Serial.println("VC.TriggerEvent&&Arduino.error&&"+data); } //clear data for next time data=""; }