Option Strict On
Imports NKH.MindSqualls
Imports WinUsbWrapper
Public Class Form1
Dim Brick As NxtBrick = New NxtBrick(NxtCommLinkType.USB, 0)
Dim TS As NxtTouchSensor = New NxtTouchSensor
Dim Switch As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Brick.Disconnect()
Brick.Connect()
Brick.CommLink.SetInputMode(NxtSensorPort.Port1, NxtSensorType.SWITCH, NxtSensorMode.BOOLEANMODE)
Brick.Sensor1 = TS
Brick.Sensor1.PollInterval = 50
AddHandler TS.OnPolled, AddressOf Switch_OnPolled
End Sub
Private Sub Switch_OnPolled(ByVal polledItem As NxtPollable)
Switch = CBool(TS.IsPressed)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Switch = True Then PictureBox1.BackColor = Color.Green
If Switch = False Then PictureBox1.BackColor = Color.Red
End Sub
End Class