PDA

View Full Version : Help with scheduling program

MacGeek117
01-18-2008, 11:43 PM
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!"

www.parallax.com (http://www.parallax.com/)
www.goldmine-elec.com (http://www.goldmine-elec.com)
www.expresspcb.com (http://www.expresspcb.com)
www.jameco.com (http://www.jameco.com)

mynet43
01-19-2008, 12:40 AM
I think you'll get what you want if you do it this way:

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

Jim

Ken Peterson
01-19-2008, 12:43 AM
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[@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.

mynet's approach should work too.

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

The more I know, the more I know I don't know.· Is this what they call Wisdom?

deSilva
01-19-2008, 01:25 AM
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[ idx] == 15 ' the hour
temperature := sunday[ idx+1]
pc.dec(temperature)
quit

MacGeek117
01-20-2008, 05:41 AM
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:)
RoboGeek

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

www.parallax.com (http://www.parallax.com/)
www.goldmine-elec.com (http://www.goldmine-elec.com)
www.expresspcb.com (http://www.expresspcb.com)
www.jameco.com (http://www.jameco.com)

deSilva
01-20-2008, 06:18 AM
Do you understand the difference between dSilva's code and Mynet's code???

MacGeek117
01-21-2008, 07:51 AM
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!"

www.parallax.com (http://www.parallax.com/)
www.goldmine-elec.com (http://www.goldmine-elec.com)
www.expresspcb.com (http://www.expresspcb.com)
www.jameco.com (http://www.jameco.com)

mynet43
01-21-2008, 10:29 AM
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

MacGeek117
01-22-2008, 04:47 AM
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!"

www.parallax.com (http://www.parallax.com/)
www.goldmine-elec.com (http://www.goldmine-elec.com)
www.expresspcb.com (http://www.expresspcb.com)
www.jameco.com (http://www.jameco.com)
·

mynet43
01-23-2008, 06:41 AM
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[idx]
if time == _time
sunday[++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 Peterson
01-23-2008, 08:53 PM
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[idx] == _time
temps[idx] := temp
return

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

The more I know, the more I know I don't know.· Is this what they call Wisdom?

MacGeek117
01-25-2008, 10:18 AM
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!"

www.parallax.com (http://www.parallax.com/)
www.goldmine-elec.com (http://www.goldmine-elec.com)
www.expresspcb.com (http://www.expresspcb.com)
www.jameco.com (http://www.jameco.com)
·

mynet43
01-26-2008, 04:11 AM
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[_time*2+1] := temp

You don't even need the return.

In fact, you probably don't even need the subroutine :)

Jim

Lawson
01-26-2008, 10:33 AM
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 :D 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?

MacGeek117
01-26-2008, 10:37 AM
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!"

www.parallax.com (http://www.parallax.com/)
www.goldmine-elec.com (http://www.goldmine-elec.com)
www.expresspcb.com (http://www.expresspcb.com)
www.jameco.com (http://www.jameco.com)
·

MacGeek117
01-26-2008, 10:55 AM
Unfortunately, my program isn't writing the EEPROM.
RoboGeek

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

www.parallax.com (http://www.parallax.com/)
www.goldmine-elec.com (http://www.goldmine-elec.com)
www.expresspcb.com (http://www.expresspcb.com)
www.jameco.com (http://www.jameco.com)

Paul Baker
01-26-2008, 11:27 AM
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 (mailto:pbaker@parallax.com)
Propeller Applications Engineer
[/url][url=http://www.parallax.com] (http://www.parallax.com)
Parallax, Inc. (http://www.parallax.com)

MacGeek117
01-26-2008, 12:09 PM
Thank you, Paul! It works! Sweet to the nth power!
Roboeek

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