Paso 4: UF... sólo 94 líneas esta vez
El código de Arduino:
///////////////////////////////
#include < math.h >
byte chargePin = 9;
byte triggerPin = 8;
byte noninvertingPin = A0;
byte invertingPin = A1;
Float constRes = 100;
timeStart largo sin firmar;
timeEnd largo sin firmar;
timeDelta largo sin firmar;
capacitancia largo sin firmar;
inductancia largo sin firmar;
resistencia largo sin firmar;
frecuencia de largo sin firmar;
String str;
char c;
void setup() {}
Serial.Begin(9600);
pinMode (chargePin, salida);
pinMode (triggerPin, entrada);
pinMode (noninvertingPin, entrada);
pinMode (invertingPin, entrada);
Str = "";
c = '\n';
}
void loop() {}
while((serial.Available() > 0)) {}
c = Serial.read();
Si (! () c=='\n')) {
Str += c;
}
Else {}
Si (str == "requestFarads") {}
testCapacitance();
Serial.println(Capacitance);
}
else if (str == "requestHenrys") {}
testInductance();
Serial.println(Inductance);
}
else if (str == "requestOhms") {}
testResistance();
Serial.println(Resistance);
}
else if (str == "requestHertz") {}
testFrequency();
Serial.println(Frequency);
}
Str = "";
while(serial.Available() > 0) Serial.read();
}
}
digitalWrite (chargePin, bajo);
}
void testCapacitance () {}
digitalWrite (chargePin, bajo);
while(analogRead(noninvertingPin) > 1) {}
timeStart = micros();
digitalWrite (chargePin, HIGH);
while(!digitalRead(triggerPin)) {if((micros()-timeStart)>5000000) break;}
timeEnd = micros();
timeDelta = timeEnd-timeStart;
capacitancia en nanoFarads
capacitancia = (-1*((timeDelta*1000)/((log((1000000-(1000000*analogRead(invertingPin)/1024)))-log(1000000))*constRes)));
}
void testInductance () {}
digitalWrite (chargePin, bajo);
while(analogRead(noninvertingPin) > 1) {}
timeStart = micros();
digitalWrite (chargePin, HIGH);
while(digitalRead(triggerPin)) {if((micros()-timeStart)>5000000) break;}
timeEnd = micros();
timeDelta = timeEnd-timeStart;
inductancia en nanoHenrys
la inductancia = (-1*((1000*timeDelta*constRes)/(log(1000000*analogRead(invertingPin)/1024)-log(1000000)));
}
void testResistance () {}
digitalWrite (chargePin, HIGH);
Delay(100);
resistencia = (float(analogRead(noninvertingPin))*100)/(1024-float(analogRead(noninvertingPin)));
}
void testFrequency () {}
frecuencia = pulseIn (triggerPin, HIGH);
frecuencia += pulseIn (triggerPin, bajo);
frecuencia = 1/frecuencia;
}