Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
int diffAnalogRead(){
int readA[6], minA, maxA;
int readB[6], minB, maxB;
for (int i = 0; i < 6; i++) {
if (i % 2 == 0) {
readA[i] = analogRead(CLK_PIN);
}
readB[i] = analogRead(DIN_PIN);
if (i % 2 == 1) {
readA[i] = analogRead(CLK_PIN);
}
if (i == 0) {
maxA = minA = readA[0];
maxB = minB = readB[0];
}
maxA = max(maxA, readA[i]);
minA = min(minA, readA[i]);
maxB = max(maxB, readB[i]);
minB = min(maxB, readB[i]);
}
int sumA = readA[0] + readA[1] + readA[2] + readA[3] + readA[4] + readA[5] - maxA - minA;
int sumB = readB[0] + readB[1] + readB[2] + readB[3] + readB[4] + readB[5] - maxB - minB;
return (sumA - sumB) / 4;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.