Hi, ive been fiddling around with my Arduino and Easyvr for a few nights but am facing some problems.
All im trying to do is give digital pin 12 an output of either high or low and the easyvr starts listening again for the next command.
I want to control some light with this as I also have a relay for it to turn on and off. But all this code does at the moment is turns the relay off and wont listen to any more commands.
Im not asking for a whole arduino tutorial or anything, just for someone to give me a kick start on how to get this to work.
Heres the code;
#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"
#include <Servo.h>
#define SND_Access_denied 1
#define SND_Access_granted 2
#define SND_Hello 3
#define SND_Please_repeat 4
#define SND_Yess_boss 6
#define SND_Please_talk_louder 5
Servo myservo;
int ledPin = 13;
int relayPin = 12;
EasyVR easyvr(port);
EasyVRBridge bridge;
uint32_t mask = 0;
int8_t group = 0;
uint8_t train = 0;
char name[32];
void setup()
{
// bridge mode?
if (bridge.check())
{
cli();
bridge.loop(0, 1, 12, 13);
}
Serial.begin(9600);
port.begin(9600);
myservo.attach(9);
myservo.write(90);
if (!easyvr.detect())
{
Serial.println("EasyVR not detected!");
for (;;);
}
easyvr.setPinOutput(EasyVR::IO1, LOW);
Serial.println("EasyVR detected!");
easyvr.setTimeout(5);
easyvr.setLanguage(EasyVR::ITALIAN);
int16_t count = 0;
if (easyvr.getGroupMask(mask)) // get trained user names and passwords
{
uint32_t msk = mask;
for (group = 0; group <= EasyVR::PASSWORD; ++group, msk >>= 1)
{
if (!(msk & 1)) continue;
if (group == EasyVR::TRIGGER)
Serial.print("Trigger: ");
else if (group == EasyVR::PASSWORD)
Serial.print("Password: ");
else
{
Serial.print("Group ");
Serial.print(group);
Serial.print(": ");
}
count = easyvr.getCommandCount(group);
Serial.println(count);
for (int8_t idx = 0; idx < count; ++idx)
{
if (easyvr.dumpCommand(group, idx, name, train))
{
Serial.print(idx);
Serial.print(" = ");
Serial.print(name);
Serial.print(", Trained ");
Serial.print(train, DEC);
if (!easyvr.isConflict())
Serial.println(" times, OK");
else
{
int8_t confl = easyvr.getWord();
if (confl >= 0)
Serial.print(" times, Similar to Word ");
else
{
confl = easyvr.getCommand();
Serial.print(" times, Similar to Command ");
}
Serial.println(confl);
}
}
}
}
}
easyvr.setLevel(EasyVR::HARDER);
easyvr.playSound(SND_Hello, EasyVR::VOL_FULL);
}
void loop()
{
int idx_cmd;
int idx_pwd;
easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
Serial.println("Say a name in Group 1");
easyvr.recognizeCommand(1); // recognise command in group 1
while (!easyvr.hasFinished()); // wait for user name
easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off
idx_cmd = easyvr.getCommand(); // get recognised user name
if (idx_cmd >= 0)
{
Serial.print("Name: ");
if (easyvr.dumpCommand(1, idx_cmd, name, train))
Serial.println(name);
else
Serial.println();
easyvr.playSound(SND_Yess_boss , EasyVR::VOL_FULL); // ask for password
easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
Serial.println("Say the password");
easyvr.recognizeCommand(EasyVR::PASSWORD); // set group 16
while (!easyvr.hasFinished()); // wait for password
easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off
idx_pwd = easyvr.getCommand(); // get recognised password
if (idx_pwd >= 0)
{
Serial.print("Password: ");
if (easyvr.dumpCommand(EasyVR::PASSWORD, idx_pwd, name, train))
{
Serial.print(" = ");
Serial.println(name);
}
else
Serial.println();
if ( idx_pwd == idx_cmd) // index of username and password are the same, access granted
{
Serial.println("Access granted");
easyvr.playSound(SND_Access_granted , EasyVR::VOL_FULL);
pinMode(relayPin, OUTPUT);
digitalWrite(ledPin, HIGH); // set the LED pin High
digitalWrite(relayPin, LOW); // set the relay pin High
}
else // index of username and password differ, access is denied
{
Serial.println("Access denied");
easyvr.playSound(SND_Access_denied , EasyVR::VOL_FULL);
}
}
int16_t err = easyvr.getError();
if (easyvr.isTimeout() || (err >= 0)) // password timeout, access is denied
{
Serial.println("Error, try again...");
easyvr.playSound(SND_Please_talk_louder , EasyVR::VOL_FULL);
}
}
else
{
if (easyvr.isTimeout())
Serial.println("Timed out, try again...");
int16_t err = easyvr.getError();
if (err >= 0)
{
Serial.print("Error ");
Serial.println(err, HEX);
}
}
}