const debugOn as boolean = true const SWITCH as byte = 12 const MOTOR as byte = 13 const RESTTIME as byte = 1 ' for minutes const MAXCRYTIME as single = 30.0 ' for seconds dim runMotor as boolean dim resting as boolean dim msg as string dim beginRest as byte dim napTime as byte dim beginCry as single dim cryTime as single dim Hour as Byte, Minute as Byte, Second as Single sub main() ' start out crying resting = false ' start cry time call GetTime(Hour, Minute, Second) beginCry = Second ' cry setMotor(1) do ' get time crying so far call GetTime(Hour, Minute, Second) cryTime = Second - beginCry if (getPin(SWITCH) = 1) then msg = "button down" if (debugOn) then debug.print msg end if ' go into resting call goRest(RESTTIME) ' elseif (cryTime >= MAXCRYTIME) then ' msg = "take a break" ' if (debugOn) then ' debug.print msg ' end if ' call goRest(1) ' ' else 'keep on cryin end if loop end sub sub goRest(byVal finishTime as byte) resting = true call GetTime(Hour, Minute, Second) beginRest = Minute setMotor(0) do while (resting) call GetTime(Hour, Minute, Second) napTime = Minute - beginRest msg = "we are resting. zzz" ' check if naptime is over if( napTime >= finishTime) then resting = false ' set crying time call GetTime(Hour, Minute, Second) beginCry = Second cryTime = 0.0 ' start crying setMotor(1) msg = "waking up." end if if (debugOn) then debug.print msg end if delay(5.0) loop end sub sub setMotor(byVal state as byte) if(state = 0) then ' turn off motor call putPin(MOTOR, 0) runMotor = false msg = "motor off" elseif (state = 1) then ' turn on motor call putPin(MOTOR, 1) runMotor = true msg = "motor on" else 'bad input end if if(debugOn) then debug.print msg end if end sub