Answer the question
In order to leave comments, you need to log in
How to compare a variable with an array element?
The Arduino uses an analog input to measure voltage. The resulting value must be compared with the table value (100 rows) and, based on the comparison, the corresponding value should be assigned to another variable. So far I know this way of comparison:
float value = (float)analogReag(A1)*5*1000/1024;
int value_int = (int)value_int;
switch(value_int) {
case(4442):
current = 120;
...
int [] [] ={
{120, 4442}
{121, 4222}
...}
Answer the question
In order to leave comments, you need to log in
You provided a code snippet
float value = (float)analogReag(A1)*5*1000/1024;
int value_int = (int)value_int;
switch(value_int) {
case(4442):
current = 120;
//Объявли массив table из 1024 значений
//Для каждого значения ввели правильный ответ
int table[] = {12, 34, 64, 33, ..., 954}
//Где-то в коде
int value = analogReag(A1);
current = table[value];
Binary search tree or hash table.
Although 100 pairs is about nothing. Did you time it? Here somewhere from 100 thousand you can already worry.
By the way, you are throwing away the formula in vain. Perhaps cubic splines could help you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question