fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: [OT] Help needed with Arduino-style "C"

[OT] Help needed with Arduino-style "C" 2 weeks 3 days ago #11469

  FFF's Avatar Topic Author FFF Offline Posts: 738
Anyone Arduino savy here?
Variables:
int TuWas = LOW;
float tmin = 25.0;
float tmax = 28.0;


loop() calls:
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  }
  else {
    Serial.print(tempC);
    Serial.print(" C");
  }

  if (tempC < tmin) {
    TuWas = HIGH;
  }

 if (tempC > tmax) {
    TuWas = LOW;
  }

...
}

Does anyone see a reason, why the first comparison tempC < tmin gets executed, but not the tempC > tmax?

I see in output the temperature values. Initially the first comparison is true, so TuWas is set to High. But later on the temp increases above tmax, but TuWas never gets set to Low. Why?

Any help greatly appreciated!
EDIT:
Solved. In the ellipsis (...) part i had:
If (TuWas = HIGH);
which seems to not only compare, but also assign :evil:
Replace with
If (TuWas)
all works.
While at it: If i need the equality compare, how can i avoid this side effect?
Regards
Karl

Please Log in or Create an account to join the conversation.

Last edit: by FFF.

[OT] Help needed with Arduino-style "C" 2 weeks 3 days ago #11470

  lumberjack's Avatar lumberjack Offline Posts: 608
Karl,

Karl Faller wrote: EDIT:
Solved. In the ellipsis (...) part i had:
If (TuWas = HIGH);
which seems to not only compare, but also assign :evil:
Replace with
If (TuWas)
all works.
While at it: If i need the equality compare, how can i avoid this side effect?

c/c# "=" means ":=" assign
c/c# "==" means "==" aka exactly equal.  c/c# does not have the same meaning as "=" of X#
if (TuWas == HIGH)
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

[OT] Help needed with Arduino-style "C" 2 weeks 3 days ago #11471

  FFF's Avatar Topic Author FFF Offline Posts: 738
I have to tinker only rarely (> years) with this, so i better wrote it down for reference ;)
Thx, Johan!
Regards
Karl

Please Log in or Create an account to join the conversation.

[OT] Help needed with Arduino-style "C" 2 weeks 3 days ago #11472

  lumberjack's Avatar lumberjack Offline Posts: 608
Karl,

Yes gets confusing when you then try VFP syntax mode, where = means ":=" and "==" or is it or...:lol:
<VFP:On>
a = b // This is assign apparently
? b = c // This is compare apparently
a = b = c // This I think means a := (b == c)
<VFP:Off>
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

Last edit: by lumberjack.

[OT] Help needed with Arduino-style "C" 2 weeks 3 days ago #11484

  FFF's Avatar Topic Author FFF Offline Posts: 738
;)
While ages ago, Foxpro was my very first encounter with xBase-style languages, i certainly will steer clear from these shallows...
But, still better than this awful brace-hell torture of C and its descendants.
Regards
Karl

Please Log in or Create an account to join the conversation.

[OT] Help needed with Arduino-style "C" 2 weeks 3 days ago #11485

  lumberjack's Avatar lumberjack Offline Posts: 608

FFF wrote: ;)
While ages ago, Foxpro was my very first encounter with xBase-style languages, i certainly will steer clear from these shallows...
But, still better than this awful brace-hell torture of C and its descendants.

I agree, specially like in your example when they use:
if (a > b) {
    a = b;
}
// instead of
if (a > b)
{
    a = b;
}
// or
if (a > b)
{   a = b; }
else
{    }
// or 
if (a > b)
{  a = b;
}
It is just not pleasing on the eye...
IF a > b
  a := b
ENDIF
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

Last edit: by lumberjack.

[OT] Help needed with Arduino-style "C" 2 weeks 3 days ago #11486

  Terry's Avatar Terry Offline Posts: 137
Just one other point:

You are using a float in your error trap "=="
Doubles should not be used that way due to rounding errors.
The same may apply to floats. I don't know - just a guess.

Terry

Please Log in or Create an account to join the conversation.

[OT] Help needed with Arduino-style "C" 2 weeks 3 days ago #11488

  lumberjack's Avatar lumberjack Offline Posts: 608
Hi Terry,

Terry wrote: You are using a float in your error trap "=="
Doubles should not be used that way due to rounding errors.
The same may apply to floats. I don't know - just a guess.

Good point!
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

[OT] Help needed with Arduino-style "C" 2 weeks 3 days ago #11489

  FFF's Avatar Topic Author FFF Offline Posts: 738
Well, that part is not my code, came with the sensor samples... I'm not quite sure, how internally the encode the readings, the output is "digital", and one can set the resolution. Possibly "-127.00" is only an equivalent for 0x0 ;)
BTW, 10 one wire temp-sensors, shipping included, for about 2.5 €. Interesting times we live in...
Regards
Karl

Please Log in or Create an account to join the conversation.

[OT] Help needed with Arduino-style "C" 2 weeks 3 days ago #11490

  FFF's Avatar Topic Author FFF Offline Posts: 738
Well, that part is not my code, came with the sensor samples... I'm not quite sure, how internally they encode the readings, the output is "digital", and one can set the resolution. Possibly "-127.00" is only an equivalent for 0x0 ;)
BTW, 10 one wire temp-sensors, shipping included, for about 2.5 €. Interesting times we live in...
Regards
Karl

Please Log in or Create an account to join the conversation.

  • Page:
  • 1