Created
January 25, 2013 19:22
-
-
Save anonymous/4637055 to your computer and use it in GitHub Desktop.
rolling average with intermittent off by one
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
#define digitalvaluesize 50 | |
int digitalVoltage[digitalvaluesize]; // array for storing Voltage ADC values | |
int digitalMinusVoltage[digitalvaluesize]; // array for storing MinusVoltage ADC values | |
int digitalACAmps[digitalvaluesize]; // array for storing ACAmps ADC values | |
int digitalMinusAmps[digitalvaluesize]; // array for storing MinusAmps ADC values | |
int digitalvalueindex = 0; // where are we in the indices | |
unsigned long digitalvalueadder; //this is used to sum each array before division | |
void getVoltages(){ | |
digitalVoltage[digitalvalueindex] = analogRead(voltPin); | |
digitalMinusVoltage[digitalvalueindex] = analogRead(minusVoltPin); | |
digitalACAmps[digitalvalueindex] = analogRead(ACAmpsPin); | |
digitalMinusAmps[digitalvalueindex] = analogRead(MinusAmpsPin); | |
if (++digitalvalueindex >= digitalvaluesize) digitalvalueindex = 0; | |
digitalvalueadder = 0; | |
for(int adder = 0 ; adder < digitalvaluesize; adder++) { | |
digitalvalueadder += digitalVoltage[adder]; | |
}; | |
voltage = digitalvalueadder / digitalvaluesize / voltCoeff; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment