fl { PropForth 5.5(DevKernel) PilseMonitor 2017/09/23 21:21:09 Vcc | Sensor A=100 A=100 ----------- (NJL5501R) ------ ------ MCP3204 | | -------- - | |out - | |out CH0 ----- | Propeller | | |-------| INV- |-------| INV- |--------| ADC |----| | | | + | AMP | + | AMP | ----- | | -------- ---| | ---| | | | | | | | | | ST7735R | | | ------ | ------ -------- | | Vcc/2 Vcc/2 | LCD |---| | | | | | -------- ----------- | GND A/D Converter(MCP3204) MCP3204 Propeller CS <--- _cs(P5) Din <--- _do(P6) Dout ---> _di(P7) CLK <--- _clk(P8) CH0 ---------------------- Analog signal Using single mode on CH0 Store current A/D value to buffer[128] Shift dot from buffer [n+1] to buffer[n] LCD:T18003T01(ST7735R) LCD Propeller RES ----- P0 RS ----- P1 SDA ----- P2 SCL ----- P3 CS ----- P4 [x,y]=[129,160] [x,y]=[2,160] -------------------------- YE=160 |[] []| ^ | | | | | | | | | | | | Pulse level | | | | LCD | row | | | | | | | | | | | | | | | | |[] []| YS=1 -------------------------- [x,y]=[2,1] XE=129 XS=2 [x,y]=[129,1] column buffer[0] buffer[127] ---------------------------> Time ThermalPrinter(CSN-A2-T) CSM-A2-T PowerSupply 1 GND ------ GND 2 NC Propeller 3 VH ------ 5V4A Gnd ----------------------- 4 Gnd P9(Rx) -------------------- 5 Tx (3V3 when idle) P10(Tx) -------------------- 6 Rx (3V3 when idle) RS232 19200bps Noparity Stopbit1 time ------------------------------------------------------------>> ------- --------- ------------ | | | | | | | | ----- ----------------------------- idle start bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 stop stop idle bit bit (always "0") (always "1") switch 3V3 | 10kohm | P11 ------| | sw | GND |\| P12 ---| | ----220ohm---GND |/| LED } \ ================================================================== \ Variables \ ================================================================== \ ----- LCD ----- wvariable ADC wvariable buffer d126 allot \ Buffer for ADC wvariable prnBuffer d46 allot \ Buffer for Thermalprinter[384bit=384dots] wvariable stopPrinter \ ----- pulseMonitor ----- wvariable pulseVar d44 allot pulseVar constant signal pulseVar 2+ constant thresh pulseVar 4+ constant Pulse pulseVar 6 + constant N pulseVar 8 + constant calcIBI pulseVar d10 + constant IBI pulseVar d12 + constant currentBeat pulseVar d14 + constant lastBeat pulseVar d16 + constant P pulseVar d18 + constant T pulseVar d20 + constant amp pulseVar d22 + constant rate pulseVar d42 + constant pulseValue pulseVar d44 + constant 1stBeat \ ----- ThermalPrinter ------ wvariable inchar \ ----- switch ------ variable DebounceTime wvariable swState wvariable debounce \ ================================================================== \ Constants \ ================================================================== \ ----- ADC ----- 5 wconstant cs 6 wconstant _do \ connect to MCP3204's Din 7 wconstant di \ connect to MCP3204's Dout 8 wconstant clk cs >m constant mcs \ ----- LCD ----- 0 wconstant RES 1 wconstant D/CX 2 wconstant SDA \ 3 wconstant SCL 4 wconstant CSX SDA >m constant mSDA wvariable initData -2 allot hB4 c, 1 c, 7 c, \ colum inversion hC0 c, 3 c, hA2 c, h02 c, h84 c, \ power control 1 hC1 c, 1 c, hC5 c, \ power control 2 hC2 c, 2 c, h0A c, h00 c, \ power control 3 hC3 c, 2 c, h8A c, h2A c, \ power control 4 hC4 c, 2 c, h8A c, hEE c, \ power control 5 hC5 c, 1 c, h0E c, \ VCOM h36 c, 1 c, hC8 c, \ Mwmory data access control [] MX, MY, BGR-Mode ] \ Gammma Sequence hE0 c, d16 c, h02 c, h1C c, h07 c, h12 c, h37 c, h32 c, h29 c, h2D c, h29 c, h25 c, h2B c, h39 c, h00 c, h01 c, h03 c, h10 c, \ VCOM hE1 c, d16 c, h03 c, h1D c, h07 c, h06 c, h2E c, h2C c, h29 c, h2D c, h2E c, h2E c, h37 c, h3F c, h00 c, h00 c, h02 c, h10 c, h2A c, 4 c, h00 c, h02 c, h00 c, h81 c, \ set column address h2B c, 4 c, h00 c, h01 c, h00 c, hA0 c, \ set row address \ Interface pixel format h3A c, 1 c, h05 c, \ 16bits/pixel RGB 5-6-5bit d800000 constant 10msec buffer d127 + constant bufferEnd \ character font wvariable font -2 allot \ char"0" h03E0 w, h0FF8 w, h1FFC w, h1F1C w, h3B0E w, h3B8E w, h3B8E w, h398E w, h398E w, h398E w, h39CE w, h39CE w, h38CE w, h38CE w, h38CE w, h38EE w, h38EE w, h386E w, h1C7C w, h1FFC w, h0FF8 w, h03E0 w, \ char"1" h3FFE w, h3FFE w, h3FFE w, h01C0 w, h01C0 w, h01C0 w, h01C0 w, h01C0 w, h01C0 w, h01C0 w, h01C0 w, h01C0 w, h01C0 w, h01C0 w, h01C0 w, h39C0 w, h3DC0 w, h1FC0 w, h0FC0 w, h07C0 w, h03C0 w, h01C0 w, \ char"2" h3FFE w, h3FFE w, h3FFE w, h3800 w, h3800 w, h3C00 w, h1C00 w, h1E00 w, h0F80 w, h07C0 w, h01F0 w, h00F8 w, h003C w, h001C w, h000E w, h000E w, h380E w, h380E w, h1C1C w, h1FFC w, h0FF8 w, h03E0 w, \ char"3" h03E0 w, h0FF8 w, h1FFC w, h1C1C w, h380E w, h380E w, h000E w, h000E w, h000E w, h001C w, h03FC w, h03F8 w, h03FC w, h001C w, h000E w, h000E w, h380E w, h380E w, h1C1C w, h1FFC w, h0FF8 w, h03E0 w, \ char"4" h0070 w, h0070 w, h0070 w, h0070 w, h0070 w, h3FFE w, h3FFE w, h3FFE w, h1C70 w, h1C70 w, h1C70 w, h0E70 w, h0E70 w, h0E00 w, h0700 w, h0700 w, h0700 w, h0380 w, h0380 w, h0380 w, h01C0 w, h01C0 w, \ char"5" h03E0 w, h0FF8 w, h1FFC w, h1C1C w, h380E w, h380E w, h000E w, h000E w, h000E w, h000E w, h381C w, h3FFC w, h3FF8 w, h3BE0 w, h3800 w, h3800 w, h3800 w, h3800 w, h3800 w, h3FFC w, h3FFC w, h3FFC w, \ char"6" h03E0 w, h0FF8 w, h1FFC w, h1C1C w, h380E w, h380E w, h380E w, h380E w, h380E w, h380E w, h3C1C w, h3FFC w, h3FF8 w, h3BE0 w, h3800 w, h3800 w, h380E w, h380E w, h1C1C w, h1FFC w, h0FF8 w, h03E0 w, \ char"7" h0380 w, h0380 w, h0380 w, h01C0 w, h01C0 w, h01C0 w, h00E0 w, h00E0 w, h00E0 w, h0070 w, h0070 w, h0070 w, h0038 w, h0038 w, h0038 w, h001C w, h001C w, h001C w, h000E w, h3FFE w, h3FFE w, h3FFE w, \ char"8" h03E0 w, h0FF8 w, h1FFC w, h1C1C w, h380E w, h380E w, h380E w, h380E w, h380E w, h1C1C w, h1FFC w, h0FF8 w, h1FFC w, h1C1C w, h380E w, h380E w, h380E w, h380E w, h1C1C w, h1FFC w, h0FF8 w, h03E0 w, \ char"9" h03E0 w, h0FF8 w, h1FFC w, h1C1C w, h380E w, h380E w, h000E w, h000E w, h03EE w, h0FFE w, h1FFE w, h1C1E w, h380E w, h380E w, h380E w, h380E w, h380E w, h380E w, h1C1C w, h1FFC w, h0FF8 w, h03E0 w, \ char" " h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, h0000 w, \ ----- pulseMonitor ----- d160000 constant 2msec \ ----- Printer ----- \ Priner command \ command-name( n1 n2 n3-nn) n1:command byte number n2:data byte number n3:command byte(1byte /2byte/nbyte) wvariable LF -2 allot 1 c, 0 c, h0A c, wvariable GS_! -2 allot 2 c, 1 c, h1D c, h21 c, wvariable DC2_* -2 allot 2 c, 2 c, h12 c, h2A c, wvariable ESC_7 -2 allot 2 c, 3 c, h1B c, h37 c, wvariable DC2_# -2 allot 2 c, 1 c, h12 c, h23 c, \ Init command wvariable ESC_@ -2 allot 2 c, 0 c, h1B c, h40 c, \ serial for PropForth<-->ThermalPrinter 9 wconstant Rx d10 wconstant Tx d4800 constant baud/4 \ 19200/4 \ ----- switch ------ d11 wconstant swpin d12 wconstant ledpin d800000 constant 10msec swpin >m constant swMask ledpin >m constant ledMask \ ================================================================== \ Variables \ ================================================================== { \ ----- pulseMonitor ----- wvariable pulseVar d44 allot pulseVar constant signal pulseVar 2+ constant thresh pulseVar 4+ constant Pulse pulseVar 6 + constant N pulseVar 8 + constant calcIBI pulseVar d10 + constant IBI pulseVar d12 + constant currentBeat pulseVar d14 + constant lastBeat pulseVar d16 + constant P pulseVar d18 + constant T pulseVar d20 + constant amp pulseVar d22 + constant rate pulseVar d42 + constant pulseValue pulseVar d44 + constant 1stBeat } { n update timer[0-500] 2byte m index for Digit^display 2byte mSDA mask of sda: 4byte font address for font 2byte Digit3 char-cod for Digit3 2byte Digit2 char-cod for Digit2 2byte Digit1 char-cod for Digit1 2byte } variable varNum -4 allot 0 l, mSDA l, font w, 0 w, 0 w, 0 w, { \ ThermalPrinter wvariable inchar } \ ================================================================== \ Main \ ================================================================== \ ----- ADC ----- : cs_l cs pinlo ; : cs_h cs pinhi ; \ A/D conversion by MCP3204 single-mode CH0 \ ( n1 -- n2 ) n1:mcs n2: ADC value lockdict create a_ADC forthentry $C_a_lxasm w, h138 h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2Wi]RB l, zfyPO1 l, z2Wi]ZB l, zfyPO1 l, z2Wi]eB l, zfyPO1 l, z2Wi]mB l, z2WiPSq l, z2WyPb5 l, z1[ix[m l, zgyPO1 l, z1jix[n l, z1Sy]Kf l, z3[yPfT l, z1[ix[n l, z1Sy]Kf l, z2WyPbD l, zfyPO1 l, z1Sy]Kf l, z1YF]il l, z20oPO1 l, z3[yPf[ l, z1[ix[p l, z1bix[m l, z1SV01X l, z1[ix[p l, z2WyPWB l, z20iPak l, z3ryPW0 l, z1bix[p l, 0 l, z1SV000 l, 0 l, 0 l, 0 l, 0 l, z300000 l, freedict \ ----- LCD ----- \ Serial-out 1byte to LCD(ST7735R) \ ( n1 n2 -- ) n:1byte data n2:lcdpin lockdict create a_byteWr forthentry $C_a_lxasm w, h123 h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2Wi[BB l, zfyPO1 l, z2Wi[JB l, z1SyLI[ l, z2WyPW8 l, zfyPOO l, zoyPO1 l, z1jix[X l, z1bix[Y l, z1[ix[Y l, z3[yP[P l, z1[ix[X l, z1SyLI[ l, z1SV01X l, 0 l, 0 l, freedict \ Shift LCD-dots to left dot by dot[1dot=10msec] \ ( n1 n2 -- ) n1:buffer address n2:mSDA \ Using [here W@] as buffer lockdict create a_dotShift forthentry $C_a_lxasm w, h159 h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2WidJB l, zfyPO1 l, z2WidRB l, zbyPO2 l, z2WidZB l, z1SyLI[ l, z2WideB l, z1SyLI[ l, z2WyPY1 l, z2Wydky l, ziPgL l, z1SycCs l, z2WiPoN l, z1SydDA l, z20ydb1 l, ziPgL l, z24ydb1 l, zFPgL l, z1SycCs l, z2WiPoO l, z1SydDA l, z20ydb1 l, z24yPW1 l, z3[ydnT l, z2WyPW2 l, ziPgL l, z1SycCs l, z2WiPoN l, z1SydDA l, z1SV01X l, z2WyQ08 l, zfyPrO l, zoyPr1 l, z1jix\I l, z1bix\J l, z1[ix\J l, z3[yQ4m l, z1SV000 l, z1[ix\K l, z2WyPrd l, z1Sya4k l, z1bix\K l, z2WyPr0 l, z1Sya4k l, z2WiPuC l, z1Sya4k l, z1[ix\K l, z2WyPre l, z1Sya4k l, z1bix\K l, z2WyPr0 l, z1Sya4k l, z2WiPuD l, z1Sya4k l, z1SV000 l, z1[ix\K l, z2WyPrf l, z1Sya4k l, z1bix\K l, z2WiPuE l, z1Sya4k l, z1Sya4k l, z1SV000 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, z3y l, freedict \ Updating pulse \ ( n1 n2 -- ) n1:pulseValue address n2:varNum address lockdict create a_dispDigits forthentry $C_a_lxasm w, h1AC h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z4iPZB l, z26VPZ8 l, z1SL05O l, z2WiPZB l, z20yPO4 l, z8iPeB l, z2WinJD l, zfyPb1 l, z2WinRD l, zfyPb1 l, z2WinZD l, zbyPb3 l, z2WineD l, z2WimRC l, z20yPW2 l, z2WimZC l, z20yPW6 l, z4immC l, z20yPW2 l, z2WimuC l, z20yPW2 l, z2Win3C l, z20yPW2 l, z2WinBC l, z1SyLI[ l, z2WimeB l, z6iPhS l, z1SL052 l, z4iP]T l, z2WyPb0 l, z25VPX[ l, z20mPb1 l, z24mPX[ l, z1SJ04k l, z1YVPey l, z2WtPbA l, z4FPhV l, z2WyPb0 l, z25VPWA l, z20mPb1 l, z24mPWA l, z1SJ04s l, z4FPhW l, z4FP]X l, z2WyPW3 l, z4FP]S l, z1SV05R l, z26VPb3 l, z1SL05A l, z4iP]V l, z2WyoPl l, z1SyioT l, z2WyPW2 l, z4FP]S l, z1SV05R l, z26VPb2 l, z1SL05I l, z4iP]W l, z2WyoPY l, z1SyioT l, z2WyPW1 l, z4FP]S l, z1SV05R l, z4iP]X l, z2WyoPI l, z1SyioT l, z2WyPW0 l, z8FP]R l, z1SV05R l, z20yPW1 l, z4FPZB l, z1SyLI[ l, z1SyLI[ l, z1SV01X l, z22yPW0 l, z1SQ05X l, z20ymjf l, z3[yP\V l, z1[ix][ l, z2WyPWd l, z1SykU7 l, z2WyPb0 l, z2WiPpe l, z1Syl6C l, z2WyPb0 l, z20yPjF l, z1Syl6C l, z2WyPWe l, z1SykU7 l, z2WyPb0 l, z2WyPl6 l, z1Syl6C l, z2WyPb0 l, z2WyPlR l, z1Syl6C l, z2WyPWf l, z1SykU7 l, z2WynjM l, z2WynrG l, z4io6U l, zkyo01 l, z1SmlhH l, z1SvmMM l, z3[ynwq l, z20ymj2 l, z3[ynoo l, z1bix][ l, z1SV000 l, z2WyQ08 l, zfyPrO l, zoyPr1 l, z1jix]Y l, z1bix]Z l, z1[ix]Z l, z3[yQ61 l, z1SV000 l, z1[ix]\ l, z2WiPuC l, z1Syjoy l, z1bix]\ l, z1SV000 l, z2WiPuD l, z1Syjoy l, z2WiPuE l, z1Syjoy l, z1SV000 l, z2WyPr0 l, z1Syjoy l, z2WyPr0 l, z1Syjoy l, z1SV000 l, z2WiPxc l, z1Syjoy l, z2WiPxd l, z1Syjoy l, z1SV000 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, z7 l, z3W l, 0 l, freedict : res_l RES pinlo ; : res_h RES pinhi ; : d/cx_l D/CX pinlo ; : d/cx_h D/CX pinhi ; : csx_l CSX pinlo ; : csx_h CSX pinhi ; \ Write byte-data to ST7735R \ ( n -- ) n:1byte : wrByte mSDA a_byteWr ; \ Write command to ST7735R \ ( n1 -- ) n1:command : wrCom d/cx_l wrByte d/cx_h ; \ Write 16bit-color-data to RAM \ ( n1 -- ) n1:16bit (RGB 5-6-5bit) : pixel dup 8 rshift wrByte wrByte ; \ Set initial data \ ( n1 -- n2 ) :n1:address n2:next address : setInitData dup C@ wrCom 1+ dup C@ 0 do 1+ dup C@ wrByte loop 1+ ; \ Paint screen(128X160dots) by 16bit-color \ ( n1 -- ) n1:16bit color : fullScrn csx_l h2C wrCom d160 0 do d128 0 do dup pixel loop loop drop csx_h ; \ initialize LCD(T18000T01 Controller:ST7735R) Default:18bit-Color : init_ST7735R \ Set all port to output RES 5 0 do dup pinout 1+ loop drop csx_h d/cx_h \ Issue reset-pulse res_h res_l res_h csx_l \ sleep out h11 wrCom d120 delms initData d13 0 do setInitData loop drop \ Display on h29 wrCom csx_h 0 fullScrn \ black ; \ Set dot to [x,y] x:2-129 y:1-160 \ ( n1 n2 -- ) n1:x n2:y : plot csx_l h2B wrCom dup 0 wrByte wrByte 0 wrByte wrByte \ x:row h2A wrCom dup 0 wrByte wrByte 0 wrByte wrByte \ y:colum h2C wrCom hFFFF pixel csx_h ; \ Display analog-signal to LCD from roght to left \( -- ) : lcd init_ST7735R \ Initialize LCD 0 varNum L! 0 buffer d64 0 do 2dup W! 2+ loop 2drop \ Clear buffer 10msec cnt COG@ + begin stopPrinter W@ if signal W@ 5 rshift 1+ dup bufferEnd C! 2 swap plot csx_l buffer mSDA a_dotShift csx_h \ Shift dots pulseValue varNum a_dispDigits \ update pulse then 10msec waitcnt \ fkey? swap drop 0 until \ drop ; \ ----- TermalPrinter ----- \ Start up serial-communication \ This need to execute when staring serial-communication at first \ ( -- ) : initSerial c" Tx Rx baud/4 serial" 4 cogx \ Start serial on cog5 d100 delms inchar 4 cogio 2+ W! \ Set output of cog5 to inchar h100 inchar W! \ Clear inchar 1 4 sersetflags ; \ Stop Serial communication \ This need to execute when finishing serial-communication at last \ ( -- ) : stopSerial 0 4 cogio 2+ W! 4 cogreset ; \ Transmit data[1byte] \ ( n1 -- ) n1:transmitting byte : Transmit begin 4 cogio W@ h100 and until \ Wait until input for serial-cog is under ready-state 4 cogio W! \ Write data to cog5's input ; \ Receive data and save them in free area \ ( n1 -- n2 ) n1:repeat number n2:last addres+1 of free area : Receive here W@ swap 0 do begin inchar W@ h100 and 0= until \ Wait until output for serial-cog is under ready-state inchar W@ over C! \ Save output-data of cog5 to free area h100 inchar W! \ Clear inchar 1+ \ Increment free space address loop ; \ Send command to ThermalPrinter \ ( nn-nm n1 -- ) nn-nm:data if needed n1:command : prtcmd dup C@ over 2+ swap 0 do dup C@ Transmit 1+ loop drop \ Serial out command 1+ C@ dup 0<> if 0 do Transmit loop \ Serial out data else drop then ; \ Set font size ( n -- ) n:font size 7 and if signal W@ T W@ < if signal W@ T W! then \ Update T then \ Check condition when signal is more than threshold signal W@ thresh W@ > signal W@ P W@ > and if signal W@ P W! then \ Update P \ Calculate pulse when N>250(ie;pulse is less than 240/min) N W@ d250 > if signal W@ thresh W@ > Pulse W@ 0= N W@ calcIBI W@ > and and if 1 Pulse W! currentBeat W@ lastBeat W@ - IBI W! currentBeat W@ lastBeat W! rate d10 0 do i 1+ 2* over + W@ over i 2* + W! loop drop IBI W@ rate d18 + W! 0 rate d10 0 do dup i 2* + W@ rot + swap loop drop d10 / d60000 swap / pulseValue W! then then \ Check condition during signal is rising down signal W@ thresh W@ < Pulse W@ 1 = and if 0 Pulse W! P W@ T W@ - dup amp W! 2/ T W@ + dup dup thresh W! P W! T W! then \ Check condition if signal go out for 2.5sec N W@ d2500 > if \ Initialize thresh,P,T,lastBeat d2048 thresh W! d2048 P W! d2048 T W! currentBeat W@ lastBeat W! 1 1stBeat W! then 2msec waitcnt 0 until ; \ Clear prnBuffer \ ( -- ) : clr_prnBuffer 0 prnBuffer d24 0 do 2dup W! 2+ loop 2drop ; \ Make dot-pattern (3dots) in prnBuffer array[48byte:384bit] \ ( n1 -- ) n1:time axis on LCD[0-127] : makeDots d128 0 do dup i buffer + C@ \ Get ADC value[0-127] = if \ Store bit-pattern in prnBuffer 3 i * \ horizontal drection on printer[0-383] 8 u/mod \ ( n1 reminder quotient ) dup if \ plotted dots is inside [8-383]dots prnBuffer + \ ( n1 reminder prnBuffer ) hE000 rot \ ( n1 prnBuffer hE000 reminder ) rshift \ ( n1 prnBuffer rshifted[E000] ) else \ plotted dots is inside [0-7]dots 2drop prnBuffer \ ( n1 prnBuffer ) hE000 i rshift \ ( n1 prnBuffer rshifted[E000] ) then 2dup 8 rshift \ ( n1 prnBuffer rshifted[E000] prnBuffer Hi_byte ) over C@ or swap C! \ ( n1 prnBuffer rshifted[E000] ) hFF and dup \ ( n1 prnBuffer Lo_byte Lo_byte ) if swap 1+ C! else 2drop then then loop drop ; \ print pulse on TeraTerm : test buffer 128 0 do dup i + C@ spaces h2E emit cr loop drop ; \ print vale inside prnBuffer[48byte] : print prnBuffer d48 0 do dup C@ .byte 1+ loop drop ; \ Print pulse-wave from upper to lower \ ( -- ) : printPulse \ Print pulse value d16 font_size c" Pulse " prt_str pulseValue W@ d100 u/mod 0= if h20 else h30 + then Transmit d10 u/mod h30 + Transmit h30 + Transmit linefeed d500 delms \ Print pulse-wave hFF DC2_# prtcmd \ Change density d128 0 do clr_prnBuffer d127 i - makeDots d48 3 DC2_* prtcmd 3 0 do prnBuffer d48 0 do dup C@ Transmit 1+ loop drop loop loop ; \ Detect sw status \ ( -- n1 ) n1:pushed-sw sensed if true : swDetect \ Check if during debounce debounce W@ if \ Check if exceeding 10msec cnt COG@ DebounceTime L@ - 10msec > if rdSw dup swState W@ <> if swState W! \ Update swState if sw-status change else drop then 0 debounce W! \ Clear debounce then else rdSw swState W@ <> if 1 debounce W! \ Set debounce cnt COG@ DebounceTime L! \ Set DebounceTime then then swState W@ ; \ Start PulseMonitor(ADC,LCD,pulse,printer) \ ( -- ) : PulseMonitor initSW initSerial init_prt setup 1 stopPrinter W! c" lcd" 5 cogx c" GetPulse" 3 cogx d100 delms begin swDetect 0= if 0 stopPrinter W! \ Stop updating lcd printPulse \ d5000 delms 1 stopPrinter W! \ Restart updating lcd begin swDetect until then fkey? swap drop until 3 cogreset 5 cogreset stopSerial ;