Make Electronics

(nextflipdebug2) #1

Experiment 36: The Lock, Revisited


312 Chapter 5


say that the value will be between 71 and 83. If we specify a range as shown in
the following table, we have a much better chance of interpreting each button
correctly.

Button number Range
9 600 71–83
6 700 84–96
3 800 97–108
0 900 109–121
8 1000 122–134
5 1100 135–147
2 1200 148–160
7 1300 161–172
4 1400 173–185
1 1500 191–198

Suppose you attach the common pin of your keypad to ADC Logic Pin 2 of the
PICAXE. You can now use the Program Editor to write a program that looks like
this:
getkey:
readadc 2,b0
let b1 = 9
if b0 < 84 then finish
let b1 = 6
if b0 < 97 then finish
let b1 = 3
if b0 < 109 then finish
let b1 = 0
if b0 < 122 then finish
let b1 = 8
if b0 < 135 then finish
let b1 = 5
if b0 < 148 then finish
let b1 = 2
if b0 < 161 then finish
let b1 = 7
if b0 < 173 then finish
let b1 = 4
if b0 < 186 then finish
let b1 = 2

finish:
return
What does the word “return” mean at the end? I’ll get to that in a second. I want
to explain the rest of the routine first.
Free download pdf