◗ PARTS LIST
Item
◗ SX28 proto board
◗ ADC0832, dual-channel ADC
◗ 24LC512 EEPROM
◗ Eight-pin DIP socket
◗ DB-15F socket (solder cup type)
◗ 220 ohm resistor
◗ 1K resistor
◗
4.7K resistor
◗ 10K resistor
◗ 0.1 µF capacitor
◗ bi-color LED (two lead)
◗ 0.025 male post headers (0.1” centers)
post-header jumpers
Qty
1
1
1
2
1
3
1
2
4
2
1
ton was held down for five consecutive cycles), it is
considered valid.
How a button press affects the program is based on the
current operational mode. The next step in the program is
to jump to the handler for the current mode:
Mode_Handler:
IF runMode = M_IDLE THEN Check_Start
IF runMode = M_REC THEN Recording
IF runMode = M_PLAY THEN Playing
IF runMode = M_PAUSE THEN Play_Paused
The first mode, M_IDLE, is where we’ll sit and wait for
a start button press, all the while the servos will follow any
motion of the joystick. When the start (x axis) button is
pressed, we’ll look at the Play/Record jumper and take
things from there.
IF btnTmr(0) = BtnOK THEN
IF PlayRec = RecordNow THEN
numRecs = 0
runMode = M_REC
ELSE
numRecs = GET_EE2 0, 0
IF numRecs > REC_LAST THEN
GOTO Empty_EE
ELSE
runMode = M_PLAY
ENDIF
ENDIF
eePntr = 2
btnTmr(0) = 0
ENDIF
GOTO Main
When the Play/Record jumper is out, the number of
records is read from the EEPROM at address $0000. Blank
EEPROMs usually have all locations set to $FF, so if we
see a bad value in the numRecs variable, the program
flashes the red LED and then jumps back to the top in idle
mode — what this means is that we need to record some
movements first.
Install the Play/Record jumper and then press the
start/stop button on the joystick — press it quickly, though.
The [movement] records count will be cleared and
the mode set to M_REC which directs the program to
84 September 2007
this section that follows:
Recording:
ledPort = LED_RED
pos0 = joyX
pos1 = joyY
IF btnTmr(0) = BtnOK THEN
GOTO Stop_Recording
ELSE
PUT_EE eePntr, joySticks
INC numRecs
IF eePntr < REC_LAST THEN
eePntr = eePntr + 2
ELSE
GOTO Stop_Recording
ENDIF
ENDIF
GOTO Main
Stop_Recording:
PUT_EE 0, 0, numRecs
runMode = M_IDLE
btnTmr(0) = 0
GOTO Main
We start by refreshing the red LED to indicate record
mode and then update the background servo controller
with the current joystick values. If the start/stop button has
not been pressed, then the axis values are written to the
memory, the records count is updated, and then we check
to see if there’s any room left in the EEPROM. If the
start/stop button has been pressed or we have run out of
memory, the recording process is stopped. Here we write
the number of records to address $0000 of the EEPROM
and reset the mode to idle.
Remove the Play/Record jumper and press the
start/stop button again — you should see the moves you just
recorded played back. I’m easily entertained, but when this
worked the first time my face lit up with a very big smile.
Here’s the playback code:
Playing:
ledPort = LED_GRN
pos0 = GET_EE2 eePntr
pos1 = __PARAM2
DEC numRecs
IF btnTmr(0) = BtnOK THEN
runMode = M_IDLE
btnTmr(0) = 0
GOTO Main
ENDIF
IF btnTmr(1) = BtnOK THEN
runMode = M_PAUSE
btnTmr(1) = 0
GOTO Main
ENDIF
IF numRecs > 0 THEN
eePntr = eePntr + 2
ELSE
IF Repeat = Yes THEN
numRecs = GET_EE2 0, 0
eePntr = 2
ELSE
runMode = M_IDLE
ENDIF
ENDIF
GOTO Main