Good day everyone! I just wanted to ask how can I indicate an increasing value using an "if" statement. For example, if (value is increasing) {do this}. By the way, I'm going to use this for controlling the connectivity of my load to a battery, I want to automatically disconnect my load as the charge of my battery runs out and reconnect it if there's already enough charge. So I just wanted know what is the best way to do it. Thanks in advance for your help. God bless everyone
Something like this.
If the 'current value' is > than the 'last value' {then make 'last value' = the 'current value' . . . }
.
Thank you sir☺. Using this command I can monitor if it is increasing or decreasing, but my another problem is that there is an instances that the 'last value' is equal to the 'current value' by that how can I determine if it is increasing or decreasing?
if you only remember the last value, then you can't... so either remember more than one, of just assume the trend continued until proven wrong.
Thank you sir JML
if you want to track/act based what the last actual change was, you need to do a little more work
try something like this:
if (curr != prev)
{
trend = curr - prev;
}
if (trend > 0)
{
// item is increasing
}
else if (trend <0)
{
// item is decreasing
}
else
{
// no trend ever identified
}
prev = curr;
Thanks sir wgoz , I'll going to try it.
You might want to factor in time. Processors go really fast so a battery charge may "look" like continental drift. You may not notice any real trends.
-jim lee
Thanks sir jim☺. Maybe I can do this by setting proper the timer delay ?
riveraraymond3535:
Thanks sir jim☺. Maybe I can do this by setting proper the timer delay ?
That would be a start, but its not the path you want to take.
Think more along along the lines of a notebook, watch and a pencil. Note down the time you took the reading and when you'd like to take the next reading. You don't want to stand in the middle of the highway looking at your watch.
-jim lee
Thank you again sir jim
there is an instances that the 'last value' is equal to the 'current value' by that how can I determine if it is increasing or decreasing?
If the last and current values are the same then surely it is neither increasing or decreasing but you will detect the direction when the next change takes place.
To get a measure of how much it has changed subtract the last value from the current value and comparing that to a some threshold value.
If you use the abs() function then you can look for either an increase or decrease with a single statement.