Now we are getting somewhere!
Yes you only need to adjust the Arduino Sketch. You do not need to modify the python code.
You only need to know a few fundamental things about Arduino to modify the code I posted. The code that I posted was supposed to be a starting point so that you could see how it works and then modify it to suit your needs. I suggest that you look over the Arduino sketch and the Python code and try to understand how it all fits together.
In order to add some extra functionality to your sketch for a button, you should first take a look at this example:
http://www.arduino.cc/en/Tutorial/ButtonThat sketch is using a button, and resistor, and Digital pin #2 to read the state of the button. You can add a button using the same wiring that they show. Then you need to borrow some of their code and adapt it a little bit to our existing sketch.
At the beginning of our sketch you need to define some constants and variables:
const int buttonPin = 2; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
in the setup() you need to let Arduino know that we will be using pin 2 as an input:
pinMode(buttonPin, INPUT);
and in the loop we need to look at the state of the button (newButtonState), compare it to the old state of the button (buttonState) to see if it changed. If it did change then we can fire an event in VC showing if the button is pressed or released. Finally we should store the new button state (newButtonState) in our variable (buttonState) so next time we can see if it changed or not.
// 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;
}
Then you can use the event to trigger any commands in VC that you like.
The updated Arduino sketch is attached.