#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); // on déclare le port série virtuel sur les broches 12 et 13 pour le dialogue entre le Shield et l'Arduino #define pcSerial SERIAL_PORT_MONITOR #endif #include "EasyVR.h" // on inclue la bibliothèque EasyVR EasyVR easyvr(port); //Groups and Commands enum Groups // les sons sont programmés avec le logiciel EasyVR v3.11.0 { GROUP_0 = 0,// le groupe 0 contient le mot de passe de démarrage "Arduino" sans ce mot de passe le shield ne démarre pas la reconnaissance vocale GROUP_1 = 1, // les 2 sons pour "ALLUME" et "ÉTEINT" GROUP_2 = 2, // Les 2 sons pour allumer la LED avec une tape sur le bureau et 2 Tapes pour éteindre la LED GROUP_3 = 3, // les 3 sons : Miau et Meuhh pour allumer , le barrissement pour éteindre // GROUP_0 correspond à l'index du groupe 0 dans le logiciel EasyVR etc ... }; enum Group0 { G0_ARDUINO = 0,// le son "ARDUINO" correspond à l'index du son 0 dans le groupe 0 }; enum Group1 { G1_ALLUME = 0,// le son "ALLUME" correspond à l'index du son 0 dans le groupe 1 G1_ETEINT = 1,// le son "ETEINT" correspond à l'index du son 1 dans le groupe 1 }; enum Group2 { G2_TAP = 0, // le son "TAP" correspond à l'index du sons 0 dans le groupe 2 G2_TAPTAP = 1,// le son "TAPTAP" correspond à l'index du son 1 dans le groupe 2 }; enum Group3 { G3_MIAOU = 0, // le son "MIAOU" correspond à l'index du son 0 dans le groupe 3 G3_MEUHHH = 1, // le son "MEUHH" correspond à l'index du son 1 dans le groupe 3 G3_ELEPHANT = 2, // le son "BARRISSEMENT" correspond à l'index du son 2 dans le groupe 3 }; int8_t group, idx;// Déclare les variables "group" et "idx" en entier signé sur 8 bits void setup() { pinMode(9, OUTPUT); // on declare la broche 9 de l'Arduino en sortie digitalWrite(9,LOW); // on eteint la LED 9 // 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); // on éteint la led IO1 sur le module reconnaissance vocale Serial.println("EasyVR detected!"); easyvr.setTimeout(10); easyvr.setLanguage(5); group = EasyVR::TRIGGER; //<-- start group (customize) le groupe du début ici on demande le mot de passe "ARDUINO" } void action(); // on test si on reconnais un son void loop() { if (easyvr.getID() < EasyVR::EASYVR3) 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()); if (easyvr.getID() < EasyVR::EASYVR3) 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(); // 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 GROUP_0: switch (idx) { case G0_ARDUINO: // write your action code here // group = GROUP_X; <-- or jump to another group X for composite commands group = GROUP_3; break; } break; case GROUP_1: switch (idx) { case G1_ALLUME: digitalWrite(9, HIGH); group = GROUP_1; break; case G1_ETEINT: digitalWrite(9, LOW); group = GROUP_2; break; } break; case GROUP_2: switch (idx) { case G2_TAP: digitalWrite(9, HIGH); group = GROUP_2; break; case G2_TAPTAP: digitalWrite(9, LOW); group = GROUP_3; break; } break; case GROUP_3: switch (idx) { case G3_MIAOU: digitalWrite(9, HIGH); group = GROUP_3; break; case G3_MEUHHH: digitalWrite(9, HIGH); group = GROUP_3; break; case G3_ELEPHANT: digitalWrite(9, LOW); group = GROUP_3; break; } break; } }