#include "Arduino.h" #if !defined(SERIAL_PORT_MONITOR) #error "Arduino version not supported. Please update your IDE to the latest version." #endif #if defined(SERIAL_PORT_USBVIRTUAL) // Shield Jumper on HW (for Leonardo and Due) #define port SERIAL_PORT_HARDWARE #define pcSerial SERIAL_PORT_USBVIRTUAL #else // Shield Jumper on SW (using pins 12/13 or 8/9 as RX/TX) #include "SoftwareSerial.h" SoftwareSerial port(12, 13); #define pcSerial SERIAL_PORT_MONITOR #endif #include "EasyVR.h" EasyVR easyvr(port); int8_t group, idx; void setup() { pinMode(9, OUTPUT); digitalWrite(9,LOW); // setup PC serial port pcSerial.begin(9600); // bridge mode? int mode = easyvr.bridgeRequested(pcSerial); switch (mode) { case EasyVR::BRIDGE_NONE: // setup EasyVR serial port port.begin(9600); // run normally pcSerial.println(F("---")); pcSerial.println(F("Bridge not started!")); break; case EasyVR::BRIDGE_NORMAL: // setup EasyVR serial port (low speed) port.begin(9600); // soft-connect the two serial ports (PC and EasyVR) easyvr.bridgeLoop(pcSerial); // resume normally if aborted pcSerial.println(F("---")); pcSerial.println(F("Bridge connection aborted!")); break; case EasyVR::BRIDGE_BOOT: // setup EasyVR serial port (high speed) port.begin(115200); // soft-connect the two serial ports (PC and EasyVR) easyvr.bridgeLoop(pcSerial); // resume normally if aborted pcSerial.println(F("---")); pcSerial.println(F("Bridge connection aborted!")); break; } while (!easyvr.detect()) { Serial.println("EasyVR not detected!"); delay(1000); } easyvr.setPinOutput(EasyVR::IO1, LOW); Serial.println("EasyVR detected!"); easyvr.setTimeout(5); easyvr.setLanguage(5); // 0 = Anglais; 5 = Français, en fait le son est Français mais le texte reste Anglais group = 0; //<-- start group (considering to start from custom grammar 0) } void action(); void loop() { if (easyvr.getID() < EasyVR::EASYVR3) easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening) Serial.print(" Dire la commande WS "); Serial.println(group); easyvr.recognizeWord(group); // pou les commandes SI ( Multi Locuteur) //easyvr.recognizeCommand(group); // used for SD commands/trigger or for built-in trigger word do { // can do some processing while waiting for a spoken command } while (!easyvr.hasFinished()); if (easyvr.getID() < EasyVR::EASYVR3) easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off /* This part of the code is not needed if using SI commands only (excluding the built-in trigger ROBOT) if (idx >= 0) { // built-in trigger (ROBOT) // group = GROUP_X; <-- jump to another group X return; } idx = easyvr.getCommand(); */ idx = easyvr.getWord(); if (idx >= 0) { // print debug message for SI commands uint8_t flags, num; char name[32]; Serial.print("Command: "); Serial.print(idx); if (easyvr.dumpGrammar(group, flags, num)) for (int8_t i = 0; i <= idx; ++i) easyvr.getNextWordLabel(name); pcSerial.print(F(" = ")); pcSerial.println(name); // beep 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); } } } void action() { switch (group) { case 0: // groupe TRIGGER switch (idx) { case 0: group = 1; // saute au Groupe WORDSET N°1 break; } break; case 1: // Groupe WORDSET N°1 switch (idx) { case 0: digitalWrite(9, HIGH); group = 1; break; case 6: digitalWrite(9, LOW); group = 1; break; } break; } }