Hi Guys
I bought a voice recognition from ebay for about $25 so far im very happy with the performance with regards to recognizing words recorded , the only problem I find is that i can not seem to get a action to be processed from a word being said, and i have track the problem down to my comparison coding.
below is the code
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
int ledPin = 0;
int redPin = 11; // R petal on RGB LED module connected to digital pin 11
int greenPin = 9; // G petal on RGB LED module connected to digital pin 9
int bluePin = 10; // B petal on RGB LED module connected to digital pin 10
byte com = 0; //reply from voice recognition
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(redPin, OUTPUT); // sets the redPin to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
delay(1000);
mySerial.write(0xAA);
mySerial.write(0x21);
delay(1000);
}
void loop() // run over and over again
{
while(mySerial.available())
{
com = Serial.write(mySerial.read());
switch(com)
{
case 0x11:
color(255,255,255); // turn RGB LED on -- white
break;
case 0x12:
color(255, 0, 0); // turn the RGB LED red
break;
case 0x13:
color(0,255, 0); // turn the RGB LED green
break;
case 0x14:
color(0, 0, 255); // turn the RGB LED blue
break;
case 0x15:
color(0,0,0); // turn the RGB LED off
break;
}
}
}
void color (unsigned char red, unsigned char green, unsigned char blue) // the color generating function
{
analogWrite(redPin, red*102/255);
analogWrite(bluePin, blue*173/255);
analogWrite(greenPin, green*173/255);
}
I have added software serial library to the code because i wanted to see if i get my commands into the arduino from the voice module and it works.
the problem area i think is the next few lines.
while(mySerial.available())
{
com = Serial.write(mySerial.read());
switch(com)
{
case 0x11:
color(255,255,255); // turn RGB LED on -- white
break;
case 0x12:
color(255, 0, 0); // turn the RGB LED red
break;
case 0x13:
color(0,255, 0); // turn the RGB LED green
break;
case 0x14:
color(0, 0, 255); // turn the RGB LED blue
break;
case 0x15:
color(0,0,0); // turn the RGB LED off
break;
}
See when you speak into the module it will return the word spoken in a form of "Result:12" or "Result:13" and so on so I try and compare an do a action with a switch/case so when the module reports "Result:12" the comparison on 0x12 should be made and the red light should switch on.... it doesn't.
any help ?... please