I'm programming my senior project and I'm using arduino voice recognitions module v2. My problem is, I used Serial.read(); and get the first instruction and when it enter to a loop I need to get another instruction so I need to use another Serial.read(); how can I do it ???? please help....
so I need to use another Serial.read();
Please post the code that you are having trouble with.
Before you do a Serial.read() (at any time) make sure that there is serial data actually available.
can you check this I did the same as you said but, when it enter the loop its doesn't read secound instruction .
void loop()
{
while (Serial.available())
{
com = Serial.read();
switch (com)
{
case 0x31:
{ int i = 30;
digitalWrite(redPin, HIGH);
com = Serial.read();
loop2();
digitalWrite(GCHPin, HIGH);
digitalWrite(GCLPin, HIGH);
}
break;
case 0x32:
okey I understand in theory but, I don't have much experiance with arduino do you think should I use a code like stop for a second or any other, can you give me some simple example ?
Have a look at Robin2's Serial Basics thread.
Link to Serial Input Basics - simple reliable ways to receive data.
...R
what shoul I write to turn of the red led for this code. if I fix that that problem I will be solve my all problems.
void loop()
{
while (Serial.available())
{
com = Serial.read();
switch (com)
{
case 0x31:
{ int i = 30;
digitalWrite(redPin, HIGH);
while (Serial.available())
{delay(1000);
com2 = Serial.read();
switch (com2)
case 0x31:
digitalWrite(redPin, LOW);
break;
}
digitalWrite(GCHPin, HIGH);
digitalWrite(GCLPin, HIGH);
}
break;
The SWITCH/CASE stuff would be much more straightforward if it was like this
void loop()
{
while (Serial.available())
{
com = Serial.read();
switch (com)
{
case 0x31:
digitalWrite(redPin, HIGH);
break;
case 0x31:
digitalWrite(redPin, LOW);
break;
}
}
}
but the obvious problem is that both tests use the same value (taken from your code) - why would you use the same value to do 2 different things?
...R
Please read the forum "sticky" and use code tags in your posts.