
To begin with, you should enter your VB or VBA environment. If you have a full version of VB installed, just start it up. If you have any of the Microsoft Office applications, you can use VBA.
In Word, for example, choose
Tools > Macro > Visual Basic Editor.
Showing Spirit.ocx in the Tool Palette
To reference
Spirit.ocx
we first need to put it in a user form. Create a new form by choosing
Insert > UserForm.
A new form appears, along with a tool palette labeled
Toolbox.
Spirit.ocx
does not appear in the tool palette. To add it, choose
Tools > Additional Controls.
In the window that appears, scroll down to find
Spirit Control
in the list of available controls.
∗
Click
on the box to its left to select it, then click on
OK.
You only have to follow this procedure once. When you use VB again later, the
Spirit.ocx
control will automatically show up in your tool
palette, as shown in Figure 8-2.
A new item with the familiar LEGO logo should now be in your tool palette. Select this item and place it on the form you just created. We won't use the form for anything except as a place to keep
the
Spirit.ocx
control. Change the name to something like
DummySpiritForm
. The control itself has a default name of
Spiritil
, which is just fine for our purposes.
∗
The
Spirit Control
item appears in the list only if you have already installed the LEGO MINDSTORMS software. During this installation,
Spirit.ocx
is registered with the system in such a way that
VB or VBA can find it later.
Page 162
Figure 8-2.
Spirit.ocx in the tool palette
You should glance over
Spiritl's
properties to make sure they're set up properly. In particular, check the
ComPortNo
property to be sure you'll be talking to the right serial port.
Hello, Spirit
Now that you've placed a
Spirit.ocx
control on a form, let's write some code to use it. Choose the
Insert > Module
menu item to create a new code module. In the window that appears, type the
following to create a new subroutine:
Sub HelloSpirit
To call functions in
Spirit.ocx,
you need to reference the control by name. The dummy form you created is
DummySpiritForm
. It contains a
Spirit.ocx
control called
Spiritl
. The full name
of the control, then, is
DummySpiritForm.Spirit1
.
Fill out the body of the
HelloSpirit
subroutine as follows:
Sub HelloSpirit ()
DummySpiritForm.Spiritl.InitComm
DummySpiritForm.Spiritl.PlaySystemSound 0
DummySpiritForm.Spiritl.CloseComm
End Sub
To run this simple subroutine, make sure your RCX is on. Then click on the play button in the toolbar. If all goes well, you should hear your RCX play a simple beep.
Summary of Contents for MINDSTORMS Robots
Page 22: ...Page 18 The back tread wheels are anchored to the shafts with the 16t gears ...
Page 23: ...Page 19 Page 20 Next start building support for the drive motors ...
Page 26: ...Page 23 The touch sensors are attached only by the shaft that runs through them ...
Page 41: ...Page 41 ...
Page 43: ...Next build the support for the light sensor ...
Page 80: ...Page 85 Make sure the bump on the long pin is up against the 4u beam ...
Page 82: ......
Page 84: ...Page 89 ...
Page 85: ...Step 14 is similar to Step 11 take a deep breath and go slowly ...
Page 87: ...Page 91 ...
Page 88: ...Page 92 Make sure that the two sides are at the same angle They should mirror each other ...
Page 89: ...Page 93 Page 94 ...
Page 90: ...Structural Support Page 95 ...
Page 91: ...Idler Wheel Page 96 ...
Page 92: ...Page 97 Drive Motor ...
Page 93: ...While you re putting the motor in hold on to the worm gear so it doesn t slip off Page 98 ...
Page 94: ...Grabber Arm Motor ...
Page 95: ...Page 99 ...
Page 96: ...Page 100 RCX Attach the RCX on both sides as shown Page 101 ...
Page 158: ......
Page 159: ...Page 175 The 16t gears are nestled inside the tread wheels ...
Page 160: ...Page 176 ...
Page 161: ...Page 177 Attach the motors to output A and output C as shown Page 178 ...