#include <EasyVR.h>
EasyVR easyvr(Serial); // Create an EasyVR object
const byte red = 11;
const byte green = 10;
const byte blue = 9;
void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
Serial.begin(9600); // Initialize serial communication
while (!Serial); // Wait for the serial connection to initialize (useful for debugging)
if (!easyvr.begin()) {
Serial.println("EasyVR not detected!");
while (true); // Stay in this loop if the EasyVR module is not found
}
Serial.println("EasyVR Module Ready");
}
void loop() {
if (easyvr.recognizeCommand(0)) { // Start listening for commands in group 0
int commandID = easyvr.getCommandID(); // Get the ID of the recognized command
switch (commandID) {
case 0: // Command ID 0: Turn RGB LED On
setRGB(HIGH, HIGH, HIGH); // Turn all colors ON
Serial.println("Command: LED On");
break;
case 1: // Command ID 1: Turn RGB LED Off
setRGB(LOW, LOW, LOW); // Turn all colors OFF
Serial.println("Command: LED Off");
break;
case 2: // Command ID 2: Red LED On
setRGB(HIGH, LOW, LOW); // Only red ON
Serial.println("Command: Red");
break;
case 3: // Command ID 3: Green LED On
setRGB(LOW, HIGH, LOW); // Only green ON
Serial.println("Command: Green");
break;
case 4: // Command ID 4: Blue LED On
setRGB(LOW, LOW, HIGH); // Only blue ON
Serial.println("Command: Blue");
break;
default:
Serial.println("Unknown Command");
break;
}
}
}
// Helper function to set the RGB LED state
void setRGB(bool r, bool g, bool b) {
digitalWrite(red, r);
digitalWrite(green, g);
digitalWrite(blue, b);
}