-
need to store a value
ok I've got this problem that is driving me crazy. (noob here)
I have two temperature sensors. #1 and #2
I want to read #1, then store the value.
Then, for the next 30 minutes, I want to continuously read #2 and compare its fluctuating value with the fixed value of #1. So, say, every time #2 gets below the stored value of #1, do X.
Then, after 30 minutes, I take a new reading of #1 and do the same comparing for the next half-hour. And so on.
My problem is that I don't know how to 'store' the value while the other one keeps on being updated. There must be a way to implement a timer of sorts, I am using an Arduino board to do this stuff, I tried to make a timer using millis() but hey, I just keep reseting it at every iteration of the loop, it's no good : (
I'm in total darkness for now, if anyone could point me in a direction...
thanks
-
You use = to store a value into a variable. Not sure what sort of timing you've got on the chip, but if you move it outside the loop, you probably will solve your resetting it inside the loop problems.
-
Code:
while not done
val1 = read val1
for thirty minutes
val2 = read val2
if val2 < val1
do thing
Just put it into actual words what you plan on doing, then turn each step into a step in pseudo-code. When you can't make the steps any simpler, it's time to turn it into actual code.
Quzah.
-
The idea of creating another function out of the loop seems nicely logic, I will put my needs in pseudo-code and give it a try, give me a few days and I'll tell you how it went.