■ FIGURE 4: SLED4C CONNECTIONS
the button is pressed (I have an encoder with a built-in button, which is
very convenient for this application), the value in the display will be compared against the combination value for the current state. If they match,
the state value is incremented; otherwise, the state is reset to zero
(locked). When the state counter hits three, the lock is opened (an electric solenoid, for example, could be energized) and “OPEn” is displayed
and flashed. At this point, the program will wait for the encoder to be
86 NUTS & VOLTS November 2005
turned again, and when this happens the lock will reenergize.
First things first — how do we set the lock code? Keeping things
easy, we can embed the combination into a DATA statement.
Combo DATA 07, 25, 62
This works well for a couple of reasons: we can read the current
combo value using the state variable as an index, and being stored in
EEPROM, we could update the program later to allow the combination
to be set externally (without reprogramming the BASIC Stamp). Note
that this program is using two digits for the dial value, so we have to
keep the combination numbers under 100.
The first part of the program initializes everything. Normally, not
much happens in this section, but since that’s not the case here, we’ll
go through it.
encOld = Encoder & %0011
state = Locked
We start by engaging the lock, making the Enable pin an output and
high to disable communication to the SLEC4C, and then we read the current encoder position so movement can be detected later. The lock state
variable gets initialized (note the alias “Locked” that makes the program
easier to understand), and finally, we update the SLED4C display.
The display update is state dependent and really just a router to the
code that handles the display for entering numbers or showing “OPEn.”
IF (state < Open) THEN
Let’s look at the module we’ll use the most. It’s called Show_Dial
and it does just that: it shows the current dial position, 0 to 99. Just to
dress up the display, I centered the value in the middle of the display
and surrounded it by underline characters (more on this in a bit).
dpCtrl = %1000
bank5 = ULine
bank4 = dial DIG 1
bank3 = dial DIG 0
bank2 = ULine
#IF (ShowState = 1) #THEN
‘‘‘‘‘ update state LEDs (colon dots)
LOOKUP state, [%0000, %0001, %0011], bank1
bank1 = %0000
display = IsOff
config = %00100111
The subroutine starts by updating the values of the bank control
registers. In banks 5 and 2, we will show an underline character; this value comes from a program constant. The DIG operator gets used to pull
■ FIGURE 5: CONFIGURATION VALUES