lunes, 22 de noviembre de 2010

PRACTICA DE LEDS VISUAL

PRACTICA DE ENCENDIDO Y APAGADO DE LEDS MEDIANTE EL PUERTO PARALELO


CODIGO

VERSION 5.00
Begin VB.Form Form1
   Appearance      =   0  'Flat
   BackColor       =   &H80000005&
   Caption         =   "Form1"
   ClientHeight    =   8970
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   9540
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   Picture         =   "Form1.frx":0000
   ScaleHeight     =   8970
   ScaleMode       =   0  'User
   ScaleWidth      =   9540
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton btnSalir
      Caption         =   "Salir"
      Height          =   375
      Left            =   2160
      TabIndex        =   28
      Top             =   7200
      Width           =   1455
   End
   Begin VB.VScrollBar VScroll1
      Height          =   375
      LargeChange     =   5
      Left            =   5280
      Max             =   0
      Min             =   10100
      SmallChange     =   100
      TabIndex        =   20
      Top             =   5040
      Value           =   100
      Width           =   255
   End
   Begin VB.TextBox txtVelocidadKitt
      Height          =   405
      Left            =   4320
      Locked          =   -1  'True
      TabIndex        =   19
      Top             =   5040
      Width           =   1215
   End
   Begin VB.PictureBox imgPrendiRojo
      Height          =   135
      Left            =   5880
      Picture         =   "Form1.frx":58AA
      ScaleHeight     =   75
      ScaleWidth      =   555
      TabIndex        =   18
      Top             =   1200
      Visible         =   0   'False
      Width           =   615
   End
   Begin VB.PictureBox imgPrendiAmarillo
      Height          =   135
      Left            =   4200
      Picture         =   "Form1.frx":5E6C
      ScaleHeight     =   75
      ScaleWidth      =   555
      TabIndex        =   17
      Top             =   1200
      Visible         =   0   'False
      Width           =   615
   End
   Begin VB.PictureBox imgPrendiVerde
      Height          =   135
      Left            =   2400
      Picture         =   "Form1.frx":642E
      ScaleHeight     =   75
      ScaleWidth      =   555
      TabIndex        =   16
      Top             =   1200
      Visible         =   0   'False
      Width           =   615
   End
   Begin VB.PictureBox imgApagRojo
      Height          =   135
      Left            =   5880
      Picture         =   "Form1.frx":69F0
      ScaleHeight     =   75
      ScaleWidth      =   555
      TabIndex        =   15
      Top             =   1200
      Width           =   615
   End
   Begin VB.PictureBox imgApagAmarillo
      Height          =   135
      Left            =   4200
      Picture         =   "Form1.frx":6FB2
      ScaleHeight     =   75
      ScaleWidth      =   555
      TabIndex        =   14
      Top             =   1200
      Width           =   615
   End
   Begin VB.PictureBox imgApagVerde
      Height          =   135
      Left            =   2400
      Picture         =   "Form1.frx":7574
      ScaleHeight     =   75
      ScaleWidth      =   555
      TabIndex        =   13
      Top             =   1200
      Width           =   615
   End
   Begin VB.Timer tmrSecuencia3
      Left            =   1200
      Top             =   5400
   End
   Begin VB.CommandButton btnSecuencia3
      Caption         =   "Secuencia 3"
      Height          =   375
      Left            =   2040
      TabIndex        =   12
      Top             =   6000
      Width           =   1695
   End
   Begin VB.Timer tmrSecuencia2
      Left            =   1200
      Top             =   4800
   End
   Begin VB.CommandButton btnSMotor
      Caption         =   "Secuencia Motor"
      Height          =   375
      Left            =   4200
      TabIndex        =   11
      Top             =   6000
      Width           =   1695
   End
   Begin VB.Timer tmrMotor
      Left            =   480
      Top             =   6000
   End
   Begin VB.CommandButton btnSecuencia2
      Caption         =   "Secuencia 2"
      Height          =   375
      Left            =   6360
      TabIndex        =   10
      Top             =   4560
      Width           =   1695
   End
   Begin VB.Timer tmrSemaforo
      Left            =   480
      Top             =   5400
   End
   Begin VB.CommandButton btnSemaforo
      Caption         =   "Semáforo"
      Height          =   375
      Left            =   6360
      TabIndex        =   9
      Top             =   6000
      Width           =   1695
   End
   Begin VB.Timer Timer1
      Left            =   480
      Top             =   4800
   End
   Begin VB.CommandButton btnSecuencia
      Caption         =   "Secuencia Kitt"
      Height          =   375
      Left            =   4200
      TabIndex        =   7
      Top             =   4200
      Width           =   1695
   End
   Begin VB.CommandButton btnRojoAmarillo
      Caption         =   "Led Amarillo y Rojo"
      Height          =   375
      Left            =   4200
      TabIndex        =   6
      Top             =   3120
      Width           =   1695
   End
   Begin VB.CommandButton btnLed10
      Caption         =   "Apagar todos"
      Height          =   375
      Left            =   2040
      TabIndex        =   5
      Top             =   4560
      Width           =   1695
   End
   Begin VB.CommandButton btnLed9
      Caption         =   "Prender todos"
      Height          =   375
      Left            =   6360
      TabIndex        =   4
      Top             =   3120
      Width           =   1695
   End
   Begin VB.CommandButton btnMotor
      Caption         =   "Motor / Led Rojo"
      Height          =   375
      Left            =   6360
      TabIndex        =   3
      Top             =   1920
      Width           =   1695
   End
   Begin VB.CommandButton btnLed7
      BackColor       =   &H8000000D&
      Caption         =   "Led Verde"
      Height          =   375
      Left            =   2040
      TabIndex        =   2
      Top             =   1920
      Width           =   1575
   End
   Begin VB.CommandButton btnLed6
      Caption         =   "Led Amarillo"
      Height          =   375
      Left            =   4200
      TabIndex        =   1
      Top             =   1920
      Width           =   1575
   End
   Begin VB.CommandButton btnLed5
      Caption         =   "Led Verde y Amarillo"
      Height          =   375
      Left            =   2040
      TabIndex        =   0
      Top             =   3120
      Width           =   1695
   End
   Begin VB.Label Label7
      BackStyle       =   0  'Transparent
      Caption         =   "2008 ©"
      BeginProperty Font
         Name            =   "Verdana"
         Size            =   9
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6120
      TabIndex        =   27
      Top             =   8400
      Width           =   3135
   End
   Begin VB.Label Label6
      BackStyle       =   0  'Transparent
      Caption         =   "Quito - Ecuador"
      BeginProperty Font
         Name            =   "Verdana"
         Size            =   9
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6120
      TabIndex        =   26
      Top             =   8160
      Width           =   3135
   End
   Begin VB.Label Label5
      BackStyle       =   0  'Transparent
      Caption         =   "6to ""A"" Telemática"
      BeginProperty Font
         Name            =   "Verdana"
         Size            =   9
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6120
      TabIndex        =   25
      Top             =   7920
      Width           =   3135
   End
   Begin VB.Label Label4
      BackStyle       =   0  'Transparent
      Caption         =   "Gabriel Reyes"
      BeginProperty Font
         Name            =   "Verdana"
         Size            =   9
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6120
      TabIndex        =   24
      Top             =   7680
      Width           =   3135
   End
   Begin VB.Label Label3
      BackStyle       =   0  'Transparent
      Caption         =   "Hugo Mora"
      BeginProperty Font
         Name            =   "Verdana"
         Size            =   9
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6120
      TabIndex        =   23
      Top             =   7440
      Width           =   3135
   End
   Begin VB.Label Label2
      BackStyle       =   0  'Transparent
      Caption         =   "Trabajo de Arquitectura de PC's"
      BeginProperty Font
         Name            =   "Verdana"
         Size            =   9
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   6120
      TabIndex        =   22
      Top             =   6960
      Width           =   3135
   End
   Begin VB.Line Line9
      X1              =   6120
      X2              =   6120
      Y1              =   1680
      Y2              =   6720
   End
   Begin VB.Line Line8
      X1              =   3960
      X2              =   3960
      Y1              =   1680
      Y2              =   6720
   End
   Begin VB.Line Line7
      X1              =   1800
      X2              =   8280
      Y1              =   5640
      Y2              =   5640
   End
   Begin VB.Line Line6
      X1              =   1800
      X2              =   8280
      Y1              =   3840
      Y2              =   3840
   End
   Begin VB.Line Line5
      X1              =   1800
      X2              =   8280
      Y1              =   2640
      Y2              =   2640
   End
   Begin VB.Line Line4
      X1              =   8280
      X2              =   8280
      Y1              =   1680
      Y2              =   6720
   End
   Begin VB.Line Line3
      X1              =   1800
      X2              =   8280
      Y1              =   6720
      Y2              =   6720
   End
   Begin VB.Line Line2
      X1              =   1800
      X2              =   8280
      Y1              =   1680
      Y2              =   1680
   End
   Begin VB.Line Line1
      X1              =   1800
      X2              =   1800
      Y1              =   1680
      Y2              =   6720
   End
   Begin VB.Label Label1
      BackStyle       =   0  'Transparent
      Caption         =   "Velocidad"
      BeginProperty Font
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   4440
      TabIndex        =   21
      Top             =   4680
      Width           =   1095
   End
   Begin VB.Label lblCuenta
      BackColor       =   &H8000000A&
      Caption         =   "             "
      Height          =   255
      Left            =   480
      TabIndex        =   8
      Top             =   4320
      Visible         =   0   'False
      Width           =   735
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Sub PortOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Byte)
Private Declare Function PortIn Lib "IO.DLL" (ByVal Port As Integer) As Byte
Dim a, b, c, d, e, f As Integer

