This is my first Arduino project and I've never programmed before so some help would be much appreciated...
I'm reading three AC voltages and trying to average them out. The code below should only return positive numbers as I have used the ABS command, but I'm still getting negative numbers in the mix. What am I doing wrong?
const int numReadings = 50;
int bluetotal = 0; // the running total
int redtotal = 0; // the running total
int greentotal = 0; // the running total
int red = A0;
int green = A1;
int blue = A2;
void setup()
{
// initialize serial communication with computer:
Serial.begin(9600);
}
void loop() {
// Take average of red blue and green
for (int count = 0; count < numReadings; count++) {
bluetotal += abs(analogRead(blue));
greentotal += abs(analogRead(green));
redtotal += abs(analogRead(red));
}
// send it to the computer as ASCII digits
Serial.print(bluetotal/numReadings);
Serial.print(" ");
Serial.print(redtotal/numReadings);
Serial.print(" ");
Serial.println(greentotal/numReadings);
}