Pages: [1]   Go Down
Author Topic: Easyvr - Domotics - Help  (Read 843 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This program will turn on or off lights and open or close blind.
I want to say a command "Entrada" e goes to group 1 if the name, saved in this group was right goes to group 16 (pwd), otherwise the program counts three attemps and blink a red led and plays buzzer for 5 secs. If program goes to group 16, that means that the name said was correct, and evething was right, the program plays a sound in sound table and goes to group 0, otherwise the program do the same procedure when the name is wrong. What I really want to do is put a If inside a Switch case, is that possible? If anyone could help me out I would appreciate it.

Code:

#include <EasyVR.h>

#define SND_SON_FINAL_1            1
#define SND_SON_FINAL_2            2
#define SND_SON_FINAL_3            3
#define SND_SON_FINAL_4            4
#define SND_SON_FINAL_5            5
#define SND_SON_FINAL_6            6
#define SND_SON_FINAL_7            7
#define SND_SON_FINAL_8            8
#define SND_SON_FINAL_9            9

EasyVR easyvr(port);

enum Groups
{
  GROUP_0  = 0,
  GROUP_1  = 1,
  GROUP_2  = 2,
  GROUP_3  = 3,
  GROUP_4  = 4,
  GROUP_5  = 5,
  GROUP_6  = 6,
  GROUP_7  = 7,
  GROUP_8  = 8,
  GROUP_16 = 16,
  Entrada = 17
};

enum Group0
{
  G0_CASA = 0,
};

enum Group1
{
  G1_LUIZ_MOURA = 0,
};

enum Group2
{
  G2_ILUMINACAO = 0,
  G2_PERSIANA = 1,
  G2_CANCELA_COMANDO = 2,
  G2_ATALHO_OFF = 3,
  G2_SAINDO = 4,
  G2_ENTRADA = 5,
};

enum Group3
{
  G3_ESTAR = 0,
  G3_SALA = 1,
  G3_QUARTO = 2,
};

enum Group4
{
  G4_LIGA = 0,
  G4_DESLIGA = 1,
  G4_CANCELA_LUZ = 2,
};

enum Group5
{
  G5_ABRE_PERSIANA = 0,
  G5_FECHA_PERSIANA = 1,
  G5_CANCELAR_PERSIANA = 2,
};

enum Group6
{
  G6_LIGA = 0,
  G6_DESLIGA = 1,
  G6_CANCELAR_LUZ = 2,
};

enum Group7
{
  G7_LIGA = 0,
  G7_DESLIGA = 1,
  G7_CANCELAR_LUZ = 2,
};

enum Group8
{
  G8_DESLIGA_ESTAR = 0,
  G8_DESLIGA_QUARTO = 1,
  G8_DESLIGA_SALA = 2,
  G8_DESLIGA_TUDO = 3,
};

enum Entrada
{
  Wake_on_char = 0,
};

enum Group16
{
  G16_PWR_LUIZ = 0,
};

EasyVRBridge bridge;

int8_t group, idx;

int E2 = 6;                      
int M2 = 7;
const int LDR = 14;
int ValorLido = 0;
int ValorLido2 = 0;
const int led = 5;

void setup()
{
  if (bridge.check())
  {
    cli();
    bridge.loop(0, 1, 12, 13);
  }
   Serial.begin(9600);
  port.begin(9600);

  if (!easyvr.detect())
  {
    Serial.println("EasyVR not detected!");
    for (;;);
  }

  easyvr.setPinOutput(EasyVR::IO1, LOW);
  Serial.println("EasyVR detected!");
  easyvr.setTimeout(5);
  easyvr.setLanguage(0);
  
  pinMode(8, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(M2, OUTPUT);
  pinMode(led, OUTPUT);
  
}

void action();

void loop()
{
 int idx_nome;
 int idx_pwd;
 char wake[32];
 int nome_nc;
 int count=0;
 
  easyvr.setPinOutput(EasyVR::IO1, HIGH);

  Serial.print("Diga um comando do grupo ");
  Serial.println(group);
  easyvr.recognizeCommand(group);

   do
  {
  ValorLido = analogRead(LDR);  
  if (ValorLido < 5){
   digitalWrite(led, HIGH);  
  }          
  else{
   digitalWrite(led, LOW);
  }
  }
  
  while (!easyvr.hasFinished());
  
  easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

  idx = easyvr.getWord();
  if (idx >= 0)
  {
return;
  }
  idx = easyvr.getCommand();
  if (idx >= 0)
  {
    // print debug message
    uint8_t train = 0;
    char name[32];
    Serial.print("Command: ");
    Serial.print(idx);
    if (easyvr.dumpCommand(group, idx, name, train))
    {
      Serial.print(" = ");
      Serial.println(name);
    }
    else
      Serial.println();
    easyvr.playSound(0, EasyVR::VOL_FULL);
    // perform some action
    action();
  }
  else // errors or timeout
  {
    if (easyvr.isTimeout())
      Serial.println("Timed out, try again...");
    int16_t err = easyvr.getError();
    if (err >= 0)
    {
      Serial.print("Error ");
      Serial.println(err, HEX);
      easyvr.playSound(8, EasyVR::VOL_FULL);
    }
  }
}

void action()
{
     switch (group)

    {
    case GROUP_0:
      switch (idx)
      {
      case G0_CASA:
        easyvr.playSound(4, EasyVR::VOL_FULL);
        group = (2);
        break;
      }
      break;
    case GROUP_1:
      switch (idx)
      {
      case G1_LUIZ_MOURA:
        easyvr.playSound(9, EasyVR::VOL_FULL);
        group = (16);
        break;
      }
      break;
    case GROUP_2:
      switch (idx)
      {
      case G2_ILUMINACAO:
        easyvr.playSound(5, EasyVR::VOL_FULL);
        group = (3);
        break;
      case G2_PERSIANA:
        easyvr.playSound(7, EasyVR::VOL_FULL);
        group = (5);
        break;
      case G2_CANCELA_COMANDO:
        easyvr.playSound(3, EasyVR::VOL_FULL);
        easyvr.setPinOutput(EasyVR::IO1, LOW);
        group = (0);
        break;
        case G2_ATALHO_OFF:
        easyvr.playSound(7, EasyVR::VOL_FULL);
        group = (8);
        break;
      case G2_SAINDO:
        easyvr.playSound(7, EasyVR::VOL_FULL);
        easyvr.setPinOutput(EasyVR::IO1, LOW);
        easyvr.sleep(0);
        break;
        case G2_ENTRADA:
        easyvr.playSound(6, EasyVR::VOL_FULL);
        group = (1);
        break;
      }
      break;
    case GROUP_3:
      switch (idx)
      {
      case G3_ESTAR:
        easyvr.playSound(7, EasyVR::VOL_FULL);
        group = (4);
        break;
      case G3_SALA:
        easyvr.playSound(7, EasyVR::VOL_FULL);
        group = (6);
        break;
      case G3_QUARTO:
        easyvr.playSound(7, EasyVR::VOL_FULL);
        group = (7);
        break;
      }
      break;
    case GROUP_4:
      switch (idx)
      {
      case G4_LIGA:
        digitalWrite(8, HIGH);
        break;
      case G4_DESLIGA:
        digitalWrite(8, LOW);
        break;
      case G4_CANCELA_LUZ:
        easyvr.playSound(3, EasyVR::VOL_FULL);
        easyvr.setPinOutput(EasyVR::IO1, LOW);
        group = (0);
        break;
      }
      break;
    case GROUP_5:
      switch (idx)
      {
      case G5_ABRE_PERSIANA:
      digitalWrite(M2,HIGH);  
      digitalWrite(E2,HIGH);      
      delay(2200);
      digitalWrite(M2,LOW);  
      digitalWrite(E2,LOW);
      break;
      case G5_FECHA_PERSIANA:
      digitalWrite(M2,LOW);  
      digitalWrite(E2,HIGH);
      delay(1600);
      digitalWrite(M2,LOW);  
      digitalWrite(E2,LOW);
      break;
      case G5_CANCELAR_PERSIANA:
      easyvr.playSound(3, EasyVR::VOL_FULL);
      easyvr.setPinOutput(EasyVR::IO1, LOW);
      group = (0);
      break;
      }
      break;
      case GROUP_6:
      switch (idx)
      {
      case G6_LIGA:
        digitalWrite(3, HIGH);
        break;
      case G6_DESLIGA:
        digitalWrite(3, LOW);
        break;
      case G6_CANCELAR_LUZ:
        easyvr.playSound(3, EasyVR::VOL_FULL);
        easyvr.setPinOutput(EasyVR::IO1, LOW);
        group = (0);
        break;
      }
      break;
    case GROUP_7:
      switch (idx)
      {
      case G7_LIGA:
        digitalWrite(4, HIGH);
        break;
      case G7_DESLIGA:
        digitalWrite(4, LOW);
        break;
      case G7_CANCELAR_LUZ:
        easyvr.playSound(3, EasyVR::VOL_FULL);
        easyvr.setPinOutput(EasyVR::IO1, LOW);
        group = (0);
        break;
      }
      break;
    case GROUP_8:
      switch (idx)
      {
      case G8_DESLIGA_ESTAR:
        digitalWrite(8, LOW);
        easyvr.playSound(3, EasyVR::VOL_FULL);
        easyvr.setPinOutput(EasyVR::IO1, LOW);
        group = (0);
        break;
      case G8_DESLIGA_QUARTO:
        digitalWrite(4, LOW);
        easyvr.playSound(3, EasyVR::VOL_FULL);
        easyvr.setPinOutput(EasyVR::IO1, LOW);
        group = (0);
        break;
      case G8_DESLIGA_SALA:
        digitalWrite(3, LOW);
        easyvr.playSound(3, EasyVR::VOL_FULL);
        easyvr.setPinOutput(EasyVR::IO1, LOW);
        group = (0);
        break;
      case G8_DESLIGA_TUDO:
        digitalWrite(8, LOW);
        digitalWrite(3, LOW);
        digitalWrite(4, LOW);
        digitalWrite(5, LOW);
        digitalWrite(M2,LOW);  
        digitalWrite(E2,HIGH);
        delay(1500);
        digitalWrite(M2,LOW);  
        digitalWrite(E2,LOW);        
        easyvr.playSound(3, EasyVR::VOL_FULL);
        easyvr.setPinOutput(EasyVR::IO1, LOW);
        group = (0);
        break;
      }
      break;
    case GROUP_16:
      switch (idx)
      {
      case G16_PWR_LUIZ:
      {
      int16_t err1 = easyvr.getError();
      if (err1 >= 11)
    {
      easyvr.playSound(1, EasyVR::VOL_FULL);
      digitalWrite(10, HIGH);
      delay(500);
      digitalWrite(10, LOW);
      delay(500);
      digitalWrite(10, HIGH);
      delay(500);
      digitalWrite(9, LOW);
      delay(500);
      digitalWrite(10, HIGH);
      delay(500);
      digitalWrite(9, LOW);
      }
       else{
        easyvr.playSound(2, EasyVR::VOL_FULL);
        digitalWrite(9, HIGH);
        delay(5000);
        digitalWrite(9, LOW);
        group = (0);
       }
      }
        break;
      }
      break;
    }
    
}
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From your code, when you say something in group 0, it goes to group 16. 

I don't think I understood your question correctly, but are you asking that when you are in group 16 and they say the word in group 16 that you want it to go back to group 0?
Logged

//LiNK

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for helping me.

This program besides turn on or turn off the light, it also control access home

In my code, after the trigger when I say "Entrada" (a word registred in group 2, that means I want to enter in the house) it goes for group 1, and when I said a word (User name) registred in group 1, it goes for group 16, if I said some word that is not registred in group 1, it should generate an error, and blink a red led and play a buzzer after three attemps. But if everything is ok, it goes for group 16.
In group 16 If I said the correct passaword for this User Name (registred in group 1), it plays a sound recorded in sound table that means that the user have the garanteed access to home and the system goes back to group 0, waiting for the trigger. If the password was wrong it shoud generate an error and blink a red led a play a buzzer after three atemps, the same procedure if the user name was not registred. I am trying to do the same as Control Access Home in the Veear web site.

Link: http://www.veear.eu/downloads/

Can you help me?
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now I know what you want it to do, what is it doing wrong?

I see your polling the error if you say something wrong, but your not printing it anywhere.  For the LEDs and buzzer, you do just like in the other groups.  You can write them HIGH or LOW depending on what you want. 

What are the numbers for?

Code:
  pinMode(8, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(M2, OUTPUT);
  pinMode(led, OUTPUT);

If you gave them meaningful names, it might help you and the people that are trying to help.
Logged

//LiNK

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think the program is not generate the error. I think that the if inside de Case G16_PWD_LUIZ is not working.

Follow:

Code:

case G16_PWR_LUIZ:
      {
      int16_t err1 = easyvr.getError();
      if (err1 >= 11)
    {
      easyvr.playSound(1, EasyVR::VOL_FULL);
      digitalWrite(10, HIGH);
      delay(500);
      digitalWrite(10, LOW);
      delay(500);
      digitalWrite(10, HIGH);
      delay(500);
      digitalWrite(10, LOW);
      delay(500);
      digitalWrite(10, HIGH);
      delay(500);
      digitalWrite(10, LOW);
      }
       else{
        easyvr.playSound(2, EasyVR::VOL_FULL);
        digitalWrite(9, HIGH);
        delay(5000);
        digitalWrite(9, LOW);// write your action code here
        group = (0);
       }// group = GROUP_X; <-- or jump to another group X for composite commands
      }
        break;
      }
      break;
    }


Here we go, the pins are: 8 - Living Room, 3 - Hall, 4 - Room, 9 - Red Led installed in the driveway, 10 - Green Led installed in the driveway, M2 - blind motor and led, another led controled by light sensor.

I did not gave the meaningful names, because the forum post limits on the maximum number of 9500 characters, and my first post of 9500 had passed characters.

If I need to put more information please let me know.
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am guessing when this error:
Code:
      int16_t err1 = easyvr.getError();
      if (err1 >= 11)

occurs, you want to:

Code:
      easyvr.playSound(1, EasyVR::VOL_FULL);
      digitalWrite(10, HIGH);
      delay(500);
      digitalWrite(10, LOW);
      delay(500);
      digitalWrite(10, HIGH);
      delay(500);
      digitalWrite(10, LOW);
      delay(500);
      digitalWrite(10, HIGH);
      delay(500);
      digitalWrite(10, LOW);
      }

If these Writes are not working than the error of "greater than or equal to 11" is not happening. 

In the manual error "11h" is the error produced from "Recognition Failed."  I honestly don't know how to write this into proper C++, but try something like this:

Code:
      int16_t err1 = easyvr.getError();
      if (err1 == 11h)

If it doesn't work, than maybe someone could chime in and tell us how to write a hex style C++ code for that.
Logged

//LiNK

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 654
Posts: 50958
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I honestly don't know how to write this into proper C++
Well, one could always Serial.print() the value to see what it is.
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I honestly don't know how to write this into proper C++
Well, one could always Serial.print() the value to see what it is.

lol, very true..
Logged

//LiNK

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I put a 11h, but it get a compile error. If anyone could help me I really, really appreciate it.
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int16_t err1 = easyvr.getError();
 Serial.println(err1);
 Serial.println("");

When you say a word that it doesn't recognize, it should print it to the serial monitor what the error is.
Logged

//LiNK

Pages: [1]   Go Up
Jump to: