VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   BackColor       =   &H80000003&
   Caption         =   "Form1"
   ClientHeight    =   7440
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4395
   DrawStyle       =   1  'Dash
   LinkTopic       =   "Form1"
   ScaleHeight     =   7440
   ScaleMode       =   0  'User
   ScaleWidth      =   4395
   StartUpPosition =   3  'Windows Default
   Begin VB.Timer Timer1 
      Left            =   360
      Top             =   2040
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   360
      Top             =   1320
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.TextBox Text2 
      Height          =   495
      Left            =   120
      TabIndex        =   13
      Text            =   "Text2"
      Top             =   6360
      Width           =   855
   End
   Begin VB.HScrollBar Snelheid 
      Height          =   495
      Left            =   1320
      Max             =   255
      TabIndex        =   9
      Top             =   6360
      Width           =   2895
   End
   Begin VB.CommandButton cmdVenti 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Aan"
      Height          =   375
      Left            =   2400
      Style           =   1  'Graphical
      TabIndex        =   8
      Top             =   4800
      Width           =   855
   End
   Begin VB.CommandButton cmdLicht 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Aan"
      Height          =   375
      Left            =   2400
      MaskColor       =   &H000000FF&
      Style           =   1  'Graphical
      TabIndex        =   7
      Top             =   4320
      Width           =   855
   End
   Begin VB.CommandButton cmdDown 
      BackColor       =   &H00C0E0FF&
      Caption         =   "v"
      Height          =   615
      Left            =   1800
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   3120
      Width           =   735
   End
   Begin VB.CommandButton cmdLeft 
      BackColor       =   &H00C0E0FF&
      Caption         =   "<"
      Height          =   615
      Left            =   1080
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   2520
      Width           =   735
   End
   Begin VB.CommandButton cmdRight 
      BackColor       =   &H00C0E0FF&
      Caption         =   ">"
      Height          =   615
      Left            =   2520
      MaskColor       =   &H8000000F&
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   2520
      Width           =   735
   End
   Begin VB.CommandButton cmdStop 
      BackColor       =   &H00C0E0FF&
      Caption         =   "STOP"
      Height          =   615
      Left            =   1800
      MaskColor       =   &H00C0C0FF&
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   2520
      Width           =   735
   End
   Begin VB.CommandButton cmdForward 
      BackColor       =   &H00C0E0FF&
      Caption         =   "^"
      Height          =   615
      Left            =   1800
      MaskColor       =   &H00C0FFFF&
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   1920
      Width           =   735
   End
   Begin VB.CommandButton cmdQuit 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Quit"
      Height          =   495
      Left            =   2880
      MaskColor       =   &H80000000&
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   600
      Width           =   1215
   End
   Begin VB.CommandButton cmdConnect 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Connect"
      Height          =   495
      Left            =   240
      MaskColor       =   &H80000013&
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   600
      Width           =   1215
   End
   Begin VB.Label Label2 
      BackColor       =   &H80000003&
      Caption         =   "Sturing"
      ForeColor       =   &H00800000&
      Height          =   255
      Left            =   1920
      TabIndex        =   15
      Top             =   1560
      Width           =   735
   End
   Begin VB.Label Label1 
      BackColor       =   &H80000003&
      Caption         =   "Verbinding"
      ForeColor       =   &H00800000&
      Height          =   255
      Left            =   1800
      TabIndex        =   14
      Top             =   120
      Width           =   975
   End
   Begin VB.Label Label5 
      BackColor       =   &H80000003&
      Caption         =   "Ventilator"
      ForeColor       =   &H00800000&
      Height          =   255
      Left            =   1440
      TabIndex        =   12
      Top             =   4920
      Width           =   855
   End
   Begin VB.Label Label4 
      BackColor       =   &H80000003&
      Caption         =   "Zwaailichten"
      ForeColor       =   &H00800000&
      Height          =   255
      Left            =   1200
      TabIndex        =   11
      Top             =   4440
      Width           =   975
   End
   Begin VB.Label Label3 
      BackColor       =   &H80000003&
      Caption         =   "Snelheidsregeling (waarde tussen 0 en 255)"
      ForeColor       =   &H00800000&
      Height          =   375
      Left            =   600
      TabIndex        =   10
      Top             =   5760
      Width           =   3135
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim bit(8), i, value, valueb As Integer

Option Explicit

