techElder
Well-known member
I use a 2 TASK program to accomplish something. The PAUSEs in these routines are about 1/3 too slow in a multiplexed program with 2 TASKs.
I've used this routine to determine what the base line NO TOUCH point is on a 1 inch diameter sensor made from double-sided PCB material.
To go along with that base line routine, I use the following to determine whether a touch to the sensor has been there for 2 seconds. I'm not at all satisfied with this because the PAUSE 2000 allows another TASK to gain attention which makes that TASK execute quicker. Not good when you want an LED to blink at a consistent rate.
I hope someone has a better TOUCH routine to suggest.
I've used this routine to determine what the base line NO TOUCH point is on a 1 inch diameter sensor made from double-sided PCB material.
Code:
calibrateNoTouch: ' Periodically determine and store the touch ON/OFF levels with no touch
touchOffLevel = 0 ' reset every time
for counter = 1 to 10
touch16 TOUCHPIN, adcreading
touchOffLevel = adcreading / 10 + touchOffLevel
next
touchOnLevel = touchOffLevel + 100
time = 0 ' restart the time
return
I hope someone has a better TOUCH routine to suggest.
Code:
do
touch16 TOUCHPIN, adcreading
if adcreading > touchOnLevel then
' here is the problem line. The PAUSE gives the other TASK more attention
pause 2000 ' wait to see if still touched after 2 seconds
touch16 TOUCHPIN, adcreading ' see if the touch is still there
if adcreading > touchOnLevel then
suspend 1 ' suspend the other task while touching
' do something here
gosub flashSomething ' change accepted
' pause 1500
restart 1 ' restart the other task after touching stuff complete
endif
else
if time > 10 then ' wait 10 seconds before allowing another no touch calibration
gosub calibrateNoTouch
gosub checkBattery
endif
endif
loop