I am trying to create a simple program in VB.NET with the MindSqualls .NET libaray v2.2 (http://www.mindsqualls.net). The program simply records the distances measured by the ultrasonic sensor attached to my Mindstorms 2.0 brick.
My problem is I don't know how to read the Ultrasonic Sensor and the only code I can find on the internet crashes the program without an error.
At the moment I have successfully connected to the NXT with the code below,
Global Variables
Code: Select all
Dim brick As NxtBrick
Dim Sensor_Ultrasonic As New NxtUltrasonicSensor
Code: Select all
Function Connect(port As Integer) As Boolean
Dim COMPortName As String
COMPortName = "COM" & port
Try
brick = New NxtBrick(COMPortName)
brick.Connect()
If brick.IsConnected Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
MsgBox("Error: " & ex.Message)
Label_Status.Text = "Error"
End Try
End Function
Code: Select all
brick.Sensor1 = Sensor_Ultrasonic
AddHandler Sensor_Ultrasonic.OnPolled, AddressOf Sensor_Ultrasonic_OnPolled
Sensor_Ultrasonic.PollInterval = 100
Code: Select all
Sub Sensor_Ultrasonic_OnPolled(ByVal polledItem As NxtPollable)
Dim sensor As NxtUltrasonicSensor = polledItem
[b]Dim Distance As Single = sensor.DistanceCm[/b]
Label1.Text = Distance.ToString
End Sub
Code: Select all
Dim Distance As Single = sensor.DistanceCm
Thanks,
JamesStewy