Private Sub btnLed10_Click()
    PortOut &H378, 0
    Me.Timer1 = False
    Me.tmrSemaforo = False
    Me.tmrMotor = False
    Me.tmrSecuencia2 = False
    Me.tmrSecuencia3 = False
    a = 0
    b = 0
    c = 0
    d = 0
    e = 0
    f = 0
    Me.imgApagAmarillo.Visible = True
    Me.imgApagRojo.Visible = True
    Me.imgApagVerde.Visible = True
    Me.imgPrendiAmarillo.Visible = False
    Me.imgPrendiRojo.Visible = False
    Me.imgPrendiVerde.Visible = False
End Sub
Private Sub btnLed5_Click()
    If Me.imgApagAmarillo.Visible = True And Me.imgApagVerde.Visible = True Then
        PortOut &H378, 96
        Me.imgPrendiAmarillo.Visible = True
        Me.imgPrendiVerde.Visible = True
        Me.imgPrendiRojo.Visible = False
        imgApagAmarillo.Visible = False
        Me.imgApagVerde.Visible = False
        Me.imgApagRojo.Visible = True
    Else
        PortOut &H378, 0
        Me.imgPrendiAmarillo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgPrendiRojo.Visible = False
        imgApagAmarillo.Visible = True
        Me.imgApagVerde.Visible = True
        Me.imgApagRojo.Visible = True
    End If
