[code]
const int sampleWindow = 50; //a sample 50 ms long
unsigned int sample;
void setup()
{
Serial.begin(9600);
}
// put your setup code here, to run once:
void loop()
{
unsigned long startMillis=millis(); //start sample window
unsigned int peakToPeak=0; //peak to peal level
unsigned int signalMax=0;
unsigned int signalMin=1024;
//collect data
while (millis()- startMillis<sampleWindow)
{
sample=analogRead(0);
if (sample<1024) //toss out spuriousreadings
{if (sample>signalMax)
{
signalMax=sample; //save just the max levels
}
else if (sample<signalMin)
{
signalMin=sample; //save min samples only
}
}
}
peakToPeak=signalMax-signalMin; //max-min=peaktopeak
double volts=(peakToPeak*1.25)/1024;//converts to volts
Serial.println(volts);
delay(1000);
}
// put your main code here, to run repeatedly: