Shop OBEX P1 Docs P2 Docs Learn Events
How to code a rolling time period? — Parallax Forums

How to code a rolling time period?

wolffwolff Posts: 41
edited 2006-05-10 23:31 in BASIC Stamp
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

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-05-10 12:59
    wolff -

    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 -->
  • Lee HarkerLee Harker Posts: 104
    edited 2006-05-10 13:09
    Wolff,
    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?" smhair.gif

    Lee
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-10 14:00
    Way back when I first started with the BS1 I wrote a program for a guy who had a private airport and wanted to use microphone "clicks" to enable runway lights and open a hanger door.· The program attached does that -- you might find something useful.· What we used was a 555 in one-shot mode as a pulse input stretcher so that the BS1 wouldn't miss the input.· The BS1 is able to reset the 555 after seeing the pulse.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • wolffwolff Posts: 41
    edited 2006-05-10 23:31
    Thanks Jon,
    That's just the push I needed. (555, why didn't I think of that???)
    J
Sign In or Register to comment.