Private blnConnected As Boolean
Const BTMAC = "00:00:00:00:00:00"
Private MSString As String

Private Sub cmdConnect_Click()
    If blnConnected Then
        DisconnectBT
        
        If MSComm1.PortOpen = True Then
            MSComm1.PortOpen = False
        End If
        cmdConnect.Caption = "&Connect"
        blnConnected = False
    Else
        On Error GoTo err
        MSComm1.CommPort = 11
        MSComm1.Settings = "9600,N,8,1"
        MSComm1.Handshaking = 0
        MSComm1.RThreshold = 1
        MSComm1.InBufferSize = 2048
        MSComm1.OutBufferSize = 2048
        If MSComm1.PortOpen = False Then
            MSComm1.PortOpen = True
            MSComm1.InBufferCount = 0
            If MSComm1.PortOpen = True Then
                blnConnected = True
                cmdConnect.Caption = "&Disconnect"
                ConnectBT
            End If
        End If
    End If
    Exit Sub

err:
    MsgBox err.Number & " " & err.Description, vbExclamation
End Sub



Private Sub Form_KeyPress(KeyAscii As Integer)
  
        If KeyAscii = vbKey4 Then
            Call cmdLeft_Click
        ElseIf KeyAscii = vbKey6 Then
            Call cmdRight_Click
        ElseIf KeyAscii = vbKey8 Then
            Call cmdForward_Click
        ElseIf KeyAscii = vbKey5 Then
            Call cmdStop_Click
        ElseIf KeyAscii = vbKey2 Then
            Call cmdDown_Click
    End If
End Sub

Private Sub MSComm1_OnComm()
    Dim strdata As String

    MSComm1.InputLen = 1
    strdata = MSComm1.Input
    MSString = MSString & strdata
    'If strdata = Chr(13) Then
     '      1st Add "1" & Mid(MSString, 1, Len(MSString) - 1)
   ' End If
End Sub

Private Sub ConnectBT()
    Dim strCommand As String
    Dim testmsg As Integer
    
    strCommand = "con " & BTMAC & Chr$(13)
    MSComm1.Output = strCommand
    
    testmsg = MsgBox("Bluetooth is connected", 0, "Connection")
    valueb = 1
End Sub

Private Sub DisconnectBT()
    Dim strCommand As String
    Dim testmsg2 As Integer
    
    strCommand = "dis" & Chr$(13)
    MSComm1.Output = strCommand
    
    testmsg2 = MsgBox("Bluetooth is disconnected", 0, "Connection")
    valueb = 0
End Sub

Private Sub Form_Load()
    Snelheid_Change
    Me.KeyPreview = True
End Sub

Private Sub Snelheid_Change()
    On Error GoTo err
    Text2.Text = Str(Snelheid.value)
    If MSComm1.PortOpen = True Then
    MSComm1.Output = Chr(getDecFromBit()) + Chr(Snelheid.value) + Chr(0)
    End If
    Exit Sub
    
err:
    MsgBox err.Number & " " & err.Description, vbExclamation

End Sub

Private Function getDecFromBit() As Integer
    Dim buff As Integer
    Dim tel As Integer
    For tel = 1 To 8
        buff = buff + bit(tel) * 2 ^ (tel - 1)
    Next
    getDecFromBit = buff
End Function

Private Sub cmdForward_Click()

cmdForward.BackColor = &HC0FFC0
cmdLeft.BackColor = &HC0E0FF
cmdRight.BackColor = &HC0E0FF
cmdDown.BackColor = &HC0E0FF
cmdStop.BackColor = &HC0E0FF

    On Error GoTo err
    value = 0
    For i = 1 To 4
        bit(i) = 0
    Next
    bit(7) = 0
    bit(8) = 0
    bit(1) = 1
    bit(3) = 1
    MSComm1.Output = Chr(getDecFromBit()) + Chr(Snelheid.value) + Chr(0)
    Exit Sub
    
err:
    MsgBox err.Number & " " & err.Description, vbExclamation
End Sub

Private Sub cmdLeft_Click()

cmdLeft.BackColor = &HC0FFC0
cmdForward.BackColor = &HC0E0FF
cmdRight.BackColor = &HC0E0FF
cmdDown.BackColor = &HC0E0FF
cmdStop.BackColor = &HC0E0FF
    On Error GoTo err
    value = 0
    For i = 1 To 4
        bit(i) = 0
    Next
    bit(7) = 0
    bit(8) = 0
    bit(1) = 1
    MSComm1.Output = Chr(getDecFromBit()) + Chr(Snelheid.value) + Chr(0)
    Exit Sub
    
