1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
| #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);
const int out3 = 7; // define Arduino pin connected to relay 3
const int out4 = 8; // define Arduino pin connected to relay 4
//Groups and Commands
enum Groups
{
GROUP_1 = 1,
};
enum Group1
{
G1_OUVRIR = 0,
G1_FERMER = 1,
};
int8_t group, idx;
void setup()
{
// 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);
group = GROUP_1; //lancement du groupe (customisé)
pinMode(7, OUTPUT); // NE PAS METTRE PIN 12 OU 13 DEJA UTILISES PAR LE SERIAL
pinMode(8, OUTPUT); // NE PAS METTRE PIN 12 OU 13 DEJA UTILISES PAR LE SERIAL
}
// enable or disable a relay (1 to 4)
void setRelay(int relay, int value)
{
if(relay > 0 && relay < 5) digitalWrite((relay + 4), value);
}
void action();
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()// la LED s'allume quand on dit OUVRIR et s'éteint avec FERMER
{
switch (group)
{
case GROUP_1:
switch (idx)
{
case G1_OUVRIR:
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
group = GROUP_1;
break;
case G1_FERMER:
digitalWrite(7, LOW);
digitalWrite(8, HIGH); setRelay(4, 1); // enable relay 4
Serial.print("Relay 4: Enabled ... ");
delay(10000); // wait for a second
setRelay(4, 0); // disable relay 4
Serial.println("Disabled");
delay(10000); // wait for a second
}
group = GROUP_1;
break;
}
} |
Partager