EasyVR-Arduino

Hello, I need help with this code of an EasyVR program, something is wrong but i dont know what is really my problem, This is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
  #if defined(ARDUINO)&&ARDUINO>= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
SoftwareSerial port(12,13);
#else // Arduino 0022 – use modified NewSoftSerial
#include "WProgram.h"
#include "NewSoftSerial.h"
#NewSoftSerial port(12,13);
#endif
#include "EasyVR"
#include "EasyVR.h"
#EasyVR easyvr(port);
#include "EasyVRdetect"
//Groups and Commands
enum Groups
{
GROUP_0 = 0,
GROUP_1 = 1,
};
enum Group0
{
G0_ARDUINO = 0,
};
enum Group1
{
G1_LED_AN = 0,
G1_LED_AUS = 1,
};
EasyVRBridge bridge;
int8_t group, idx;
void setup()
{
// bridge mode?
if (bridge.check())
{
cli();
bridge.loop(0, 1, 12, 13);
}
// run normally
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(3);
group = EasyVR::TRIGGER; //<– start group (customize)
pinMode(11, OUTPUT);
digitalWrite(11, LOW); // set the LED off
}
void action();
void loop()
{
easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
Serial.print("Say a command in Group");
Serial.println(group);
easyvr.recognizeCommand(group);
do
{
// can do some processing while waiting for a spoken command
}
while (!easyvr.hasFinished());
easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off
idx = easyvr.getWord();
if (idx>= 0)
{
// built-in trigger (ROBOT)
// group = GROUP_X; <– jump to another group X
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 (idx>= 0)
{
Serial.print("Error");
Serial.println(err, HEX);
}
group = GROUP_0;
}
}
void action()
{
switch (group)
{
case GROUP_0:
switch (idx)
{
case G0_ARDUINO:
// write your action code here
group = GROUP_1; //<– or jump to another group X for composite commands
break;
}
break;
case GROUP_1:
switch (idx)
{
case G1_LED_AN:
// write your action code here
group = GROUP_0; //<– or jump to another group X for composite commands
digitalWrite(11, HIGH); // set the LED on
break;
case G1_LED_AUS:
// write your action code here
group = GROUP_0; //<– or jump to another group X for composite commands
digitalWrite(11, LOW); // set the LED off
break;
}
break;
}
}
Last edited on
Topic archived. No new replies allowed.