' Demo PWM "Heartbeat/breathing " PICAXE-08 April.03 SiChip Ver 1.2 9th March.03 ' Best assembled & tested with solderless "PICNIK" box as detailed SiChip Feb.03 ' Refer http://picaxe.orcon.net.nz for background info & potential of PICAXE-08 ' MORE RELIABLE OPERATION REPORTED FROM 5V OR LESS (4.5V ?) 6V MAY BE TOO HIGH ? ' REF http://picaxe.orcon.net.nz/optocalc.jpg for a modified calculator counter ! ' ***************************************************************************** ' Extra parts = 100k NTC thermistor (DSE R-1895),Red LED, 1 x 15k ,1 x 330 Ohm ' NTC can be moved off board, but water proof(epoxy/hot melt glue ?)if outdoors ' New commands here = PWM , SOUND 255 (=hiss ), ' Ref.PICAXE prog.editor .pdf help files,& BASIC Stamp 1 manuals for insights ' via Stan. SWAN ( MU@W, New Zealand ) => s.t.swan@massey.ac.nz <= '------------------------------------------------------------------------------- ' Byte b0= NTC measure-increases as temp rises b1= loop counter 0-255 ' Variables b2= divided NTC measure (approx.= R) b3= "heartbeat" delay ' b4= loop counter 1-6 to give suitable pulse/respiration ratio '------------------------------------------------------------------------------- ' Lines beginning ' are program documentation & could be ignored if need be. ' Program available for web download => http://picaxe.orcon.net.nz/heartled.bas '------------------------------------------------------------------------------- heartbeat: ' LED/PWM thermistor resistance monitoring routine ' approximates human TPR heartbeat & breathing ! for b4=1 to 6 ' cycle heartbeat loop so approx 10 breathes/min readadc 1,b0 ' low res.read NTC value via 15k voltage divider ' sub zero temps may give b0=0 & beating ceases! b2=b0/4 ' divide for a conveniently smaller step value debug b0 ' show variable NTC value(s) to attached PC VDU for b1= 0 to 255 step b2 ' counter loop so LED has multiple PWM cycles pwm 2,b1,1 ' PWM pin 2 LED one cycle increasing pulse width next b1 ' effect is a pleasing surging brightness increase for b1= 255 to 0 step -b2 ' When warm b2 decreases so step less/beat faster pwm 2,b1,1 ' PWM pin 2 LED one cycle decreasing pulse width next b1 ' gives a fading brightness instead of sudden off b3= 100/b2 *10 ' "invert" NTC b2 value & limit to a useful range pause b3 ' delay decreases as temp rises next b4 ' continue heartbeat loop until time for breath! sound 4,(255,80) ' inhale = breathe in "hiss" approx. 1sec pause 400 ' hold 400 millisecs (seems ~normal ? ) sound 4,(255,40) ' exhale = breathe out "hiss" approx. 1/2 sec goto heartbeat ' repeat routine