Debugg not as expected

Hi, trying to debug part of my code and not expecting the output variables that I was expecting.

Pretty easy code, just increase a counter and calculate the output according to this counter but things not going well.

When stepp++ I got...

step....2
setPercentage...0.01
PDiverter...2.44

This should be ie. (500*(2/200))=5??

What I am missing here?

Thanks

float PGrid = 0;                       //Watts so float variable
float PDiverter = 0;                   //Watts so float variable
const uint8_t max_load_power = 500;    // Constant max load
const uint8_t totalsteps = 200;        // dimming effect
uint8_t steps = 0;                     // start step,increments of ++
float setpercentage = 0;               // to debug the PDiverter

void setup() {
  Serial.begin(9600);
}

void loop() {

  if (PGrid <= 0) {
    steps++;
    Serial.print("steps...");
    Serial.println(steps);
    setpercentage = float(steps) / totalsteps;           // even though setpercentage is float, further float variable so it can calculate the result
    PDiverter = float( max_load_power) * setpercentage;  // not sure if FLOAT needed but no calculates properly
    Serial.print("setPercentage...");
    Serial.println(setpercentage);
    Serial.print("PDiverter...");
    Serial.println(PDiverter);

    delay(1000);
  }
}

Hi, this is the monitor....

steps...1
22:10:08.583 -> setPercentage...0.00
22:10:08.617 -> PDiverter...1.22
steps...2
22:10:09.614 -> setPercentage...0.01
22:10:09.614 -> PDiverter...2.44
steps...3
22:10:10.605 -> setPercentage...0.01
22:10:10.605 -> PDiverter...3.66
steps...4
22:10:11.601 -> setPercentage...0.02
22:10:11.635 -> PDiverter...4.88

const uint8_t max_load_power = 500;    // Constant max load

That is a very big uint8_t.

You should enable warnings.

Somewhere\BadDebug\BadDebug.ino:5:32: warning: large integer implicitly truncated to unsigned type [-Woverflow]

 const uint8_t max_load_power = 500;    // Constant max load

                                ^

Thanks for you advice, I have enabled them now and working... :slight_smile:

Thanks