err:
    MsgBox err.Number & " " & err.Description, vbExclamation

End Sub

Private Sub cmdRight_Click()

cmdRight.BackColor = &HC0FFC0
cmdLeft.BackColor = &HC0E0FF
cmdForward.BackColor = &HC0E0FF
cmdDown.BackColor = &HC0E0FF
cmdStop.BackColor = &HC0E0FF
    On Error GoTo err
    value = 0
    For i = 1 To 4
        bit(i) = 0
    Next
    bit(7) = 0
    bit(8) = 0
    bit(3) = 1
    MSComm1.Output = Chr(getDecFromBit()) + Chr(Snelheid.value) + Chr(0)
    Exit Sub
    
err:
    MsgBox err.Number & " " & err.Description, vbExclamation

End Sub

Private Sub cmdDown_Click()

cmdDown.BackColor = &HC0FFC0
cmdLeft.BackColor = &HC0E0FF
cmdRight.BackColor = &HC0E0FF
cmdForward.BackColor = &HC0E0FF
cmdStop.BackColor = &HC0E0FF
    On Error GoTo err
    value = 0
    For i = 1 To 4
        bit(i) = 0
    Next
    bit(7) = 0
    bit(8) = 0
    bit(2) = 1
    bit(4) = 1
    MSComm1.Output = Chr(getDecFromBit()) + Chr(Snelheid.value) + Chr(0)
    Exit Sub
    
err:
    MsgBox err.Number & " " & err.Description, vbExclamation

End Sub

Private Sub cmdStop_Click()

cmdStop.BackColor = &HC0FFC0
cmdLeft.BackColor = &HC0E0FF
cmdRight.BackColor = &HC0E0FF
cmdDown.BackColor = &HC0E0FF
cmdForward.BackColor = &HC0E0FF
    On Error GoTo err
    value = 0
    For i = 1 To 4
        bit(i) = 0
    Next
    bit(7) = 0
    bit(8) = 0
    MSComm1.Output = Chr(getDecFromBit()) + Chr(Snelheid.value) + Chr(0)
    Exit Sub
    
err:
    MsgBox err.Number & " " & err.Description, vbExclamation

End Sub

Private Sub cmdLicht_Click()


On Error GoTo err
    If cmdLicht.Caption = "Uit" Then
        cmdLicht.Caption = "Aan"
        
        value = 0
        bit(6) = 1
        bit(7) = 0
        bit(8) = 0
        MSComm1.Output = Chr(getDecFromBit()) + Chr(Snelheid.value) + Chr(0)
    Else
        cmdLicht.Caption = "Uit"
     
        value = 0
        bit(6) = 0
        bit(7) = 0
        bit(8) = 0
        MSComm1.Output = Chr(getDecFromBit()) + Chr(Snelheid.value) + Chr(0)
    End If
    Exit Sub
    
err:
    MsgBox err.Number & " " & err.Description, vbExclamation

End Sub

Private Sub cmdVenti_Click()
On Error GoTo err
  If cmdVenti.Caption = "Aan" Then
        cmdVenti.Caption = "Uit"
       
        value = 0
        bit(5) = 1
        bit(7) = 0
        bit(8) = 0
        MSComm1.Output = Chr(getDecFromBit()) + Chr(Snelheid.value) + Chr(0)
    Else
        cmdVenti.Caption = "Aan"
     
        value = 0
        bit(5) = 0
        bit(7) = 0
        bit(8) = 0
        MSComm1.Output = Chr(getDecFromBit()) + Chr(Snelheid.value) + Chr(0)
    End If
    Exit Sub
    
err:
    MsgBox err.Number & " " & err.Description, vbExclamation

End Sub

Private Sub cmdQuit_Click()
    Dim testmsg3 As Integer
    If cmdConnect.Caption = "&Disconnect" Then
        If MSComm1.PortOpen = True Then
            MSComm1.PortOpen = False
        End If
    End If
    If valueb = 1 Then
     testmsg3 = MsgBox("Bluetooth is disconnected", 0, "Connection")
     End If
    Unload Form1
End Sub

'Aurélie De Coster - 2008

