need to store a value

This is a discussion on need to store a value within the C Programming forums, part of the General Programming Boards category; ok I've got this problem that is driving me crazy. (noob here) I have two temperature sensors. #1 and #2 ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    11

    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

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    11
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to store it
    By zcrself in forum C Programming
    Replies: 4
    Last Post: 08-18-2009, 11:35 PM
  2. store pi O.o;
    By adr in forum C++ Programming
    Replies: 17
    Last Post: 10-30-2006, 04:35 AM
  3. store data from ifstream and store in link list
    By peter_hii in forum C++ Programming
    Replies: 2
    Last Post: 10-26-2006, 08:50 AM
  4. how should i store these?
    By Waldo2k2 in forum C++ Programming
    Replies: 8
    Last Post: 07-10-2002, 02:10 PM
  5. Do you store store one off data arrays in a class?
    By blood.angel in forum C++ Programming
    Replies: 5
    Last Post: 06-24-2002, 12:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21