Newbie Help Needed! Inactivity timeout code w/ DS1302
shgarshane
Posts: 4
Im am new to Basic programming, minus a brief semester in in high school.
' {$STAMP BS2}
{$PBASIC 2.5}
I plan to use the demo code and RTC DS1302 at the following link: http://forums.parallax.com/showthread.php?77867-DS1302-Demo-Code-(Updated)
I am trying to write a program that uses a real-time-clock to perform an action 3 times each day. (turn lights on) I believe that I can figure out the programming for this action but I am having trouble trying to figure out a way to pause the program when there is no one in the home. I plan to connect a micro switch to the door which will send a signal to the stamp, letting it know that someone is home and to resume the program. But if no signal is received within three hours of the next time the lights are to go on then I want the program to pause until the next time it receives a signal. I think the name of this type of program is an inactivity timeout?
Any help would be greatly appreciated!!!
' {$STAMP BS2}
{$PBASIC 2.5}
I plan to use the demo code and RTC DS1302 at the following link: http://forums.parallax.com/showthread.php?77867-DS1302-Demo-Code-(Updated)
I am trying to write a program that uses a real-time-clock to perform an action 3 times each day. (turn lights on) I believe that I can figure out the programming for this action but I am having trouble trying to figure out a way to pause the program when there is no one in the home. I plan to connect a micro switch to the door which will send a signal to the stamp, letting it know that someone is home and to resume the program. But if no signal is received within three hours of the next time the lights are to go on then I want the program to pause until the next time it receives a signal. I think the name of this type of program is an inactivity timeout?
Any help would be greatly appreciated!!!
Comments
Your program would have two loops where it would check the door sensor. In one loop, it would wait for the door sensor to go on. This loop represents someone being at home, waiting for them to leave. If the sensor goes on, the program does a GOTO to the other loop. The second loop also waits for the door sensor to go on. This loop represents no one at home, waiting for them to arrive. If the sensor goes on, the program does a GOTO to the first loop. Inside the second loop, the program reads the RTC and compares the time to one of three values and turns the lights on if there's a match. Presumably there's some other set of values for turning the lights off.
If you want an "inactivity" timer instead, you'd have one loop that tests the door sensor and reads the RTC. If the door sensor goes on, the RTC value is saved as the "time of the last activity". Every time through the loop, the program subtracts the saved RTC value from the current RTC value (adjusting for different days). If the result is greater than 3 hours, the program compares the current time to the 3 times when an action should be done. If any of the comparisons match, the program turns the lights on. Presumably, there are other times when the lights should be turned off.
Thank you so much for the help! I was wondering if you could take a look at the attached code and see if it would work? I try debugging and keep getting an error when it gets ELSE and the ENDIF statement in the following:
Run_Door:
IF door = 1 THEN lastactive = hrs
IF (((hrsA = hrs) AND (minsA = mins) AND (secsA = secs)) OR ((hrsB = hrs) AND (minsB = mins) AND (secsB = secs)) OR ((hrsC = hrs) AND (minsC = mins) AND (secsC = secs))) AND (hrs - lastactive <= 4) THEN
GOSUB Run_Lights ' Run lights program
ELSE
ENDIF
ELSE
ENDIF
RETURN
Run_lights:
HIGH light ' Turn on motor to feed
PAUSE
3000 ' keep lights on for "3 secs" amount of time needed
LOW light ' Turn off lights
RETURN
I'm unsure what to edit in order to correct this problem...
One thing you should do is get the Scott Edwards book on Basic Stamps, were he shows an application with code using a RTC.
If you provide your whole code we can show you where your problems are.
This is short hand and does not require an ENDIF
You want
Or
bsnut,
Thank you for the motivational assistance, and i will definitely check out the book.
The code that I currently have is based on Chris Savage's code for the ds1302...
Mike G,
Thank you! This worked perfectly! i didn't know that there was a shorthand version of this code as well! For peace of mind, how would one use this shorthand if they are doing multiple loops like the one that i tried to do? or is it not an action that can be performed???
I am sure that I will be back often throughout the next few months to ask many more questions on this code. Thank you again