Hi all. i have created a mini project whereby i can control the lights of the leds and fans to turn on and off with my voice command. But the problem now is, now that i have train all my commands, when i say them after putting the pin to SW mode, the board does not read me. Can anyone explain why?
#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.h"
EasyVR easyvr(port);
//Groups and Commands
enum Groups
{
GROUP_0 = 0,
GROUP_1 = 1,
};
enum Group0
{
G0_CLOVER = 0,
};
enum Group1
{
G1_RED_ON = 0,
G1_GREEN_ON = 1,
G1_YELLOW_ON = 2,
G1_RED_OFF = 3,
G1_GREEN_OFF = 4,
G1_YELLOW_OFF = 5,
G1_RED_BLINK = 6,
G1_GREEN_BLINK = 7,
G1_YELLOW_BLINK = 8,
G1_FAN_ON = 9,
G1_FAN_OFF = 10,
G1_SHUT_DOWN = 11,
G1_ON_ALL = 12,
};
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(0);
group = EasyVR::TRIGGER; //<-- start group (customize)
pinMode(8, OUTPUT);
digitalWrite(8, LOW); // set the LED off
pinMode(9, OUTPUT);
digitalWrite(9, LOW); // set the LED off
pinMode(10, OUTPUT);
digitalWrite(10, LOW); // set the LED off
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 (err >= 0)
{
Serial.print("Error ");
Serial.println(err, HEX);
}
group = GROUP_0;
}
}
void action()
{
switch (group)
{
case GROUP_0:
switch (idx)
{
case G0_CLOVER:
// 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_RED_ON:
// write your action code here
group = GROUP_0; //<-- or jump to another group X for composite commands
digitalWrite(9, HIGH); // set the LED on
break;
case G1_GREEN_ON:
// write your action code here
group = GROUP_0; //<-- or jump to another group X for composite commands
digitalWrite(10, HIGH); // set the LED on
break;
case G1_YELLOW_ON:
// 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_RED_OFF:
// write your action code here
group = GROUP_0; //<-- or jump to another group X for composite commands
digitalWrite(9, LOW); // set the LED on
break;
case G1_GREEN_OFF:
// write your action code here
group = GROUP_0; //<-- or jump to another group X for composite commands
digitalWrite(10, LOW); // set the LED on
break;
case G1_YELLOW_OFF:
// write your action code here
group = GROUP_0; //<-- or jump to another group X for composite commands
digitalWrite(11, LOW); // set the LED on
break;
case G1_RED_BLINK:
// write your action code here
group = GROUP_0; //<-- or jump to another group X for composite commands
digitalWrite(9, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(9, HIGH); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
break;
case G1_GREEN_BLINK:
// write your action code here
digitalWrite(10, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(10, HIGH); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
group = GROUP_0; //<-- or jump to another group X for composite commands
break;
case G1_YELLOW_BLINK:
// write your action code here
digitalWrite(11, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(11, HIGH); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second// write your action code here
group = GROUP_0; // <-- or jump to another group X for composite commands
break;
case G1_FAN_ON:
// write your action code here
group = GROUP_0;// <-- or jump to another group X for composite commands
digitalWrite(8, HIGH); // turn the LED off by making the voltage LOW
break;
case G1_FAN_OFF:
// write your action code here
group = GROUP_0;// <-- or jump to another group X for composite commands
digitalWrite(8, LOW); // turn the LED on (HIGH is the voltage level)
break;
case G1_SHUT_DOWN:
// write your action code here
group = GROUP_0;// <-- or jump to another group X for composite commands
digitalWrite(8, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(9, LOW); // set the LED on
digitalWrite(10, LOW); // set the LED on
digitalWrite(11, LOW); // set the LED on
case G1_ON_ALL:
// write your action code here
group = GROUP_0;// <-- or jump to another group X for composite commands
digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(9, HIGH); // set the LED on
digitalWrite(10, HIGH); // set the LED on
digitalWrite(11, HIGH); // set the LED on
break;
}
break;
}
}