# My Project Toggle switches

is there a way to to tell arduino to pull information from a chart

because i have 11 input with a specic set of combinations to present values

the only way i see it is to define each toggle switch(input) then write if then statements all over the place

just wondering if there's a shorter way of doing it

Yes you can have lookup tables. It's quite common practice. How many values are you concerned with and what sort of values are they?

well i'm making an encoding altimeter, it has 11 inputs all in grey code i want arduino to just use the chart directly its has 1278 outputs

here a short part of my chart

Altitude in.pdf (128 KB)

Ah right. So all these inputs are a simple HIGH or LOW?

BTW do you actually need the negative values in your table?

yeah i do need the negative value yeah they are just high and low but in gray not binary

i really appreciate programming is still tough for me

OK. I’d suggest you treat those bits as if they are binary bits, copy and paste the entire table into an excel spreadsheet to convert each 11 bit value into an integer. Convert the readings into integer (ie -0.9 thousand wants to be -9000)

The other issue you are going to have is that the sheer size of the table will be impractical to hold in sRam so you’ll need to use PROGMEM to store it.

Anyhow, as a pointer in the right direction, here’s a bit of an idea.

``````#include <avr/pgmspace.h>

struct altitudeValue
{
int altitude;
};

int altTableSize;
const PROGMEM altitudeValue AVS[]=
{
2, -1000,
6, -900
//etc..
};

void setup() {
// put your setup code here, to run once:

altTableSize = sizeof (AVS) / sizeof (altitudeValue);

}

void loop() {
// put your main code here, to run repeatedly:

}

{
altitudeValue tableEntry;

for(int n=0; n< altTableSize; n++ )
{
//Copy table entry to local variable
memcpy_P(&tableEntry, &AVS[n],sizeof(altitudeValue));
return tableEntry.altitude;
}

//pick a value that you'll recognise as WRONG
//return it here to indicate that a search of the table failed
return -20000;
}
``````

trackstarx2: is there a way to to tell arduino to pull information from a chart

because i have 11 input with a specic set of combinations to present values

the only way i see it is to define each toggle switch(input) then write if then statements all over the place

just wondering if there's a shorter way of doing it

Are the switches debounced, say in hardware?

You can put each switch read into a separate bit in an int and the resulting value will be unique. 11 bits gives 0 to 2047. Use that as your table index.