Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - laksmanx

Pages: [1]
1
Arduino support / Re: Arduino Plugin
« on: June 21, 2015, 04:12:04 AM »
Hi James

Thank you for the advice on VC responding to inputs on the Arduino.

It all makes a great deal of sense now.

By triggering events with digital inputs on Arduino, one can literally do anything. I went from the idea of VC letting me know when the front door or garage door is opening, to a multimedia interface where i can play, pause and skip music from my entertainment area with buttons or voice.

Here is the code I used to trigger multiple inputs.

Code: [Select]
String data="";  //used to receive serial messages
const int buttonPin1 =2;
const int buttonPin2 =3;
const int buttonPin3 =4;
const int buttonPin4 =5;
bool flag_1 = 0;
bool flag_2 = 0;
bool flag_3 = 0;
bool flag_4 = 0;
bool buttonState_1 = 0;
bool buttonState_2 = 0;
bool buttonState_3 = 0;
bool buttonState_4 = 0;
void setup() {
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  Serial.begin(9600);
}

void loop() {
  delay(100);
  int oneButtonState = digitalRead(buttonPin1);
 
  if (oneButtonState != buttonState_1) {
    if(oneButtonState)
    {
       if(flag_1 == 0)
       {
       Serial.println("VC.TriggerEvent&&ButtonOne.Pressed");
       flag_1 = 1;
       }
    }
    else
    {
       if(flag_1 == 1)
          {
            Serial.println("VC.TriggerEvent&&ButtonOne.State.Released");
            flag_1 = 0;
          }
    }
    buttonState_1 = oneButtonState;
  }
  delay(100);
  int twoButtonState = digitalRead(buttonPin2);
  if (twoButtonState != buttonState_2) {
    if(twoButtonState)
    {
      if(flag_2 == 0)
        {
         Serial.println("VC.TriggerEvent&&ButtonTwo.Pressed");
         flag_2 = 1;
        }
    }
    else
    {
      if(flag_2 == 1)
        {
         Serial.println("VC.TriggerEvent&&ButtonTwo.Released");
         flag_2 = 0;
        } 
    }
    buttonState_2 = twoButtonState;
  }
 
  delay(100);
  int threeButtonState = digitalRead(buttonPin3);
  if (threeButtonState != buttonState_3) {
    if(threeButtonState)
    {
      if(flag_3 == 0)
        {
         Serial.println("VC.TriggerEvent&&ButtonThree.Pressed");
         flag_3 = 1;
        }
    }
    else
    {
      if(flag_3 == 1)
        {
         Serial.println("VC.TriggerEvent&&ButtonThree.Released");
         flag_3 = 0;
        } 
    }
    buttonState_3 = threeButtonState;
  }
delay(100);
  int fourButtonState = digitalRead(buttonPin4);
  if (fourButtonState != buttonState_4) {
    if(fourButtonState)
    {
      if(flag_4 == 0)
        {
         Serial.println("VC.TriggerEvent&&ButtonFour.Pressed");
         flag_4 = 1;
        }
    }
    else
    {
      if(flag_4 == 1)
        {
         Serial.println("VC.TriggerEvent&&ButtonFour.Released");
         flag_4 = 0;
        } 
    }
    buttonState_4 = fourButtonState;
  }
}

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="";
}










2
Arduino support / Re: Arduino Plugin
« on: June 16, 2015, 09:49:57 AM »
I am referring to reply #9 to #12 in the Arduino plugin post which is about two way coms between VC and Arduino.

I used the code and it works for both Arduino uno and VC.
VC is able to set outputs on Arduino high or low and I am able to ask VC what the pin status is of relevant pin.

What I would like to do is trigger an input on the Arduin uno and have VC respond with a phrase eg. the front door is open garage door opening.

I am not sure where to make the change , in Arduino code or python code or probably both.



3
Arduino support / Re: Arduino Plugin
« on: June 16, 2015, 08:18:26 AM »
Hi James.

I want VC to reply with speech if an input is triggered on the arduino.

I used the code provided in THIS FORUM and it works but I am unable to get VC to read an input from my Arduino when triggered.



Kind regards


Pages: [1]