Go Down

Topic: if value has changed less than 2 (Read 192 times) previous topic - next topic

boelle

so I'm building this weather station thing for mominlaw and its working reasonable good

doing some long-term testing I have found that the radio connection can get some false values that make to go crazy like adding 4000 mm of rain in one hour and no I don't live in a rainforest :-P


I thought that the problem only happens once in a while and it must be a disturbance from another transmitter around where I live and I have no control over it


currently i update the display this way:

if (remoteHours != previousRemoteHours)
  {

my thought was expanding it to only update if the change in value is less than 2

that goes for every value in date and clock and the rain count as it would not be able to tip more than one time during a transmission of values.. not even if I put a whole cup of water in the rain gauge

how do i: if value has changed less than 2?

i googled for it but only got more confused

AWOL

Take the difference of two consecutive values.
If the absolute value of the difference is less than two . . .  Do or don't do your thing.

boelle

so: if (remoteHours - previousRemoteHours < 2)

or did i screw a simple task?

boelle


boelle

can i do it in this way?


if abs(remoteHours - previousRemoteHours) < 2

{

do this

}

AWOL

Quote
can i do it in this way?
The compiler won't like it like that but that's the general idea.

boelle

hehe

it might not like it, but at least a dummie like me understand it

boelle

you are right

might not like it in this case means a fail to compile


so how do i make it enough complicated that the compiler likes it?


i thought just subtracting the 2 values and do a thing if the difference was less than 2 would be simple

AWOL

Code: [Select]
if (someCondition)

Those () really make a difference.

boelle


Go Up