ROBODYSSEY SYSTEMS LLC
Product Catalog
Code Page
Policies
Gallery
Whats New
Press Releases
Resources
Links
Contact Us
About Us
Press
Educators Page
BasicX and Robotics book
After School
Mini Challenge!
Free Robots to Kids
Hack-A-Toy
Shopping Cart
Page23_2
Home Product Catalog Shopping Cart Resources Links
Code Page Policies Gallery

Follow the line


PIC Home Previous Page Next Page Next Chapter

Page: 1 2

You are ready to program

Copy and Pastable code


Be sure to create a new project first.
For a review of creating projects please go here
Paste BELOW your program name!
PROGRAM NAME CREATED VIA NEW PROJECT!!
COPY AND PASTE FROM NEXT LINE DOWN
'***********************************
Dim Value as Integer
Dim x as Integer
Dim duration as Integer
'***********************************************
Sub Procedure Forward
    PortB = %00000000
    Delay_ms(10)
    PortB = %00101101
    Delay_ms(50)
end sub
'***********************************************
Sub Procedure Reverse
    PortB = %00000000
    Delay_ms(10)
    PortB = %00110011
    Delay_ms(50)
end sub
'***********************************************
Sub Procedure T_Left
    PortB = %00000000
    Delay_ms(10)
    PortB = %00101011
    Delay_ms(50)
end sub
'***********************************************
Sub Procedure T_Right
    PortB = %00000000
    Delay_ms(10)
    PortB = %00110101
    Delay_ms(50)
end sub
'***********************************************
Sub Procedure Halt
    PortB = %00000000
end sub
'***********************************************
Sub Procedure GetValue1
   TrisA = %00001100      ' Set the pulsing ports to output
   Value = 1              ' Start Value at 1
   PortA = %00000001      ' Pulse the capacitor to fill it
   Delay_ms(5)            ' Charge up the capacitor
   TrisA = %00001101      ' Set the port to collect data
   While TestBit(PortA,0) > 0   ' Loop till the capacitor
         Value = Value + 1      ' runs out of juice
   Wend
   If value > 100 Then   ' If it goes over 100 then
       'T_Right step****
       duration = 10     ' Make this number bigger to make it do it longer
       While duration > 0
       T_Left
       duration = duration - 1
       Wend
   End If
End Sub
'*************************
Sub Procedure GetValue2
   TrisA = %00001100      ' Set the pulsing ports to output
   Value = 1              ' Start Value at 1
   PortA = %00000010      ' Pulse the capacitor to fill it
   Delay_ms(5)            ' Charge up the capacitor
   TrisA = %00001110      ' Set the port to collect data
   While TestBit(PortA,1) > 0   ' Loop till the capacitor
         Value = Value + 1      ' runs out of juice
   Wend
   PortB = Value         ' Display the data
   If value > 100 Then   ' If it goes over 100 then
       'T_Right step****
       duration = 10     ' Make this number bigger to make it do it longer
       While duration > 0
       T_Right
       duration = duration - 1
       Wend
   End If
End Sub
'*************************
Main:
  TrisB = %00000000
  TrisA = %00001100      ' Need two inputs for switches
  CMCON = %00000111

  While True
    GetValue1               ' Get left data
    GetValue2               ' Get right Data
    Forward
  Wend
End.
Click here to see a Quicktime movie (.mov) of a robot following a line.
PIC Home Previous Page Next Page Next Chapter

Page: 1 2

Robodyssey and the Robodyssey logo are trademarks of Robodyssey Systems, LLC
PIC is a registered trademark of Microchip Technology Inc. in the U.S. and other countries.
MikroBasic is a registered trademark of mikroElectronika Inc. in the U.S. and other countries.
Home Product Catalog Shopping Cart Resources Links
Code Page Policies Gallery