Programación en Visual Basic 2010

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Programacin en visual basic 2010

Imports System
Imports System.Threading
Imports System.IO.Ports
Imports System.ComponentModel
Public Class Form1
Dim myPort As Array
Delegate Sub SetTextCallback(ByVal Form1 As String)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
myPort = IO.Ports.SerialPort.GetPortNames()
ComboBox1.Items.AddRange(myPort)
Button2.Enabled = False
Button1.Enabled = False
Button4.Enabled = False
Label10.Text = "OFF"
Button5.Enabled = False
Button6.Enabled = False
Button3.Enabled = False
Button7.Enabled = False
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown, Button1.KeyUp,
Button1.KeyDown, Button4.KeyDown, Button3.KeyDown, Button2.KeyDown,
Button7.KeyDown
If e.KeyCode = Keys.F Then
Button1.PerformClick()
End If
If e.KeyCode = Keys.B Then
Button2.PerformClick()
End If
If e.KeyCode = Keys.C Then
Button3.PerformClick()
End If
If e.KeyCode = Keys.V Then
Button4.PerformClick()
End If
If e.KeyCode = Keys.X Then
Button7.PerformClick()
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button5.Click
SerialPort1.PortName = ComboBox1.Text
SerialPort1.BaudRate = ComboBox2.Text
SerialPort1.Open()
Button5.Enabled = False
Button1.Enabled = True
Button2.Enabled = True
Label10.Text = "ON"
Button3.Enabled = True
Button4.Enabled = True
Button6.Enabled = True

Button7.Enabled = True
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button6.Click
SerialPort1.Close()
Button5.Enabled = True
Button1.Enabled = False
Button2.Enabled = False
Label10.Text = "OFF"
Button3.Enabled = False
Button4.Enabled = False
Button6.Enabled = False
Button7.Enabled = False
Label11.Text = "-"
Label12.Text = "-"
Label13.Text = "-"
Label14.Text = "-"
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Button5.Enabled = True
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
SerialPort1.Write("I")
Label11.Text = "Encendido"
Label13.Text = "Encendido"
Label14.Text = "Derecha"
Label12.Text = "Derecha"
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
SerialPort1.Write("S")
Label13.Text = "Encendido"
Label11.Text = "Encendido"
Label14.Text = "Izquierda"
Label12.Text = "Derecha"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
SerialPort1.Write("R")
Label11.Text = "Encendido"
Label13.Text = "Encendido"
Label12.Text = "Izquierda"
Label14.Text = "Derecha"
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Button2.Click
SerialPort1.Write("J")
Label11.Text = "Encendido"
Label13.Text = "Encendido"
Label14.Text = "Izquierda"
Label12.Text = "Izquierda"
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button7.Click
SerialPort1.Write("X")
Label11.Text = "Apagado"
Label13.Text = "Apagado"
Label14.Text = "-"
Label12.Text = "-"
End Sub
End Class

Programacin DEL PIC EN PICAXE PROGRAMMING EDITOR


setfreq m8
inicio:
serin C.0, T9600_8,b0 'Comunicamos serie por entrada C.0 y almacena en b0
debug b0 'Mostramos en pantalla
low B.0,1,2,3
pause 10
if b0=83 then goto adelante 'Pulsa tecla adelante asociada a S (S en ASCII equivale a 83 en
decimal)
if b0=82 then goto atras 'Pulsa tecla atras asociada a letra R
if b0=74 then goto izquierda 'Pulsa tecla izquierda asociada a letra J
if b0=73 then goto derecha 'Pulsa tecla derecha asociada a letra I
if b0=88 then goto apagado 'Pulsa tecla apagado asociada a letra I
adelante:
high B.0,2
'pause 1000
'low B.0,2
goto inicio

atras:
high B.1,3
'pause 1000
'low B.1,3
goto inicio
izquierda:
high B.0,3
'pause 1000
'low B.0,3
goto inicio
derecha:
high B.2,1
'pause 1000
'low B.2,1
goto inicio
apagado:
'low B.0,1,2,3
goto inicio

You might also like