enum Scale {uf, nf};
//in nF so we don't have to worry about decimals, and thus our array will be smaller in terms of bytes
//1uf (microfarad)=1000nf (nanofarad)
//unsigned int CommonValues[]={1000, 15000, 22000, 33000, 47000, 68000, 1000, 15000, 2000, 22000, 3000, 33000, 4000, 47000, 5000, 56000, 68000, 7000, 8000, 82000, 10000, 12000, 15000, 16000, 18000, 20000, 21000, 22000, 24000, 25000, 27000, 30000, 33000, 35000, 36000, 39000, 40000, 43000, 47000, 50000, 53000, 56000, 60000, 68000, 72000, 75000, 82000, 88000, 100000, 108000, 120000, 124000, 130000, 140000, 145000, 150000, 161000, 170000, 180000, 189000, 200000, 210000, 216000, 220000, 230000, 233000, 240000, 243000, 250000, 270000, 300000, 320000, 324000, 330000, 340000, 350000, 370000, 378000, 380000, 390000, 400000, 420000, 430000, 450000, 460000, 470000, 480000, 500000, 510000, 520000, 540000, 550000, 560000, 590000, 620000, 645000, 650000, 680000, 700000, 708000, 730000, 800000, 820000, 850000, 860000, 1000000, 1100000, 1200000, 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 2000000, 2100000, 2200000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3300000, 3400000, 3500000, 3600000, 3700000, 3900000, 4000000, 4100000, 4200000, 4300000, 4600000, 4700000, 4800000, 5000000, 5100000, 5400000, 5500000, 5600000, 5800000, 6000000, 6500000, 6800000, 7200000, 7400000, 7600000, 7800000, 8200000, 8300000, 8400000, 8700000, 9000000, 9600000, 10000000, 11000000, 12000000, 13000000, 15000000, 16000000, 17000000, 18000000, 20000000, 22000000, 23000000, 24000000, 25000000, 26000000, 27000000, 28000000, 30000000, 31000000, 32000000, 33000000, 34000000, 36000000, 37000000, 38000000, 39000000, 40000000, 41000000, 47000000, 48000000, 50000000, 55000000, 56000000, 60000000, 62000000, 66000000, 68000000, 76000000};
unsigned int CommonValues[]={1, 15, 22, 33, 47, 68, 1, 15, 2, 22, 3, 33, 4, 47, 5, 56, 68, 7, 8, 82, 10, 12, 15, 16, 18, 20, 21, 22, 24, 25, 27, 30, 33, 35, 36, 39, 40, 43, 47, 50, 53, 56, 60, 68, 72, 75, 82, 88, 100, 108, 120, 124, 130, 140, 145, 150, 161, 170, 180, 189, 200, 210, 216, 220, 230, 233, 240, 243, 250, 270, 300, 320, 324, 330, 340, 350, 370, 378, 380, 390, 400, 420, 430, 450, 460, 470, 480, 500, 510, 520, 540, 550, 560, 590, 620, 645, 650, 680, 700, 708, 730, 800, 820, 850, 860, 1, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 2, 2100, 2200, 2500, 2600, 2700, 2800, 2900, 3, 3100, 3300, 3400, 3500, 3600, 3700, 3900, 4, 4100, 4200, 4300, 4600, 4700, 4800, 5, 5100, 5400, 5500, 5600, 5800, 6, 6500, 6800, 7200, 7400, 7600, 7800, 8200, 8300, 8400, 8700, 9, 9600, 10, 11, 12, 13, 15, 16, 17, 18, 20, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 41, 47, 48, 50, 55, 56, 60, 62, 66, 68, 76};
long CommonValuesMultiplier=0.1;
Scale CommonValues_Scale= nf;
int CommonValuesCount =sizeof CommonValues/sizeof CommonValues[0];
float Tolerance=0.2; //+-20%
//long CommonValue=0;
float Actual_Value_nf;
int totalCommonValues = sizeof(CommonValues) / sizeof(CommonValues[0]);
int CommonValue_nf;
//String ToleranceAmt=Tolerance;
void setup()
{ Serial.begin(9600);
//119 microfarads
Get_LabelValue(119,uf);
//Get_LabelValue(5800,nf);
}
void loop()
{
}
//1000nf (nanofarad)=1uf (microfarad)
float Get_LabelValue(float Actual_Value,Scale scale)
{
CommonValue_nf=0;
long Min=0;
long Max=0;
long microFarads; // floating point variable to preserve precision, make calculations
long nanoFarads;
if(Actual_Value == 0){return 0;}
Actual_Value_nf=Actual_Value;
if(scale==uf) { Actual_Value_nf*= 1000; }
//Serial.print("Actual_Value_nf:");
// Serial.println(String(Actual_Value_nf, 5));
//Serial.println(Actual_Value_nf);
//long Min=0;
// long Max=0;
for (int i=0; i<CommonValuesCount; i++)
// for (int i=0; i<3; i++)
{
// CommonValue_nf=CommonValues[i];
//1uf (microfarad)=1000nf (nanofarad)
if(CommonValues_Scale==uf){ CommonValue_nf=CommonValues[i]*1000; }else if (CommonValues_Scale==nf) {CommonValue_nf=CommonValues[i]; } else { return 0;}
Serial.print("CommonValueNF:");
Serial.println(CommonValue_nf);
Max=(CommonValue_nf + (Tolerance* CommonValue_nf));
Min=CommonValue_nf - (Tolerance* CommonValue_nf);
if(Actual_Value_nf>=Min && Actual_Value_nf<=Max)
{
Serial.print("LabelValue:");
Serial.println(CommonValue_nf);
// Serial.println(""); Serial.println("");
return CommonValue_nf;
}
// Actual_Value
}
return Actual_Value_nf;
}