Created
May 28, 2014 20:23
-
-
Save beydogan/b4226dda3a95f80cb358 to your computer and use it in GitHub Desktop.
getSensorValues ACS712 - not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void getSensorValues(){ | |
unsigned long currentAcc = 0; | |
unsigned int count = 0; | |
unsigned long prevMicros = micros() - sampleInterval ; | |
while (count < numSamples) | |
{ | |
if (micros() - prevMicros >= sampleInterval) | |
{ | |
int adc_raw = analogRead(0) - adc_zero; | |
currentAcc += (unsigned long)(adc_raw * adc_raw); | |
++count; | |
prevMicros += sampleInterval; | |
} | |
} | |
float rms = sqrt((float)currentAcc/(float)numSamples) * (75.7576 / 1024.0); | |
mySerial.println(rms); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment