Help on a project I'm working on
Hi,
I'm in need of a bit of help on a project that I'm working on and was wondering if anyone here can help. I'm trying to make a pill reminder. You know, something connected to a 7-day pill box and an alarm system that would sound and flash LEDs [noparse][[/noparse]possibly display a message on an LCD too] if the corresponding day's box is not opened on time. I'm using a parallax BS2p24 chip and all of the other parts that I'm using came from parallax as well. I've already written the code for the speaker and LEDs [noparse][[/noparse]I've determined the frequencies and "pause" times]. Currently I'm trying to get the timer portion set up. I'm using a DS1302 chip and I found some threads about it, but I was wondering if anyone knows if I am able to use the chip as an input for the controller. My idea overall is to have switches attached to each day's box and have the clock running so that for example, if the person was supposed to take the pill at 10:30am each day, then when 10:30 comes around on Sunday and the box isn't opened [noparse][[/noparse]switch would still be closed] then a "warning" alarm would sound but if the box was opened correctly [noparse][[/noparse]switch opened] then a "good job" alarm would sound. So you see, I need the clock to be an input for the controller so that the it would "know" what time it is and appropriately signal the alarm.
Please, any help that you can provide would be greatly appreciated.
I'm in need of a bit of help on a project that I'm working on and was wondering if anyone here can help. I'm trying to make a pill reminder. You know, something connected to a 7-day pill box and an alarm system that would sound and flash LEDs [noparse][[/noparse]possibly display a message on an LCD too] if the corresponding day's box is not opened on time. I'm using a parallax BS2p24 chip and all of the other parts that I'm using came from parallax as well. I've already written the code for the speaker and LEDs [noparse][[/noparse]I've determined the frequencies and "pause" times]. Currently I'm trying to get the timer portion set up. I'm using a DS1302 chip and I found some threads about it, but I was wondering if anyone knows if I am able to use the chip as an input for the controller. My idea overall is to have switches attached to each day's box and have the clock running so that for example, if the person was supposed to take the pill at 10:30am each day, then when 10:30 comes around on Sunday and the box isn't opened [noparse][[/noparse]switch would still be closed] then a "warning" alarm would sound but if the box was opened correctly [noparse][[/noparse]switch opened] then a "good job" alarm would sound. So you see, I need the clock to be an input for the controller so that the it would "know" what time it is and appropriately signal the alarm.
Please, any help that you can provide would be greatly appreciated.

Comments
Rick
The ds1302 is a pretty good time keeper and Chris Savage has a demo program which will exercise every aspect of the chip. I think the demo program is on the Resources section of the Parallax site.
One technique for a job such as yours is to just count minutes, starting at, say, Sunday at 12:01 AM. Seven days of minutes is 10080 minutes, so is an easy number to work with in a Word variable.
As time passes, you know that 10:30 each day will occur at 630 minutes on Sunday, 2070 minutes on Mon, 3510 minutes on Weds, etc, etc. Reset to zero on Saturday at 12 midnight and repeat.
You could also use the clock's ability to tell the day of the week and just watch for the appropriate time to roll around.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
The logic for checking if the pill has been taken isn't too rough. It might look something like this in pseudo-code:
pillsTaken VAR Byte ' each bit position is a flag for whether or not the pill was taken that day... Main: GOSUB GetTimeAndDate ' not shown, but returns hour, minute, dayOfWeek (0-6 with 0 = sunday), etc., from DS1302 or similar IF pillsTaken.BIT0(dayOfWeek) = 0 THEN ' flag for this day not set!!!!!! better check it IF ( hour > 7 AND minute > 30 ) OR ( hour >= 8 ) THEN ' if 7:30 or later, take the pill! ' sound alarm!!!! GOSUB Make_Loud_Beep IF switch = 0 THEN ' active low switch, check it and see if they did it! pillsTaken.BIT0(dayOfWeek) = 1 ' they did, so set flag ENDIF ENDIF ENDIF IF dayOfWeek = 0 AND hour = 0 AND minute <= 1 THEN ' at first minute of day on sunday, reset the flags pillsTaken = 0 ENDIF GOTO MainIf you get that, then you could extend it a bit by setting custom times for each day, or lighting an LED that corresponds to the correct day's pill compartment:
compartmentLeds VAR OUTL ' pins 0-7 with leds hooked up to pins 0-6; one for each compartment pillsTaken VAR Byte ' each bit position is a flag for whether or not the pill was taken that day... Start: DIRL = $FF ' all outputs for leds Main: GOSUB GetTimeAndDate ' not shown, but returns hour, minute, dayOfWeek (0-6 with 0 = sunday), etc., from DS1302 or similar IF pillsTaken.BIT0(dayOfWeek) = 0 THEN ' flag for this day not set!!!!!! better check it IF ( hour > 7 AND minute > 30 ) OR ( hour >= 8 ) THEN ' if 7:30 or later, take the pill! ' sound alarm!!!! GOSUB Make_Loud_Beep compartmentLeds.BIT0(dayOfWeek) = ~compartmentLeds.BIT0(dayOfWeek) ' blink the led IF switch = 0 THEN ' active low switch, check it and see if they did it! pillsTaken.BIT0(dayOfWeek) = 1 ' they did, so set flag ENDIF ENDIF ELSE compartmentLeds.BIT0(dayOfWeek) = 0 ' make sure LED is off ENDIF IF dayOfWeek = 0 AND hour = 0 AND minute <= 1 THEN ' at first minute of day on sunday, reset the flags pillsTaken = 0 ENDIF GOTO Main▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php