'-------------------------------------------------------------- ' file: digilabs.BAS ' DLC 4/13/2003 ' Wandering object avoider demo code '-------------------------------------------------------------- Dim A As Byte Config Portb = &B10101110 Config Portd = &B11111000 'Port B pins 'B7 = SCK output 'B6 = MISO input 'B5 = MOSI output 'B4 = IRM input 'B3 = 40KHz IR modulation output 'B2 = Left IR LED enable output 'B1 = Right IR LED enable output 'B0 = LED signal output 'Port D pins 'D7 = N/A set to output 'D6 = Left servo output 'D5 = Right servo output 'D4 = LED signal output 'D3 = unassigned output 'D2 = Left line sensor input 'D1 = Center line sensor input 'D0 = Right line sensor input $crystal = 10000000 'Sets 40KHz OC for IRPD LEDs Config Timer1 = Timer , Prescale = 1 , Compare A = Toggle Set Tccr1b.3 Compare1a = 125 Dim Count As Byte Dim Button As Byte Declare Function Getbutton() As Byte Declare Sub Blink5 Do Portd.4 = 0 Button = Getbutton() If Button = 0 Then Call Blink5 End If While Button = 0 Button = Getbutton() Wend Loop Goto Lastone Do If Pinb.0 = 0 Then Portd.4 = 1 Else 'leave off else at first Portd.4 = 0 End If Loop Lastone: Do If Pinb.0 = 0 Then Toggle Portd.4 Waitms 250 Else Toggle Portd.3 Waitms 250 End If Portd.4 = 0 Portd.3 = 0 waitms 250 Loop Secondone: Do While Pinb.0 = 0 Portd.4 = 1 Wend Portd.4 = 0 Loop Thirdone: For Count = 1 To 5 Portd.4 = 1 Waitms 500 Portd.4 = 0 Waitms 500 Next Do Loop Fourthone: Do While Pinb.0 = 0 Toggle Portd.4 Waitms 250 Wend Portd.4 = 0 Loop End Function Getbutton() Dim Dbounce As Bit Dim Dbounce2 As Bit Dbounce = Pinb.0 Waitms 20 Dbounce2 = Pinb.0 If Dbounce = Dbounce2 Then Getbutton = Dbounce Else Getbutton = Dbounce2 End If End Function Sub Blink5 For A = 1 To 5 Set Portd.4 Waitms 250 Reset Portd.4 Waitms 250 Next End Sub