Option Strict On
Imports System.Drawing
Imports System.IO
Imports WinUsbWrapper
Imports NKH.MindSqualls
Public Class Form1
'déclaration de la brique, des sensors et des variables qui reçoivent les valeurs des sensors
Dim Brick As NxtBrick = New NxtBrick(NxtCommLinkType.USB, 0)
Dim TS As NxtTouchSensor = New NxtTouchSensor
Dim CL As Nxt2ColorSensor = New Nxt2ColorSensor
Dim Couleur As Nxt2Color
Dim Switch As Boolean
Dim Compteur As Boolean = False
Dim Tour As Integer
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Brick.CommLink.StopProgram()
End Sub
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.CommLink.SetInputMode(NxtSensorPort.Port3, NxtSensorType.COLORFULL, NxtSensorMode.RAWMODE)
Brick.Sensor1 = TS : TS.PollInterval = 60
Brick.Sensor3 = CL : CL.PollInterval = 50
AddHandler TS.OnPolled, AddressOf Switch_OnPolled
AddHandler CL.OnPolled, AddressOf Color_OnPolled
End Sub
Private Sub Switch_OnPolled(ByVal polledItem As NxtPollable)
Switch = CBool(TS.IsPressed)
End Sub
Private Sub Color_OnPolled(ByVal polledItem3 As NxtPollable)
Couleur = CL.Color.Value
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Switch = True Then
Label1.Text = "ON"
If Compteur = False Then
Compteur = True
Tour = Tour + 1
Label2.Text = Tour.ToString
TextBox1.AppendText(PictureBox1.BackColor.ToString & vbCrLf)
PB3.CreateGraphics.FillEllipse(New SolidBrush(PictureBox1.BackColor), 30 * (Tour - 1), 0, 30, 30)
End If
Else
Label1.Text = "OFF"
Compteur = False
End If
Select Case Couleur
Case CType(1, Nxt2Color)
PictureBox1.BackColor = PictureBox1.BackColor
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)
End Select
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), 1) & " v"
JaugeBatterie.CreateGraphics.Clear(Color.White)
JaugeBatterie.CreateGraphics.FillRectangle(Brushes.OliveDrab, 0, 0, CInt(Brick.BatteryLevel / 100) * 3, 30)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Brick.CommLink.StartProgram("mixsorter.rxe")
End Sub
End Class