I'm trying to set up an arduino infrared sensor and when I try to use a switch statement it returns "duplicate case value". Any suggestions or explanations on this issue? Btw. I'm a total beginner so don't be suprised if I do some stupid mistake.
I tried using int for the val variable but it says there's an overflow so I used double instead. I tried looking at some other problems similar to mine but none of them apply here.
//code starts here
void loop() {
constexpr long double val[10]=
{16724175,16718055,16743045,16716015,16726215,16734885,16728765,16730805,16732845,16738455}; //holds all values from infrared sensor
int results_val;
if (reciever.decode(&results)){ //not relevant
Serial.println(results.value);
results_val = results.value;
reciever.resume();
}
switch(results_val){ //should check which button was pressed
case (int) val[0] : Serial.println(1);
break;
case (int) val[1] : Serial.println(2);
break;
case (int) val[2] : Serial.println(3);
break;
case (int) val[3] : Serial.println(4);
break;
case (int) val[4] : Serial.println(5);
break;
case (int) val[5] : Serial.println(6);
break;
case (int) val[6] : Serial.println(7);
break;
case (int) val[7] : Serial.println(8);
break;
case (int) val[8] : Serial.println(9);
break;
case (int) val[9] : Serial.println(0);
break;
}
}
//code ends here
I expected to get any result; even if wrong; but it returns "duplicate case value"