I'm haveing real trouble I'm getting this error expected unqualified~id before 'switch' for this code
const int AudioSource1 = 12; //audio inputs decleared at pin 12 and 13
const int AudioSource2 = 13;
const int LeftEarphones = 7; //left ear phones declared at pin A0
const int RightEarphones = A1; //Right ear phones declared at pin A1
const int LeftDolbyFront = A2;//Dolby 5:5 outputs
const int LeftDolbyBack = A3;
const int RightDolbyFront = A4;
const int RightDolbyBack = A5;
const int DolbySub = ~11;//dolby sub-woofer
//const int Button
int k = A0;
int adc_key_val[5] ={50, 200, 400, 600, 800 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;
boolean incremented = false;
int state = 0;
//int k;//keypress
void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode (AudioSource1, INPUT);
pinMode (AudioSource2, INPUT);
pinMode (LeftEarphones, OUTPUT);
pinMode (RightEarphones, OUTPUT);
pinMode (LeftDolbyFront, OUTPUT);
pinMode (LeftDolbyBack, OUTPUT);
pinMode (RightDolbyFront, OUTPUT);
pinMode (RightDolbyBack, OUTPUT);
pinMode (DolbySub, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the sensor:
if (adc_key_in < 200 && (incremented = false));{
state ++;
incremented=true;
}
if (adc_key_in < 200);
{
incremented =false;
if(state >2);
state=0;
}
}
// map the sensor range to a range of four options:
// int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
// do something different depending on the
// range value:
[color=red]switch (adc_key_in < 200) {[/color]
case 0: { // rightspeakers
Serial.println('Right speakers');
int RightDolbyFront = HIGH;
int RightDolbyBack = HIGH;
int DolbySub = HIGH;
break;
}
case 1: {//Left speakers
Serial.println('Left speakers');
int LeftDolbyFront = HIGH;
int LeftDolbyBack = HIGH;
int DolbySub = HIGH;
break;
}
case 2:{ // Headphones
Serial.println('Headphones');
int LeftEarphones = HIGH;
int RightEarphones = HIGH;
break;
}
Default:{
Serial.println("off");
break;
}
delay(1); // delay in between reads for stability
}
(code tags added by moderator)
which I heavley modified from an exampleI found on the web. the compiler says the error is in in the line in red but I just cant see whats wrong please help
Robin2:
SWITCH just takes the name of a variable so it should be
No, "switch" takes any integer expression, but obviously with a comparison as that expression, the range of possible cases is severely limited.
I was going to post, in fact I did then deleted it, exactly what Robin said. But when I took the comparison out, it still gave the OP's quoted compile error. I realised that it's legit as code, although as you say AWOL, the cases then need to have passed the test first. Interesting.....