# Problem with looping in Processing

Hi there,

I´m working on a Energymonitor project to send Energy-data (explained here http://arduino.cc/forum/index.php/topic,51395.0.html)

Hardware: Energy sensing circuit+Arduino UNO
Software: Arduino 0022 with Firmata for UNO + Processing.

My problem is the following Processing code:
I want to calculate the average of the analog Values from A0-Pin over 3000 samples (draw-block), then calculate Current, and
Apparent Power (Scheinleistung S).
Checking the S- and w-Average values on the Serial COM, it seems like the Averaging isn´t working. I get w= 9,9,9,1,5,6,9… and so on. Almost the same code in Arduino IDE (other Post), gives a w= 8.0394,8.0239,8.2334…, so the averaging is working fine.
I´m a coding wrong? I believe it´s something simple, but I´m a mechanical engineer student trying to program

Thanks,

``````import processing.serial.*;
import cc.arduino.*;
import eeml.*;

// Definition der Variablen.................................
Arduino arduino;
float w; //analoge Wert (zw. 0 und 1023) aus die Sensorschaltung
int numberOfSamples=3000;// n=3000, Anzahl der Wiederholungen
float wsum;
float wqm;
float wkorr;// Bzw. gemittelte analoger Wert mit Korrekturfaktor
float U;// Analoge Wert entspricht eine Spannung U
float Uf=0.00488758; //Umwandlungsfaktor 5V/1023
float Uum=3.1; //Umw.faktor für Strom->Aus Datenblatt der Stromwandler CR 3110-3000
float I;// Effektive Strom
float Uleit=230;//Annahme für eff.Spannung
float S; //Scheinleistung
float lastUpdate;

DataOut dOut;

void setup()
{
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[2], 57600);

dOut = new DataOut(this, "http://api.pachube.com/v2/feeds/15963.xml" , "dc0949c55775db92f74729df0696b555daf427ad966ef3ed3a4f7447c74d8941");
}

void draw()
{
for (int i=0; i<numberOfSamples; i++)
{
}
wqm=(sqrt(wsum/numberOfSamples));

wkorr=wqm;// Hier konnte man um X-Faktor der Wert korrigieren
U= wkorr*Uf;
I=U*Uum;
S=I*Uleit;
println(S);
wsum=0;

if ((millis() - lastUpdate) > 180000){
dOut.update(0,S);
int response = dOut.updatePachube();
println(response);
lastUpdate = millis();

}

}