End Sub
Private Sub btnLed6_Click()
    If Me.imgApagAmarillo.Visible = True Then
            PortOut &H378, 32
            Me.imgPrendiAmarillo.Visible = True
            Me.imgPrendiVerde.Visible = False
            Me.imgPrendiRojo.Visible = False
            imgApagAmarillo.Visible = False
            Me.imgApagVerde.Visible = True
            Me.imgApagRojo.Visible = True
        Else
            PortOut &H378, 0
            Me.imgPrendiAmarillo.Visible = False
            Me.imgPrendiVerde.Visible = False
            Me.imgPrendiRojo.Visible = False
            imgApagAmarillo.Visible = True
            Me.imgApagVerde.Visible = True
            Me.imgApagRojo.Visible = True
        End If
End Sub
Private Sub btnLed7_Click()
    If Me.imgApagVerde.Visible = True Then
        PortOut &H378, 64
        Me.imgPrendiAmarillo.Visible = False
        Me.imgPrendiVerde.Visible = True
        Me.imgPrendiRojo.Visible = False
        imgApagAmarillo.Visible = True
        Me.imgApagVerde.Visible = False
        Me.imgApagRojo.Visible = True
    Else
        PortOut &H378, 0
        Me.imgPrendiAmarillo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgPrendiRojo.Visible = False
        imgApagAmarillo.Visible = True
        Me.imgApagVerde.Visible = True
        Me.imgApagRojo.Visible = True
    End If
