don't see this working
won't your adc reading always be > 0 and it can never be higher than 1023
If DataW > 0 AND DataW < 1023 then GPIO.2 = 1
as dave says something like this
Code:
@ __config _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _BODEN_ON
DEFINE OSC 4
long_press_threshold con 20 ;2 sec
press_threshold con 10 ;1 sec
trigger_thresshold con 600 ; adc reading must fall below this to countr as pressed
CMCON = 7
TRISIO = %00001001
INTCON = 0
IOC = 0
GPIO = 0
ANSEL = %00110001
ADCON0.7 = 1
DataW var WORD ' Just a WORD Temporary working variable
b_cnt var byte
b_ACT var byte ;0 not pressed ,1 pressed for 1 sec ,2 pressed for 2 sec
clear
Main:
gosub chk_sw
Pause 100
if b_ACT then
if b_ACT ==1 then
GPIO.2 = 0
else
GPIO.2 = 1
endif
b_ACT=0
b_cnt=0
endif
Goto Main
chk_sw:
ADCON0 = %10000001 ;ch0
Pauseus 50 ' Wait for channel to setup
ADCON0.1 = 1 ' Start conversion
While ADCON0.1=1:Wend ' Wait for conversion
DataW.HighByte=ADRESH ' Read variable from ADC and save
DataW.LowByte=ADRESL
if DataW < trigger_thresshold then
b_cnt=b_cnt+1 ;if btn is active add to count
IF b_cnt > long_press_threshold THEN b_ACT= 2
ELSE ;button released
if b_cnt > press_threshold THEN ;press_threshold met
IF b_cnt > long_press_threshold THEN
b_ACT= 2 ;LONG press >2 SEC
ELSE
b_ACT= 1
ENDIF
ELSE ;press_threshold not met
b_ACT= 0
b_cnt=0 ;reset count
ENDIF
endif
return
Bookmarks