Shop OBEX P1 Docs P2 Docs Learn Events
Help with scheduling program — Parallax Forums

Help with scheduling program

MacGeek117MacGeek117 Posts: 747
edited 2008-01-26 05:09 in Propeller 1
I'm trying to automate my home, and one aspect of this is a thermostat that I am building from scratch. I'm trying to come up with a way to schedule different temps at different times. I have 24 time slots (one for each hour).
I'm trying to get my Prop to output the right value. It should read the time until it reaches 15 (3p.m.) then output the temp (70). It is outputing 33.
Help?
RoboGeek

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I reject your reality and subsitute my own!"

Adam Savage, Mythbusters
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.jameco.com

Comments

  • mynet43mynet43 Posts: 644
    edited 2008-01-18 17:40
    I think you'll get what you want if you do it this way:

      repeat idx from 0 to 47
        time := sunday[noparse][[/noparse]idx]
        if time == 15
          idx++
          value := sunday[noparse][[/noparse]idx]
          pc.dec(value)
          quit
    
    
    



    Also, in the if statement, you had := instead of ==.

    Jim
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-01-18 17:43
    I'm thinking of doing exactly what you are doing. I'm waiting to see if I can get my hands on a touch screen real cheap before I begin.

    I think you need to use BYTE[noparse][[/noparse]@sunday + idx] to get the byte at the address calculated by @sunday+idx. I think you're getting the address itself and the low byte of that address is probably 33.

    [noparse][[/noparse]edit] mynet's approach should work too.[noparse][[/noparse]/edit]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-18 18:25
    RoboGeek: What you most likely want to do is to look at each second value (containing the hour), and getting the byte after it (the temperature). That does not work the way you tried it... Have a look at this code:
      repeat idx from 0 to 46 step 2
        if sunday[noparse][[/noparse] idx] == 15            ' the hour
          temperature := sunday[noparse][[/noparse] idx+1]
          pc.dec(temperature)
          quit
    
    
  • MacGeek117MacGeek117 Posts: 747
    edited 2008-01-19 22:41
    Thanks for the help! I got it to read the schedule with mynet's code.
    Now I need help with being able to change the values.(Here's the code[noparse]:)[/noparse]
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-19 23:18
    Do you understand the difference between dSilva's code and Mynet's code???
  • MacGeek117MacGeek117 Posts: 747
    edited 2008-01-21 00:51
    Yes, and your code does work a little better, but it still doesn't write the value.
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
  • mynet43mynet43 Posts: 644
    edited 2008-01-21 03:29
    deSilva's code should be better than mine. The code I posted was designed to make the code you had work, not to optimize it.

    With deSilva's code you avoid reading the values you don't need.

    Jim
  • MacGeek117MacGeek117 Posts: 747
    edited 2008-01-21 21:47
    I do understand that, deSilva's code is more efficient and takes less time to run through the data, but I still need to know how to write new values.
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
    ·
  • mynet43mynet43 Posts: 644
    edited 2008-01-22 23:41
    I didn't understand what you were asking.

    I think this is what you want:

    PUB Set_Temp(_time, temp)
      repeat idx from 0 to 47
        time := sunday[noparse][[/noparse]idx]
        if time == _time
          sunday[noparse][[/noparse]++idx] := temp
      return
    
    



    I tried it with your code and it worked.

    Note that I didn't optimize it to read only the times, which you could do with 'repeat idx from 0 to 46 step 2'.

    I hope this helps.
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-01-23 13:53
    Seems the first byte of each pair of values is 0, 1, 2, etc. Is that static, or do you intend to change these values? Otherwise you can use the hour as an index instead of a value in the table that you have to search through.

    Another approach would be to use one table for the hours and another table for the settings. This might make your code easier to read and understand.

    PUB Set_Temp(_time, temp)
      repeat idx from 0 to 23
        if time[noparse][[/noparse]idx] == _time
           temps[noparse][[/noparse]idx] := temp
      return
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • MacGeek117MacGeek117 Posts: 747
    edited 2008-01-25 03:18
    THANK YOU GUYS!!!!! Mynet's code worked perfectly! Now, how would I go about writing the Prop's RAM back into the EEPROM to save the changes?
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
    ·
  • mynet43mynet43 Posts: 644
    edited 2008-01-25 21:11
    Since your "times" are really just integers ranging from 0 to 23, you can easily do it with one line of code:

    PUB Set_Temp(_time, temp)
      sunday[noparse][[/noparse]_time*2+1] := temp
    
    



    You don't even need the return.

    In fact, you probably don't even need the subroutine [noparse]:)[/noparse]

    Jim
  • LawsonLawson Posts: 870
    edited 2008-01-26 03:33
    RoboGeek said...
    THANK YOU GUYS!!!!! Mynet's code worked perfectly! Now, how would I go about writing the Prop's RAM back into the EEPROM to save the changes?
    RoboGeek

    heh that's an easy trick [noparse]:D[/noparse] The key thing to understand is that the propeller loads an exact copy of the EEPROM into ram on startup.

    Part one, add an I2C object that can write to the EEPROM.

    Part two, code like "writeEEPROM( @my_var, my_var)" will backup any changes. I.e. you write the value of my_var to the same location in the EEPROM that it's stored in hub-ram and the updated value magically re-appears next reset.

    Marty

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lunch cures all problems! have you had lunch?
  • MacGeek117MacGeek117 Posts: 747
    edited 2008-01-26 03:37
    What you're saying is, I can just write the data blocks back to the EEPROM without writing anything else? Sweet!
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
    ·
  • MacGeek117MacGeek117 Posts: 747
    edited 2008-01-26 03:55
    Unfortunately, my program isn't writing the EEPROM.
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-01-26 04:27
    Robogeek, did you look at Andy's eeprom datalogger example? http://forums.parallax.com/showthread.php?p=617192
    It provides examples of reading and writing to the eeprom.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • MacGeek117MacGeek117 Posts: 747
    edited 2008-01-26 05:09
    Thank you, Paul! It works! Sweet to the nth power!
    Roboeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
    ·
Sign In or Register to comment.