Hey, I'm not really experienced in coding. I want to make my ws2812b led strips voice reactive. I need them to only turn on when I talk. I also want to learn how to make them react to specific voice commands like if I say "ON" they turn on and when I say "OFF" to turn off. Any help would be appreciated.
Supplies:
SMAKN Speak Recognition, Voice Recognition Module V3, compatible with Arduino
Alitove WS2812B LED Strip
ELEGOO UNO R3
#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"
#include <FastLED.h>
#define NUM_LEDS 150
#define LED_PIN 5
CRGB led[NUM_LEDS];
/**
Connection
Arduino VoiceRecognitionModule
2 -------> TX
3 -------> RX
*/
VR myVR(2, 3); // 2:RX 3:TX, you can choose your favourite pins.
uint8_t records[7]; // save record
uint8_t buf[64];
//int led = 13;
int led1 = 4;
#define On (0)
#define Off (1)
void printSignature(uint8_t *buf, int len)
{
int i;
for (i = 0; i < len; i++) {
if (buf[i] > 0x19 && buf[i] < 0x7F) {
Serial.write(buf[i]);
}
else {
Serial.print("[");
Serial.print(buf[i], HEX);
Serial.print("]");
}
}
}
void printVR(uint8_t *buf)
{
Serial.println("VR Index\tGroup\tRecordNum\tSignature");
Serial.print(buf[2], DEC);
Serial.print("\t\t");
if (buf[0] == 0xFF) {
Serial.print("NONE");
}
else if (buf[0] & 0x80) {
Serial.print("UG ");
Serial.print(buf[0] & (~0x80), DEC);
}
else {
Serial.print("SG ");
Serial.print(buf[0], DEC);
}
Serial.print("\t");
Serial.print(buf[1], DEC);
Serial.print("\t\t");
if (buf[3] > 0) {
printSignature(buf + 4, buf[3]);
}
else {
Serial.print("NONE");
}
Serial.println("\r\n");
}
void setup()
{
/** initialize */
myVR.begin(9600);
Serial.begin(115200);
Serial.println("Elechouse Voice Recognition V3 Module\r\nControl LED sample");
for (int x = 0; x < 359; x++) {
led[2 * x] = CRGB(255, 100, 0);
FastLED.show();
if (myVR.clear() == 0) {
Serial.println("Recognizer cleared.");
} else {
Serial.println("Not find VoiceRecognitionModule.");
Serial.println("Please check connection and restart Arduino.");
while (1);
}
if (myVR.load((uint8_t)On) >= 0) {
Serial.println("On");
}
if (myVR.load((uint8_t)Off) >= 0) {
Serial.println("Off");
}
}
void loop()
{
int ret;
ret = myVR.recognize(buf, 50);
if (ret > 0) {
switch (buf[1]) {
case On:
/** turn on LED */
digitalWrite(crgb, HIGH);
break;
case Off:
/** turn off LED*/
digitalWrite(crgb, LOW);
break;
default:
Serial.println("Record function undefined");
break;
}
/** voice recognized */
printVR(buf);
}
}