'Tiny Bot Version 2 'By Eddy Wright 'Wright Hobbies, LLC 'http://www.wrighthobbies.net 'Dimension Variables Dim Sensors As Byte 'Used to hold a 2-bit representation of the sensors 'Configure ports Config Portd.4 = Input Config Portd.5 = Input Config Portb = Output 'Turn on internal pull-up resistors Portd.4 = 1 Portd.5 = 1 'Set all output on portB to low Portb = 0 'Create friendly names for all ports Leftenable Alias Portb.1 Rightenable Alias Portb.4 Leftin1 Alias Portb.0 Leftin2 Alias Portb.2 Rightin1 Alias Portb.3 Rightin2 Alias Portb.5 Leftsensor Alias Pind.5 Rightsensor Alias Pind.4 'Wait for 10 seconds before starting up Wait 10 'Turn on the Motors Leftenable = 1 Leftin1 = 1 Leftin2 = 0 Rightenable = 1 Rightin1 = 0 Rightin2 = 1 'Main Loop Do 'Check sensor state and put into sensors var Sensors = Leftsensor Sensors = Sensors * 2 Sensors = Sensors + Rightsensor 'Using a Select Case statement is overkill 'for 2 sensors but it greatly enhances the 'legibility of the logic used and allows me 'to add more sensors easily Select Case Sensors Case &B00 'Over the line Rightenable = 1 Leftenable = 1 Case &B01 'Left sees line but right doesn't Rightenable = 1 Leftenable = 0 Case &B10 'Right sees line but left doesn't Rightenable = 0 Leftenable = 1 Case &B11 'Lost the line 'In this case, make no changes 'Continue in the direction prior to losing 'the line End Select Waitms 10 Loop