End Sub
Private Sub btnLed9_Click()
    If Me.imgApagAmarillo.Visible = True And Me.imgApagVerde.Visible = True And Me.imgApagRojo.Visible = True Then
        PortOut &H378, 255
        Me.imgPrendiAmarillo.Visible = True
        Me.imgPrendiVerde.Visible = True
        Me.imgPrendiRojo.Visible = True
        imgApagAmarillo.Visible = False
        Me.imgApagVerde.Visible = False
        Me.imgApagRojo.Visible = False
    Else
        PortOut &H378, 0
        Me.imgPrendiAmarillo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgPrendiRojo.Visible = False
        imgApagAmarillo.Visible = True
        Me.imgApagVerde.Visible = True
        Me.imgApagRojo.Visible = True
    End If
End Sub
Private Sub btnMotor_Click()
    If Me.imgApagRojo.Visible = True Then
        PortOut &H378, 128
        Me.imgPrendiAmarillo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgPrendiRojo.Visible = True
        imgApagAmarillo.Visible = True
        Me.imgApagVerde.Visible = True
        Me.imgApagRojo.Visible = False
    Else
        PortOut &H378, 0
        Me.imgPrendiAmarillo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgPrendiRojo.Visible = False
        imgApagAmarillo.Visible = True
        Me.imgApagVerde.Visible = True
        Me.imgApagRojo.Visible = True
    End If
End Sub
Private Sub btnRojoAmarillo_Click()
    'PortOut &H378, 160
    If Me.imgApagAmarillo.Visible = True And Me.imgApagRojo.Visible = True Then
        PortOut &H378, 160
        Me.imgPrendiAmarillo.Visible = True
        Me.imgPrendiRojo.Visible = True
        Me.imgPrendiVerde.Visible = False
        imgApagAmarillo.Visible = False
        Me.imgApagRojo.Visible = False
        Me.imgApagVerde.Visible = True
    Else
        PortOut &H378, 0
        Me.imgPrendiAmarillo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgPrendiRojo.Visible = False
        imgApagAmarillo.Visible = True
        Me.imgApagVerde.Visible = True
        Me.imgApagRojo.Visible = True
    End If
End Sub

Private Sub btnSalir_Click()
    End
End Sub
Private Sub btnSecuencia_Click()
    If Me.txtVelocidadKitt.Text = "" Or Me.txtVelocidadKitt.Text = "0" Then
        MsgBox "Seleccione algún valor de velocidad mayor a cero"
    Else
         Me.Timer1.Interval = CInt(Me.txtVelocidadKitt.Text)
         Me.Timer1 = True
    End If
End Sub
Private Sub btnSecuencia2_Click()
    Me.tmrSecuencia2.Interval = 1000
    Me.tmrSecuencia2 = True
End Sub
Private Sub btnSecuencia3_Click()
    Me.tmrSecuencia3.Interval = 1000
    Me.tmrSecuencia3 = True
End Sub
Private Sub btnSemaforo_Click()
    Me.tmrSemaforo.Interval = 1000
    Me.tmrSemaforo = True
End Sub

Private Sub btnSMotor_Click()
    Me.tmrMotor.Interval = 1000
    Me.tmrMotor = True
End Sub

Private Sub Timer1_Timer()
    a = a + 1
    lblCuenta.Caption = a
 
    'Secuencia del Kitt
    If a = 1 Then
        PortOut &H378, 64
        Me.imgApagAmarillo.Visible = True
        Me.imgPrendiAmarillo.Visible = False
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = True
        Me.imgApagVerde.Visible = False
    ElseIf a = 2 Then
        PortOut &H378, 32
        Me.imgApagAmarillo.Visible = False
        Me.imgPrendiAmarillo.Visible = True
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgApagVerde.Visible = True
    ElseIf a = 3 Then
        PortOut &H378, 128
        Me.imgApagAmarillo.Visible = True
        Me.imgPrendiAmarillo.Visible = False
        Me.imgApagRojo.Visible = False
        Me.imgPrendiRojo.Visible = True
        Me.imgPrendiVerde.Visible = False
        Me.imgApagVerde.Visible = True
    ElseIf a = 4 Then
        PortOut &H378, 32
        Me.imgApagAmarillo.Visible = False
        Me.imgPrendiAmarillo.Visible = True
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgApagVerde.Visible = True
        a = 0
    End If
