What is AI?
Log Book Entries
Basic Stamp 2P40 Source Code
Basic Stamp 2 Source Code
Visual Basic Source Code
Schematic
Pictures
References


Visual Basic Source Code

   The Visual Basic program served one purpose, it acted as the "human to computer" interface. This code would convert the serial signals coming from the robot and display all the gathered information from the sensors and displaying the data on the screen with a graphical front end (also called a GUI, graphical user interface). Our main goal by this was to make the robot as easy to control as possible so that any human being would have no trouble understanding what the robot was detecting. 

Option Explicit

Dim CommandMode As Integer
Dim KillBtn As Boolean

Private Sub Command1_Click()
     KillBtn =
True 'Turn off robot
End Sub

Private Sub Form_Load()
     CommandMode = 254
'Set command
     MSComm1.PortOpen =
True 'Open serial port
End Sub

Private Sub Form_Unload(Cancel As Integer)
    
End 'End program
End Sub

Private Sub MSComm1_OnComm()
    
Dim TmpData As String

    
If MSComm1.CommEvent = comEvReceive Then
          TmpData = MSComm1.Input 'Store serial data to buffer

          'Debug serial data
         
Debug.Print Asc(TmpData) & " " & CommandMode

         
If CommandMode = 254 Then
               CommandMode = Asc(TmpData)
'Store ASCII Type
         
End If

         
If Asc(TmpData) = 254 Then
               CommandMode = 254
'Store integer type
         
End If

         
If CommandMode <> 254 Then
              
Select Case CommandMode 'Command modes
                   
Case 4
                        
Select Case Asc(TmpData)
                             
Case 1
                                   MotorR.Caption = "STOP"
                                   Shape2(5).FillColor = RGB(255, 0, 0)
                                   MotorL.Caption = "STOP"
                                   Shape2(6).FillColor = RGB(255, 0, 0)
                             
Case 2
                                   MotorR.Caption = "REV"
                                   Shape2(5).FillColor = RGB(0, 0, 255)
                                   MotorL.Caption = "REV"
                                   Shape2(6).FillColor = RGB(0, 0, 255)
                             
Case 3
                                   MotorR.Caption = "FWD"
                                   Shape2(5).FillColor = RGB(0, 255, 0)
                                   MotorL.Caption = "FWD"
                                   Shape2(6).FillColor = RGB(0, 255, 0)
                             
Case 4
                                   MotorR.Caption = "FWD"
                                   Shape2(6).FillColor = RGB(0, 255, 0)
                                   MotorL.Caption = "REV"
                                   Shape2(5).FillColor = RGB(0, 0, 255)
                             
Case 5
                                   MotorR.Caption = "REV"
                                   Shape2(6).FillColor = RGB(0, 0, 255)
                                   MotorL.Caption = "FWD"
                                   Shape2(5).FillColor = RGB(0, 255, 0)
                        
End Select
                   
Case 3
                        
If Asc(TmpData) = 250 Then
                              MsgBox "Robot program ended"
                              MotorR.Caption = "STOP"
                              Shape2(5).FillColor = RGB(255, 0, 0)
                              MotorL.Caption = "STOP"
                              Shape2(6).FillColor = RGB(255, 0, 0)
                        
End If
                   
Case 30
                         SonarL.Caption = Asc(TmpData)
                         Shape2(2).FillColor = RGB(0, Asc(TmpData), 0)
                   
Case 31
                         Sonarc.Caption = Asc(TmpData)
                         Shape2(3).FillColor = RGB(0, Asc(TmpData), 0)
                   
Case 32
                         SonarR.Caption = Asc(TmpData)
                         Shape2(4).FillColor = RGB(0, Asc(TmpData), 0)
                   
Case 33
                         IRODL.Caption = Asc(TmpData)
                   
Case 34
                         IRODR.Caption = Asc(TmpData)
                         CommandMode = 254
              
End Select
         
End If
    
End If
End Sub

Private Sub Timer1_Timer()
     MSComm1.Output = Chr(255)
'Handle output
End Sub