Option Strict On
Imports WinUsbWrapper
Imports NKH.MindSqualls
Public Class Form1
Dim Brick As NxtBrick = New NxtBrick(NxtCommLinkType.USB, 0)
Dim TS As NxtTouchSensor = New NxtTouchSensor
Dim UL As NxtUltrasonicSensor = New NxtUltrasonicSensor
Dim CL As Nxt2ColorSensor = New Nxt2ColorSensor
Dim LL As NxtLightSensor = New NxtLightSensor
Dim Couleur As Nxt2Color
Dim Lumiere As Byte
Dim Distance As Byte
Dim Switch As Boolean
Private Sub Switch_OnPolled(ByVal polledItem As NxtPollable)
Switch = CBool(TS.IsPressed)
End Sub
Private Sub UltrasonicSensor_OnPolled(ByVal polledItem2 As NxtPollable)
Distance = CByte(UL.DistanceCm)
End Sub
Private Sub Color_OnPolled(ByVal polledItem3 As NxtPollable)
If CheckBox1.Checked = False Then Exit Sub
Couleur = CL.Color.Value
End Sub
Private Sub Light_OnPolled(ByVal polledItem4 As NxtPollable)
If CheckBox1.Checked = True Then Exit Sub
Lumiere = CByte(LL.Intensity)
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
Brick.CommLink.SetInputMode(NxtSensorPort.Port3, NxtSensorType.COLORFULL, NxtSensorMode.RAWMODE)
Brick.Sensor3 = CL
Brick.Sensor3.PollInterval = 70
Else
Brick.CommLink.SetInputMode(NxtSensorPort.Port3, NxtSensorType.COLORNONE, NxtSensorMode.PCTFULLSCALEMODE)
Brick.Sensor3 = LL
Brick.Sensor3.PollInterval = 400
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Brick.Disconnect()
Brick.Connect()
Dim hoho As NxtGetFirmwareVersionReply = CType(Brick.CommLink.GetFirmwareVersion, NxtGetFirmwareVersionReply)
Label12.Text = "Version Firmware = " & hoho.firmwareVersion.ToString
Label10.Text = "Nom : " & Brick.Name
Brick.CommLink.SetInputMode(NxtSensorPort.Port1, NxtSensorType.SWITCH, NxtSensorMode.BOOLEANMODE)
Brick.CommLink.SetInputMode(NxtSensorPort.Port4, NxtSensorType.LOWSPEED, NxtSensorMode.RAWMODE)
CheckBox1.Checked = True
Brick.Sensor1 = TS
Brick.Sensor1.PollInterval = 50
Brick.Sensor4 = UL
Brick.Sensor4.PollInterval = 80
AddHandler TS.OnPolled, AddressOf Switch_OnPolled
AddHandler UL.OnPolled, AddressOf UltrasonicSensor_OnPolled
AddHandler CL.OnPolled, AddressOf Color_OnPolled
AddHandler LL.OnPolled, AddressOf Light_OnPolled
End Sub
Private Sub Frequence_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Frequence.Scroll
Brick.PlayTone(CUShort(Frequence.Value), 50)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label2.Text = Distance.ToString
Jauge.CreateGraphics.Clear(Color.White)
Jauge.CreateGraphics.FillRectangle(Brushes.BlueViolet, 0, 0, Distance, 30)
If Switch = True Then Label1.Text = "OK"
If Switch = False Then Label1.Text = "Non OK"
Select Case Couleur
Case CType(1, Nxt2Color)
PictureBox1.BackColor = Color.Black
Case CType(2, Nxt2Color)
PictureBox1.BackColor = Color.Blue
Case CType(3, Nxt2Color)
PictureBox1.BackColor = Color.Green
Case CType(4, Nxt2Color)
PictureBox1.BackColor = Color.Yellow
Case CType(5, Nxt2Color)
PictureBox1.BackColor = Color.Red
Case CType(6, Nxt2Color)
PictureBox1.BackColor = Color.White
End Select
Label8.Text = CStr(Lumiere)
JaugeLight.CreateGraphics.Clear(Color.White)
JaugeLight.CreateGraphics.FillRectangle(Brushes.GreenYellow, 0, 0, CInt(Lumiere) * 2, 30)
End Sub
Private Sub TimerBattery_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerBattery.Tick
Label4.Text = Decimal.Round(CDec(Brick.BatteryLevel / 1000), 2) & " v"
JaugeBatterie.CreateGraphics.Clear(Color.White)
JaugeBatterie.CreateGraphics.FillRectangle(Brushes.Orange, 0, 0, CInt(Brick.BatteryLevel / 100) * 3, 30)
End Sub
End Class