Advertisement
IrvinHeslan

VB_Mouse_Bouton_Partie1

Feb 17th, 2014
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.08 KB | None | 0 0
  1. Imports System
  2. Imports System.IO
  3.  
  4. Public Class Form1
  5.     Dim comPorts As Array
  6.     Dim x As Integer
  7.     Dim y As Integer
  8.  
  9.     Private Sub Form(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  10.         comPorts = IO.Ports.SerialPort.GetPortNames()
  11.           SerialPort1.PortName = "COM15"  'le com15 est definit sur lequel la carte arduino est reliée'
  12.           SerialPort1.BaudRate = 9600     'la vitesse est definit'
  13.           SerialPort1.Parity = IO.Ports.Parity.None 'il n'y a pas de bit de parité'
  14.           SerialPort1.StopBits = IO.Ports.StopBits.One 'il n'y pas de bit de stop'
  15.           SerialPort1.DataBits = 8 'ce sont des mots de 8bits qui sont envoyés'
  16.  
  17.         If SerialPort1.IsOpen = False Then
  18.             SerialPort1.PortName = "COM18"
  19.         Else : MsgBox("Le port est Fermé.", MsgBoxStyle.Exclamation, "Erreur")
  20.         End If
  21.     End Sub
  22.  
  23.     Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs)
  24.  
  25.         If SerialPort1.IsOpen = True Then
  26.             Lecture() 'direction vers la fonction lecture'
  27.         End If
  28.  
  29.     End Sub
  30.  
  31.  
  32.     Private Sub Lecture()
  33.         If SerialPort1.IsOpen Then 'boucle conditionnelle si le port1 serie est ouvert alors'
  34.             Dim donnee As String = SerialPort1.ReadExisting() 'la valeur donnee prend la valeur de ce qui est envoyé par la carte Arduino
  35.             TextBox1.Text = donnee 'la zone de texte Textbox1 prend la valeur de donnee
  36.         End If
  37.  
  38.     End Sub
  39.  
  40.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  41.         SerialPort1.Open()  'si le bouton 1 est cliqué alors le port1 s'ouvre
  42.         Timer1.Start() 'et on démarre un timer (compteur)'
  43.     End Sub
  44.  
  45.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  46.     If donnee = 1 Then  'si la valeur donnee est égale a 1 alors'
  47.     x + 1 =  x  'x + 1 prend la valeur de x
  48.     Cursor.Position = New Point(x, y) 'on indique la position du curseur'
  49.    End Sub
  50. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement