PICAXE PRIMER
statement, add a touch B. 2, b2
statement.
2) Edit the sertxd statement so
that it reads sertxd (#b1, 32,
#b2, cr, lf) ( 32 is the ASCII
code for a space; it just
separates the two values).
■ FIGURE 7.
Breadboard setup
for Experiment 3.
After I saved my edited program
with a new name (Touch Test2.bas),
I ran it and conducted a few more
experiments. Before I describe
some of my results, I want to
mention three additional aspects of
working with the 18M2’s touch
sensors that are important to keep
in mind. First, analogously to the
readADC and readADC10
commands, there are actually two
different touch related commands
(touch and touch16). We’re not
going to discuss the details of the
touch16 command this time, but it
would be a good idea to familiarize
yourself with the differences between
the two commands. Secondly, as
mentioned in Section 2 of the
manual, each of the 10 touch-sensitive inputs on the 18M2 will
produce slightly different readings
from the same touch pad. In other
words, if we were to move our
two-key keypad to two different
touch-sensitive inputs on the 18M2,
the touch readings that I’m about
to discuss would be somewhat
different.
Also, changes in various
characteristics of the hardware that
you are using will also have an
impact on the touch readings. For
example, if you change the size of a
touchpad or the length of the wire
leading to it, the reading will change
when the pad is touched. Finally,
how lightly or heavily the sensor is
touched also changes the touch
reading. I think this variation is
produced by the fact that pressing a
touch sensor firmly as opposed to
lightly results in a larger area of skin
coming as close to the surface of the
sensor as possible.
Keeping the above
considerations in mind, let’s take a
look at the results that I obtained
when I first tested my two-key touch
keypad. When I ran Touch Test2.bas
without touching
either key, my
“On” key (pin B.1)
produced a touch
reading that varied
from 90 to 92,
while my “Off”
key (pin B. 2)
reading varied
between 82 and
84. By positioning my finger very
close to either key (without actually
touching the paper label), I could
easily increase each of these readings
by a value of 25 or more. Lightly
touching the on key produced a
value of about 160 ± 10 or so; lightly
touching the off key resulted in
readings of 170 ± 10. A medium
amount of pressure produced
readings in the vicinity of 200 for
both pins; pressing very firmly on
either key produced readings greater
than 220.
At one point, I accidentally hit a
small plastic tube on my desk,
moving it close to my keypad. Even
this small change in the keypad’s
environment affected the results; the
non-touch readings decreased by
approximately a value of 10. Finally, I
also found a small variability in my
results when I repeated my tests on a
couple of different days; I think this
was due to changes in temperature
and/or humidity.
My main purpose in discussing
some of the details of my results is
to emphasize the fact that the
touch readings have a considerable
amount of variability which can be
produced by a variety of
environmental factors. These factors
need to be taken into consideration
when designing both the hardware
and software aspects of a project
that involves touch sensors. When
you implement your touch keypad
and run the TouchTest2.bas software,
see how closely your results parallel
mine. If you discover additional
factors that also influence the
variability of your touch readings,
send me an email
( Ron@JRHackett.net) describing your
findings and I’ll mention them in a
future Primer.
EXPERIMENT 3:
IMPLEMENTING A
SINGLE MOMENTARY
TOUCH-SENSITIVE KEY
Now that we have experimented
with some of the factors that
influence the touch readings, let’s
turn our attention to implementing a
single momentary touch-sensitive key.
For this experiment, our hardware
remains the same, except for the
addition of a red LED on pin C.1 (see
Figure 7). As usual, I’m using a
resistorized LED, but don’t forget to
include the current-limiting resistor if
you use a non-resistorized LED. The
program for our next experiment is
again simple enough to directly type
into the Programming Editor:
; === TouchMoment.bas ===
; Implements a single
; momentary touch “key”
; === Constants ===
symbol LED_R = C.1
symbol onKey = B.1
; === Variables ===
symbol onVal = b1
; === Directives ===
#com 5
#picaxe 18M2
#no_data
#terminal off
; === Begin Main ====
do
touch onKey, onVal
if onVal > 100 then
high LED_R
else
low LED_R
endif
loop
December 2010 19