"Hi i need your help with my code I don't know what i did wrong, but for some re

"Hi i need your help with my code I don’t know what i did wrong, but for some reason i am getting an error message saying a function-definition is not allowed here before ‘{’ token , please can you help me anyone, i have tried everything. :frowning:

int redPin = 9; 
int greenPin = 10; 
int bluePin = 11; 
byte com = 0; //reply from voice recognition

void setup()
{
Serial.begin(9600);

pinMode(redPin, OUTPUT); 
pinMode(greenPin, OUTPUT); 
pinMode(bluePin, OUTPUT); 
delay(500);



void loop()

{
  while(Serial.available())

{
com = Serial.read();
switch(com)
{
case 0x11:
digitalWrite(redPin, HIGH);
break;

case 0x12:
digitalWrite(greenPin, HIGH);
break;

case 0x13:
digitalWrite(bluePin, HIGH);
break;

case 0x14:
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
break;

case 0x15:
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
break;
    }
  }
}
pinMode(bluePin, OUTPUT);
delay(500);

void loop()

Where is the closing bracket for setup()?

If you use the autoformat function of the IDE (ctrl-t or Tools, Autoformat) errors like that are often easier to see.

the code worked now put the circuit didnt work at all :frowning:

Do you have current limiting resistors for your LEDs?

How do you send 0x11,0x12 etc on your serial port?

Please post a circuit diagram. Which Arduino board are you using?

com = Serial.read();
switch(com)
{
case 0x11:
digitalWrite(redPin, HIGH);
break;

// etc …

0x11 is 17, which is an ASCII control-Q. So you want the red LED do come on when you type a control-Q on the keyboard. Right?

Probably not. The ASCII code for Q is 0x51 for an uppercase R and 0x71 for a lowercase one. But the easier way is to use a char constant:

com = Serial.read();
switch(com)
{
case 'Q':
digitalWrite(redPin, HIGH);
break;

// etc …