const int buttonPin = 2; // the number of the pushbutton pin int buttonState = 0; // variable for reading the pushbutton status String data=""; //used to receive serial messages void setup() { // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); Serial.begin(9600); } void loop() { // read the state of the pushbutton value: int newButtonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (newButtonState != buttonState) { //send event to VC showing the button changed if(newButtonState) { Serial.println("VC.TriggerEvent&&Button.Pressed"); } else { Serial.println("VC.TriggerEvent&&Button.State.Released"); } buttonState=newButtonState; } 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=""; }