weird behavior of code (floats included).

I had a problem yesterday with floats that i successfully solved with the arduino forum. Now, since i removed all the debuging, the code does not work nice.

Here are the required parts:

if(millis() > ( 1000 + m2_lastDp)){

    float m2_barCalc_float = ((float)100/(m2_sampleTime*60000.00))*(millis()-m2_logStart);
    int m2_barCalc = m2_barCalc_float;
    m2_lastDp = millis();


void m2_updateDisplay(unsigned long m2_dp_intCount, unsigned long m2_dp_extCount,int m2_dpBarLevel) {
  if(m2_logDone ==false)DOG.rectangle(13,3,m2_dpBarLevel+13, 3, 255);
  if(m2_logDone ==true)DOG.string(19,3,font_8x8, "Successful!");


As you can see there are two //Serial.print

Since i removed both, the “m2_dpBarLevel” seems to be 0!

When i add them back it displays a correct value for both prints.
When i only have the second (the one that shows the “given value” to the void), it appers 0!

So the Serial seems to be doing something to that code, but i want this removed and want to understand why and what is happening!

Thank you for helping

Sorry, I cannot help you with your question. Removing Serial.print(...) and Serial.println(...) should not have the effect that you observed, although it might affect millis() and change the result slightly. Of course, I cannot see your entire program and I do not know what you have included and I do not know what Arduino you are using. For example, you could have a problem with the amount of memory used and I would not have a way to know.

However, I can tell you this...

sgt_johnny wrote (in part):

the one that shows the "given value" to the void

Actually, m2_updateDisplay(...) is a function. The word void just means that this function does not return any value. Please do not call m2_updateDisplay(...) a void. It is not. The same thing applies to the setup() function and to the loop() function.

You are mixing floating point numbers with math, which often causes and can lead to compile errors.

A snippet of code usually gets a snippet of an answer.

I discovered a post via google where someone tried to make a % too.

I have fixed this now with map();

Seems like map is somewhat making percent directly.

int m2_barCalc = map(m2_currentTime,0,m2_sampleTime,0,100);