Why is all the time zero 0

Hi
VmsTotal - why is all the time zero 0

int Vms;
void setup() {
  Serial.begin(115200);
}

void loop() {

  static long VmsTotal = 0;
  static int VmsCount = 0;

for (int i = 0; i < 360; i += 5) {
    float y = 5 * sin(i * M_PI / 180);

    Serial.print( " y = "); Serial.print(y);
    if (y > 2)
    {
      VmsTotal += Vms;
      VmsCount++;

      Serial.print( "  Vms = "); Serial.print(4);
      Serial.print( "   VmsCount = "); Serial.print( VmsCount);// p
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      Serial.print( "   VmsTotal = "); Serial.print( VmsTotal);// why is zero   0 
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    }
    else
    {
      VmsCount = 0;
      VmsTotal = 0;

      Serial.print( "  Vms = "); Serial.print(1);
      Serial.print( "    VmsCount = "); Serial.print( VmsCount);//p
      Serial.print( "   VmsTotal = "); Serial.print( VmsTotal); //     zero = ok
    }
    Serial.println();

    delay(50);
  }
}

try this

float y = 5.0 * sin(i * M_PI / 180.0);`

int Vms;
.....
VmsTotal += Vms;

Vms is never changing, so VmsTotal will always be 0.

Try Vms = 1;
and you will see that VmsTotal changes.

= no changes

Thanks it is working

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.