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);
}
}