long microFarads; // floating point variable to preserve precision, make calculations
long nanoFarads;
enum Scale {uf, nf};
//1uf (microfarad)=1000nf (nanofarad)
//unsigned int CommonValues[]={10,15,22,33,47,68,100,150,200,220,300,330,400,470,500,560,680,700,800,820,1000,1200,1500,1600,1800,2000,2100,2200,2400,2500,2700,3000,3300,3500,3600,3900,4000,4300,4700,5000,5300,5600,6000,6800,7200,7500,8200,8800,10000,10800,12000,12400,13000,14000,14500,15000,16100,17000,18000,18900,20000,21000,21600,22000,23000,23300,24000,24300,25000,27000,30000,32000,32400,33000,34000,35000,37000,37800,38000,39000,40000,42000,43000,45000,46000,47000,48000,50000,51000,52000,54000,55000,56000,59000,62000,64500,65000,68000,70000,70800,73000,80000,82000,85000,86000,100000,110000,120000,130000,140000,150000,160000,170000,180000,200000,210000,220000,250000,260000,270000,280000,290000,300000,310000,330000,340000,350000,360000,370000,390000,400000,410000,420000,430000,460000,470000,480000,500000};
unsigned int CommonValues[]={10,15,22,33,47,68,100,150,200,220,300,330,400,470,500,560,680,700,800,820,1000,1200,1500,1600,1800,2000,2100,2200,2400,2500,2700,3000,3300,3500,3600,3900,4000,4300,4700,5000,5300,5600,6000,6800,7200,7500,8200,8800,10000,10800,12000,12400,13000,14000,14500,15000,16100,17000,18000,18900,20000,21000,21600,22000,23000,23300,24000,24300,25000,27000,30000,32000,32400,33000,34000,35000,37000,37800,38000,39000,40000,42000,43000,45000,46000,47000,48000,50000,51000,52000,54000,55000,56000,59000,62000,64500,65000,68000,70000,70800,73000,80000,82000,85000,86000,100000,110000,120000,130000,140000};
float CommonValuesMultiplier=.01;
Scale CommonValues_Scale= nf;
int CommonValuesCount =sizeof CommonValues/sizeof CommonValues[0];
float Tolerance=0.2; //+-20%
float Actual_Value_nf;
float CommonValue_nf;
float Min=0;
float Max=0;
void setup()
{
Serial.begin(9600);
/*
label: 100uf
0 mS 0 microFarads
936 mS 93 microFarads
915 mS 91 microFarads
909 mS 90 microFarads
80 mS 8 microFarads
912 mS 91 microFarads
903 mS 90 microFarads
902 mS 90 microFarads
900 mS 90 microFarads
897 mS 89 microFarads
0 mS 0 microFarads
0 mS 0 microFarads
90.5 is the average
*/
//312 microfarads
//Get_LabelValue(93,uf);
Get_LabelValue(113,uf);
// Get_LabelValue(90,uf);
// Get_LabelValue(91,uf);
//119 microfarads
//Get_LabelValue(119,uf);
//label: 330
//registered values
// 221 microFarads
// 336 microFarads
// 227 microFarads
// 339 microFarads
//1123/4=280.75
//get the average???? ergo, if it isn't 0, add to array, if 0, then end array,
//take average then get computer label value
//330*0.2=66
//(66)+330=396
//330-66=264
//Get_LabelValue(5800,nf);
}
void loop()
{
}
//1000nf (nanofarad)=1uf (microfarad)
float Get_LabelValue(float Actual_Value,Scale scale)
{
if(Actual_Value == 0){return 0;}
if(scale==nf) { Actual_Value_nf= Actual_Value * 1000; }else if(scale==uf) {Actual_Value_nf= Actual_Value;}else{ return 0;}
for (int i=0; i<CommonValuesCount; i++)
{
if(CommonValues_Scale==uf)
{
CommonValue_nf=CommonValues[i]*1000;
}
else if ( CommonValues_Scale==nf)
{
CommonValue_nf=CommonValues[i];
}
else
{
return 0;
}
CommonValue_nf=CommonValue_nf * CommonValuesMultiplier;
Max=(CommonValue_nf + (Tolerance* CommonValue_nf));
Min=CommonValue_nf - (Tolerance* CommonValue_nf);
/*Serial.print("CommonValue_nf ");
Serial.println(CommonValue_nf);
Serial.print("Min ");
Serial.println(Min);
Serial.print("Max ");
Serial.println(Max);
Serial.println("");
*/
if(Actual_Value_nf>=Min && Actual_Value_nf<=Max)
//if(Actual_Value_nf>=CommonValues[i] - (Tolerance* CommonValues[i]) && Actual_Value_nf<=(CommonValues[i] + (Tolerance* CommonValues[i])))
{
Serial.print("Min ");
Serial.println(Min);
Serial.print("Max ");
Serial.println(Max);
Serial.print("Actual_Value_nf - CommonValue_nf ");
Serial.println(Actual_Value_nf - CommonValue_nf);
Serial.print("CommonValue_nf ");
Serial.println(CommonValue_nf);
Serial.println("");
// return CommonValue_nf;//CommonValue_nf * CommonValuesMultiplier;
}
}
// Serial.print("LabelValue: UNKNOWN");
// return Actual_Value_nf;
}