How to code a rolling time period?
wolff
Posts: 43
I’m having trouble coming up with code to perform the following function. I have a BS1 and I want it to look for an event. If the event occurs more then 3 times over a rolling 6 hour period then an alarm will go off… until the event occurs less then 3 times in the 6 rolling hours.
I don’t need the exact code just a push in the right direction.
Thanks,
J
I don’t need the exact code just a push in the right direction.
Thanks,
J
Comments
Is it fair to presume that by "rolling 6 hour period" you are speaking of any of the 4 x 6 hour segments of a 24 hour day, or is there something more to it than that?
If you aren't "locked in" to a BS-1 I would suggest using a BS-2 unless you are quite familiar with PBASIC programming on the BS-1 and recognize its limitations, and how to overcome some/many of them.
Is it also fair to presume that you were planning to use an RTC (real time clock)?
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
The first thing you would need to do is attach a real time clock RTC such as the DS1302 to your basic stamp so that you can get the actual time. You can use timing loops on the Stamp for rough timing but it is not acurate over a long period.
The first time the questionable event happens, you will record the time it happened. The second time it happens, record time again and compare to first. If 6 hours have elapsed, replace first time value with second, otherwise keep going. The next time it happens, compare with 1st and if less than 6 hrs, do alarm, otherwise replace 1st with second, 2nd with 3rd et al.
Once the alarm has been activated, set a bit to keep track of that. Reverse the logic to decide when to shut off the alarm.
Boy this reminds me of when I was a kid trying to learn how to score bowling. "Dad how can I add the next 2 balls when I haven't bowled that frame yet?"
Lee
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
That's just the push I needed. (555, why didn't I think of that???)
J