End Sub
Private Sub tmrMotor_Timer()
    c = c + 1
    d = d + 1
    If c = 1 Then
        PortOut &H378, 64
        Me.imgApagAmarillo.Visible = True
        Me.imgPrendiAmarillo.Visible = False
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = True
        Me.imgApagVerde.Visible = False
    ElseIf c = 2 Then
        PortOut &H378, 0
        Me.imgApagAmarillo.Visible = True
        Me.imgPrendiAmarillo.Visible = False
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgApagVerde.Visible = True
        c = 0
    End If
    If d = 8 Then
        PortOut &H378, 128
        Me.imgApagAmarillo.Visible = True
        Me.imgPrendiAmarillo.Visible = False
        Me.imgApagRojo.Visible = False
        Me.imgPrendiRojo.Visible = True
        Me.imgPrendiVerde.Visible = False
        Me.imgApagVerde.Visible = True
        Me.tmrMotor = False
    End If
   
    Me.lblCuenta.Caption = d
End Sub
Private Sub tmrSecuencia2_Timer()
    e = e + 1
     'Secuencia 2
    If e = 1 Then
        PortOut &H378, 64
        Me.imgApagAmarillo.Visible = True
        Me.imgPrendiAmarillo.Visible = False
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = True
        Me.imgApagVerde.Visible = False
    ElseIf e = 3 Then
        PortOut &H378, 32
        Me.imgApagAmarillo.Visible = False
        Me.imgPrendiAmarillo.Visible = True
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgApagVerde.Visible = True
    ElseIf e = 5 Then
        PortOut &H378, 96
        Me.imgApagAmarillo.Visible = False
        Me.imgPrendiAmarillo.Visible = True
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = True
        Me.imgApagVerde.Visible = False
        e = 0
    ElseIf (e Mod 2) = 0 Then
        PortOut &H378, 0
        Me.imgApagAmarillo.Visible = True
        Me.imgPrendiAmarillo.Visible = False
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgApagVerde.Visible = True
    End If
End Sub
Private Sub tmrSecuencia3_Timer()
    f = f + 1
    'Secuencia 2
    If f = 1 Then
        PortOut &H378, 64
        Me.imgApagAmarillo.Visible = True
        Me.imgPrendiAmarillo.Visible = False
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = True
        Me.imgApagVerde.Visible = False
    ElseIf f = 2 Then
        PortOut &H378, 32
        Me.imgApagAmarillo.Visible = False
        Me.imgPrendiAmarillo.Visible = True
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = False
        Me.imgApagVerde.Visible = True
        f = 0
    End If
End Sub
Private Sub tmrSemaforo_Timer()
    b = b + 1
    If b = 1 Then
        PortOut &H378, 64
        Me.imgApagAmarillo.Visible = True
        Me.imgPrendiAmarillo.Visible = False
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = True
        Me.imgApagVerde.Visible = False
    ElseIf b = 4 Then
        PortOut &H378, 96
        Me.imgApagAmarillo.Visible = False
        Me.imgPrendiAmarillo.Visible = True
        Me.imgApagRojo.Visible = True
        Me.imgPrendiRojo.Visible = False
        Me.imgPrendiVerde.Visible = True
        Me.imgApagVerde.Visible = False
    ElseIf b = 6 Then
         PortOut &H378, 128
         Me.imgApagAmarillo.Visible = True
         Me.imgPrendiAmarillo.Visible = False
         Me.imgApagRojo.Visible = False
         Me.imgPrendiRojo.Visible = True
         Me.imgPrendiVerde.Visible = False
         Me.imgApagVerde.Visible = True
    ElseIf b = 9 Then
         b = 0
    End If
    
End Sub
Private Sub VScroll1_Change()
    Me.txtVelocidadKitt.Text = CInt(VScroll1.Value)
End Sub

PROTOBOARD TERMINADO:

Aqui se muestra el Protoboard ya terminado con los Leds y el Puerto Paralelo:


Aqui se muestra el Protoboard ya terminado con los Leds:


En esta Imagen el Protoboard con la estudiante del equipo:


En esta imagen se muestra el Programa ya ejecutado:

No hay comentarios:

Publicar un comentario