My arduino needs to take a 14-bit number and convert it to a 10-bit number. Can't use a formula for it since the data is quite random. So I created a lookup table with 2^14 elements, each containing a 10-bit value. But it's too big to fit on the arduino. So I thought of using a switch statement instead. Would this result in a significant speed decrease?
Say, for example, that the input value is 16383. How much longer would it take for the arduino to iterate through the 16384 cases compared to accessing index #16383 of an array?
EDIT: This code compiles fine and reports a program memory usage of 1000 bytes.
int xval;
int yval;
void setup() {
// put your setup code here, to run once:
}
void loop() {
xval = random(0,16383);
switch (xval) {
case 0:
yval = 0;
break;
case 1:
yval = 4;
break;
case 2:
yval = 4;
break;
case 3:
yval = -60;
...
case 16383:
yval = 1023;
break;
}
}
However, I haven't tried if it really works so maybe the compiler is optimizing away too much.
EDIT 2: Added the line Serial.println(yval);
so that I'm actually doing something with yval as Majenko commented. And now it doesn't compile :'( :'( :'(
So, I'll tackle my problem in some other way.