Page:1

# TOPIC:

## [OT] Help needed with Arduino-style "C" 27 Oct 2019 21:28 #11469

 FFF Topic Author Posts: 976 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 Replace with If (TuWas) all works. While at it: If i need the equality compare, how can i avoid this side effect? Regards Karl (X# 2.5b; Xide 1.25; W8.1/64 German) Please Log in or Create an account to join the conversation. Last edit: by FFF.

## [OT] Help needed with Arduino-style "C" 27 Oct 2019 22:21 #11470

 lumberjack Posts: 688 Karl,Karl Faller wrote: EDIT: Solved. In the ellipsis (...) part i had: If (TuWas = HIGH); which seems to not only compare, but also assign 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" 27 Oct 2019 22:32 #11471

 FFF Topic Author Posts: 976 I have to tinker only rarely (> years) with this, so i better wrote it down for reference Thx, Johan! Regards Karl (X# 2.5b; Xide 1.25; W8.1/64 German) Please Log in or Create an account to join the conversation.

## [OT] Help needed with Arduino-style "C" 27 Oct 2019 22:41 #11472

 lumberjack Posts: 688 Karl, Yes gets confusing when you then try VFP syntax mode, where = means ":=" and "==" or is it or...``` a = b // This is assign apparently ? b = c // This is compare apparently a = b = c // This I think means a := (b == c) ```______________________ 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" 28 Oct 2019 09:08 #11484

 FFF Topic Author Posts: 976 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 (X# 2.5b; Xide 1.25; W8.1/64 German) Please Log in or Create an account to join the conversation.

## [OT] Help needed with Arduino-style "C" 28 Oct 2019 09:18 #11485

 lumberjack Posts: 688 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" 28 Oct 2019 09:57 #11486

 Terry Posts: 184 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" 28 Oct 2019 11:08 #11488

 lumberjack Posts: 688 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" 28 Oct 2019 12:54 #11489

 FFF Topic Author Posts: 976 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 (X# 2.5b; Xide 1.25; W8.1/64 German) Please Log in or Create an account to join the conversation.

## [OT] Help needed with Arduino-style "C" 28 Oct 2019 12:54 #11490

 FFF Topic Author Posts: 976 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 (X# 2.5b; Xide 1.25; W8.1/64 German) Please Log in or Create an account to join the conversation.

## [OT] Help needed with Arduino-style "C" 05 Dec 2019 14:18 #12098

 Phil Hepburn Posts: 743 hi guys, back after a long break ;-0) its the same as in Python - the single and double equals signs. am now looking into Python and am writing an eBook as I go - for any who may be interested in the future. have made plenty of wood working projects in my time off programming. all the best, Phil. Please Log in or Create an account to join the conversation.
 Page:1