mark.duyvesteyn
Member
I posted a while ago about making a foaling alarm for a horse. Below is the code im using. I read about clock the speed of the 08m down to save on power, how would i go about doing this? Also any one got any ideas on how to compress the program some what, ive use the whole memory of the chip and still need to add a few lines of code!! Also is the disablebod / enablebod used correctly, will it have any significant effect?
thanks for any help.
-------------------------
The reset sequence clears the last missed calls from the phone which the pic is connected too. The ring sequence dials and hangs up the last two missed calls.
thanks for any help.
Code:
'Foaling alarm.
'when a horse gives birth, it lies on its side. This code detects this by using
'mercury switches. after about 30 seconds the picaxe will control three small
'relays which simulates pressing the 'attached nokia phones buttons. The
'Phone will ring and hang up the last two missed calls, This 'makes for easy
'set up. A reed switch is fitted, which when activated by a magnet will run a
'reset routine that will clear the last missed calls.
'pin 1 = controls the down button on the phone
'pin 2 = controls the select button on the phone
'pin 0 = controls the power button on the phone
'pin 4 = reed switch input
'pin 3 = mercury switch input
main:
sleep 3 'held in a sleep state for power conservation. Checks the
'reed switch and the mercury switch every 6 seconds.
for B1 = 1 to 10 ' if mercury switch is constant for 23 seconds then 'start ring sequence.
if Pin4 = 1 then goto reset 'reed switch for resetting the alarm.
if Pin3 = 0 then goto main go back to main if mercury switch is not active.
sleep 1
Next B1
goto Ring
Reset:
'first check to make sure the reed switch is still active then tun the
'phone on and cycle through the menu to reset the last missed
'calls,and leave the phone on to allow new "missed calls" to be set up
if pin4 = 0 then goto main
high 0
sleep 1
low 0
sleep 5
gosub select1
gosub down
gosub select1
for B3 = 1 to 3
gosub down
next B3
for B4 = 1 to 2
gosub select1
next b4
pause 1000
gosub powershort
sleep 100
gosub powerlong
goto main
ring:
'goes through the process of ringing the last missed call
'and hanging up, it then goes to the next missed call.
'a delay of ten minutes is added before it starts check
'the mercury switches again.
gosub powerlong
gosub select1
gosub down
for B4 = 1 to 3
gosub select1
next B4
for B5 = 1 to 7
gosub down
next B5
gosub select1
sleep 3
for B6 = 1 to 2
gosub powershort
sleep 1
next B6
'ring the next number in the missed calls list.
gosub select1
'down
high 1
pause 100
low 1
pause 100
'select1: 'have run out of subroutines (16 max),
for B6 = 1 to 2 'have to do it manually
high 2
pause 100
low 2
pause 100
next B6
'down:
high 1
pause 100
low 1
pause 100
'select1:
high 2
pause 100
low 2
pause 100
'down:
for B7 = 1 to 7
high 1
pause 100
low 1
pause 20
Next B7
'select1:
high 2
pause 100
low 2
pause 100
sleep 3
high 0
sleep 1
low 0
sleep 240
goto main
'sub routines - these simulate pressing the buttons. Power
'long is a long hold to turn the phone 'on and off.
'Power short just takes it back to the home page.
down:
high 1
pause 100
low 1
pause 100
return
select1:
high 2
pause 100
low 2
pause 100
return
powershort:
high 0
pause 100
low 0
pause 100
return
powerlong:
high 0
sleep 1
low 0
sleep 5
return
The reset sequence clears the last missed calls from the phone which the pic is connected too. The ring sequence dials and hangs up the last two missed calls.
Last edited: