#include "Arduino.h" #include "Platform.h" #include "Servo.h" #include "EasyVR.h" EasyVR easyvr(Serial); Servo* srv; //Groups and Commands enum Groups { GROUP_1 = 1, }; enum Group1 { G1_SHIRT = 0, G1_PEAR = 1, G1_ORANGE = 2, }; enum { SRV_SHIRT = 0, SRV_PEAR = 1, SRV_ORANGE = 2, }; EasyVRBridge bridge; int8_t group, idx; void setup() { Serial.begin(9600); pinMode(13, OUTPUT); digitalWrite(13, LOW); while (!easyvr.detect()) { delay(1000); } easyvr.setPinOutput(EasyVR::IO1, LOW); easyvr.setTimeout(5); easyvr.setLanguage(0); group = EasyVR::TRIGGER; //<-- start group (customize) srv = new Servo[3]; srv[SRV_SHIRT].attach(3); srv[SRV_SHIRT].write(0); srv[SRV_ORANGE].attach(5); srv[SRV_ORANGE].write(0); srv[SRV_PEAR].attach(6); srv[SRV_PEAR].write(0); srv[SRV_SHIRT].write(90); delay(2000); srv[SRV_SHIRT].write(0); delay(1000); srv[SRV_ORANGE].write(90); delay(2000); srv[SRV_ORANGE].write(0); delay(1000); srv[SRV_PEAR].write(90); delay(2000); srv[SRV_PEAR].write(0); } void action(); void loop() { easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening) 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]; easyvr.dumpCommand(group, idx, name, train); // perform some action action(); } else // errors or timeout { digitalWrite(13, LOW); if(easyvr.isTimeout()) /* error */; int16_t err = easyvr.getError(); } } void action() { digitalWrite(13, HIGH); switch (group) { case GROUP_1: switch (idx) { case G1_SHIRT: // write your action code here // group = GROUP_X; <-- or jump to another group X for composite commands srv[SRV_SHIRT].write(90); delay(1000); srv[SRV_SHIRT].write(0); break; case G1_PEAR: // write your action code here // group = GROUP_X; <-- or jump to another group X for composite commands srv[SRV_PEAR].write(90); delay(1000); srv[SRV_PEAR].write(0); break; case G1_ORANGE: // write your action code here // group = GROUP_X; <-- or jump to another group X for composite commands srv[SRV_ORANGE].write(90); delay(1000); srv[SRV_ORANGE].write(0); break; } break; } }