Push Buttons and Jumpers (switches)
Two general purpose buttons and jumpers (also called switches) are provided on the controller card which can be read by the Basic Stamp II. Buttons are momentary – after you press them they return to the off state. Jumpers can be left in the on or off position using the jumper plug or wired to external switches. Buttons and Jumpers can be use in your program to set certain parameters or modes as needed. They may be ignored and not used at all. Here is a piece of PBasic example code that reads them: Notice they are active LOW (LOW=on).
if in12=0 then jmp1on if in13=0 then jmp2on if in14=0 then button1 if in15=0 then button2
'If jumper 1 on then jmp1on. 'If jumper 2 on then jmp2on. 'If button 1 on then but1on. 'If button 2 on then but2on.
Drive Motor and Encoder
The drive motor moves the motor forward and backward using the
An encoder wheel and encoder sensor are used to measure rotation of the drive wheel resulting in dis- tance measurement. There are 20 encoder slots (counts) per revolution. As it rotates, the slots are de- tected by the encoder sensor. The drive wheel is about
The following PBasic subroutine will show how to control the drive motor through the coprocessor. We suggest you also study the WANDER and TEST program.
'Drive Motor Control Subroutine. speed var byte
distance var word direction var byte net con 8
baud con 396
'Speed variable.
'Subroutine to start drive motor.
'
drivemotor:
serout net,baud,["!1M1", dec1 direction, speed, hex4 distance]
serin net,baud,[char] 'Get "A" back. return
31