An ActiveX Control for Real-time Computer Control
by Charles H. Huddleston and Douglas A. Troy


Listing One
Private Sub StartButton_Click()
    Call Lego1.StartLegos
End Sub
Private Sub StopButton_Click()
    Call Lego1.StopLegos
End Sub
Private Sub OnButton_Click()
    Call Lego1.TurnOn(port)
End Sub
Private Sub OffButton_Click()
    Call Lego1.TurnOff(port)
End Sub
Private Sub DirectionButton_Click()
Dim d As Boolean
If Direction = 1 Then d = True Else d = False
Call Lego1.SetDirection(port, d)
End Sub
Private Sub ReverseButton_Click()
    Call Lego1.Reverse(port)
End Sub
Private Sub PowerButton_Click()
    Call Lego1.SetPower(port, Power)
End Sub
The following procedures handle events fired by the Lego Control:
Private Sub Lego1_OnPress(ByVal port As Integer)
    Press(port).Value = 1
End Sub
Private Sub Lego1_OnRelease(ByVal port As Integer)
    Press(port).Value = 0
End Sub
Private Sub Lego1_OnTemperatureChange(ByVal port As Integer, ByVal 
temperature As Double)
Temp(port) = temperature
End Sub
Private Sub Lego1_OnAngleChange(ByVal port As Integer, 
ByVal angle As Integer)
AngleBox(port) = angle
End Sub


Listing Two
<HEAD><TITLE>HTML JavaScript Example</TITLE></HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript" FOR="Lego1" EVENT="OnPress(port)">
<!--
if(port==Document.Form1.SwitchPort.value)
{
Lego1.TurnOn(Document.Form1.MotorPort.value)
}
-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript" FOR="Lego1" EVENT="OnRelease(port)">
<!--
if(port==Document.Form1.SwitchPort.value)
{
Lego1.TurnOff(Document.Form1.MotorPort.value)
}
-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript" FOR="Lego1" EVENT="OnAngleChange(port, angle)">
<!--
if(port==Document.Form1.AnglePort.value)
{
Lego1.SetPower(Document.Form1.MotorPort.value, (angle+2)/2)
}
-->
</SCRIPT>
<OBJECT ID="Lego1" WIDTH=49 HEIGHT=51
CLASSID="CLSID:93B2A113-8FF2-11D0-8606-00A0246926AB"
CODEBASE="Lego.ocx">
<PARAM NAME="_Version" VALUE="65536">
<PARAM NAME="_ExtentX" VALUE="1291">
<PARAM NAME="_ExtentY" VALUE="1323">
<PARAM NAME="_StockProps" VALUE="0">
</OBJECT>
<FORM NAME="Form1">
<INPUT LANGUAGE="JavaScript" TYPE=BUTTON VALUE="Start"    ONCLICK="Lego1.StartLegos()"
NAME="StartButton">
<INPUT LANGUAGE="JavaScript" TYPE=BUTTON VALUE="Stop"    ONCLICK="Lego1.StopLegos()"
NAME="StopButton"><BR>
Motor Port: <INPUT VALUE="1" SIZE=1 NAME="MotorPort" MAXLENGTH="1"><BR>
Angle Sensor Port: <INPUT VALUE="7" SIZE=1 NAME="AnglePort" MAXLENGTH="1"><BR>
Switch Port: <INPUT VALUE="4" SIZE=1 NAME="SwitchPort" MAXLENGTH="1">
</FORM>
</BODY></HTML>


2


