Tip: Click lines to highlight, hold ctrl/cmd to multi-select
http://codedumper.com/ajegu (24-Jan @ 02:23)
Syntax Highlighted Code
- '****************************************************************
- '* Name : UNTITLED.BAS *
- '* Author : Kyle Siopiolosz and Alyssa Mole *
- '* Notice : Copyright (c) 2011 iPod Chargers *
- '* : All Rights Reserved *
- '* Date : 1/18/2011 *
- '* Version : 1.0 *
- '* Notes : *
- '* : *
- '****************************************************************
- 'NOTE: LINE SENSOR SEES NOTHING WHEN = 1, BOT SENSOR SEES NOTHING WHEN = 1
- CMCON = 7
- TRISA = %00000011
- TRISB = %00000000
- REVERSECOUNT VAR BYTE ' Counts how many times the bot has been moving backwards
- LEFTCOUNT VAR BYTE ' Counts how many times the bot has turned left
- RIGHTCOUNT VAR BYTE ' Counts how many times the bot has turned right
- SEED VAR BYTE ' Sets up the first seed within the main routine
- MAINCOUNT VAR BYTE ' Counts how many times the bot returns back to the MAINCOUNT routine
- SYMBOL FORWARD = %00000101 ' Required binary string to tell motors to move forwards
- SYMBOL BACKWARD = %00001010 ' Required binary string to tell motors to move backwards
- SYMBOL LEFTTURN = %00001001 ' Required binary string to tell motors to turn left
- SYMBOL RIGHTTURN = %00000110 ' Required binary string to tell motors to turn right
- REVERSECOUNT = 0 ' Set variable REVERSECOUNT to 0
- LEFTCOUNT = 0 ' Set variable LEFTCOUNT to 0
- SEED = 0 ' Set variable SEED to 0
- MAINCOUNT = 0 ' Set variable MAINCOUNT to 0
- MAIN:
- IF MAINCOUNT < 4 THEN ' Perfoms specificed actions while MAINCOUNT is less then 4
- WHILE PORTA.0 = 1 ' Performs specified actions while line sensor sees nothing
- PORTB = LEFTTURN ' Bot turns left
- SEED = SEED + 1 ' Adds 1 to the SEED variable
- IF SEED =>10 THEN ' Checks if SEED is equal to 10 or greater
- SEED = 0 ' Sets SEED back to 0
- ENDIF ' Ends variable check
- IF PORTA.1 = 0 THEN GOSUB ATTACK ' Checks to see if the botsensor sees sometbing, if it does it goes to the subroutine ATTACK, otherwise it stays in the MAIN loop
- WEND ' Ends while statement
- GOSUB DODGE ' Goes to the DODGE subroutine
- ELSE ' If MAINCOUNT is not less than 10
- GOTO TREE ' Goes to TREE
- ENDIF
- DODGE:
- WHILE REVERSECOUNT <= 1000 ' Performs action while REVERSECOUNT is less than or equal to 1000
- PORTB = BACKWARD ' Bot moves backwards
- IF PORTA.0 = 0 THEN ' If there is a black surface
- MAINCOUNT = MAINCOUNT + 1 ' Add 1 to MAINCOUNT variable
- GOTO MAIN ' Go back to the MAIN routine
- ENDIF ' Ends the if statement
- REVERSECOUNT = REVERSECOUNT + 1 ' Add 1 to REVERSECOUNT variable
- WEND ' Ends the while statement
- REVERSECOUNT = 0 ' Sets REVERSECOUNT back to 0
- WHILE LEFTCOUNT <= 1000 ' Performs action while LEFTCOUNT is less than or equal to 100
- PORTB = LEFTTURN ' Bot turns left
- IF PORTA.0 = 0 THEN ' If there is a black surface
- MAINCOUNT = MAINCOUNT + 1 ' Add 1 to MAINCOUNT variable
- GOTO MAIN ' Go back to the MAIN routine
- ENDIF ' Ends the if statement
- LEFTCOUNT = LEFTCOUNT + 1 ' Add 1 to REVERSECOUNT variable
- WEND ' Ends the while statement
- LEFTCOUNT = 0 ' Sets LEFTCOUNT back to 0
- IF PORTA.0 = 1 THEN ' If there is still a line
- GOSUB DODGE2 ' Goes to DODGE2 Subroutine
- ENDIF ' Ends if
- IF PORTA.0 = 0 THEN ' If there is no line
- RETURN ' Returns to previous routine
- ENDIF ' Ends if
- DODGE2:
- WHILE RIGHTCOUNT <= 1000 ' Performs action while RIGHTCOUNT is less than or equal to 1000
- PORTB = RIGHTTURN ' Bot moves backwards
- IF PORTA.0 = 0 THEN ' If there is a black surface
- MAINCOUNT = MAINCOUNT + 1 ' Add 1 to MAINCOUNT variable
- GOTO MAIN ' Go back to the MAIN routine
- ENDIF ' Ends the if statement
- RIGHTCOUNT = RIGHTCOUNT + 1 ' Add 1 to RIGHTCOUNT variable
- WEND ' Ends the while statement
- RIGHTCOUNT = 0 ' Sets RIGHTCOUNT back to 0
- WHILE REVERSECOUNT <= 1000 ' Performs action while REVERSECOUNT is less than or equal to 1000
- PORTB = BACKWARD ' Bot moves backwards
- IF PORTA.0 = 0 THEN ' If there is a black surface
- MAINCOUNT = MAINCOUNT + 1 ' Add 1 to MAINCOUNT variable
- GOTO MAIN ' Go back to the MAIN routine
- ENDIF ' Ends the if statement
- REVERSECOUNT = REVERSECOUNT + 1 ' Add 1 to REVERSECOUNT variable
- WEND ' Ends the while statement
- REVERSECOUNT = 0 ' Ends the while statement
- IF PORTA.0 = 1 THEN ' If there is still a line
- GOSUB DODGE ' Goes to DODGE2 Subroutine
- ENDIF ' Ends if
- IF PORTA.0 = 0 THEN ' If there is no line
- RETURN ' Returns to previous routine
- ENDIF ' Ends if
- ATTACK:
- WHILE PORTA.1 = 0 ' While bot sees another (bot)?
- PORTB = FORWARD ' Bot moves forward
- WEND ' End if
- RETURN ' Returns to previous routine
- TREE:
- IF SEED < = 3 THEN ' Checks if SEED is less than or equal to 3
- GOTO SEEK1 ' Goes to SEEK1
- ENDIF ' Ends if statement
- IF SEED < = 6 THEN ' SEED less than or equal to 6
- GOTO SEEK2 ' Goes to SEEK2
- ENDIF ' Ends if statement
- IF SEED < = 10 THEN ' SEED less than or equal to 10
- GOTO SEEK3 ' Goes to SEEK3
- ENDIF ' Ends if statement
Plain Code
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : Kyle Siopiolosz and Alyssa Mole *
'* Notice : Copyright (c) 2011 iPod Chargers *
'* : All Rights Reserved *
'* Date : 1/18/2011 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
'NOTE: LINE SENSOR SEES NOTHING WHEN = 1, BOT SENSOR SEES NOTHING WHEN = 1
CMCON = 7
TRISA = %00000011
TRISB = %00000000
REVERSECOUNT VAR BYTE ' Counts how many times the bot has been moving backwards
LEFTCOUNT VAR BYTE ' Counts how many times the bot has turned left
RIGHTCOUNT VAR BYTE ' Counts how many times the bot has turned right
SEED VAR BYTE ' Sets up the first seed within the main routine
MAINCOUNT VAR BYTE ' Counts how many times the bot returns back to the MAINCOUNT routine
SYMBOL FORWARD = %00000101 ' Required binary string to tell motors to move forwards
SYMBOL BACKWARD = %00001010 ' Required binary string to tell motors to move backwards
SYMBOL LEFTTURN = %00001001 ' Required binary string to tell motors to turn left
SYMBOL RIGHTTURN = %00000110 ' Required binary string to tell motors to turn right
REVERSECOUNT = 0 ' Set variable REVERSECOUNT to 0
LEFTCOUNT = 0 ' Set variable LEFTCOUNT to 0
SEED = 0 ' Set variable SEED to 0
MAINCOUNT = 0 ' Set variable MAINCOUNT to 0
MAIN:
IF MAINCOUNT < 4 THEN ' Perfoms specificed actions while MAINCOUNT is less then 4
WHILE PORTA.0 = 1 ' Performs specified actions while line sensor sees nothing
PORTB = LEFTTURN ' Bot turns left
SEED = SEED + 1 ' Adds 1 to the SEED variable
IF SEED =>10 THEN ' Checks if SEED is equal to 10 or greater
SEED = 0 ' Sets SEED back to 0
ENDIF ' Ends variable check
IF PORTA.1 = 0 THEN GOSUB ATTACK ' Checks to see if the botsensor sees sometbing, if it does it goes to the subroutine ATTACK, otherwise it stays in the MAIN loop
WEND ' Ends while statement
GOSUB DODGE ' Goes to the DODGE subroutine
ELSE ' If MAINCOUNT is not less than 10
GOTO TREE ' Goes to TREE
ENDIF
DODGE:
WHILE REVERSECOUNT <= 1000 ' Performs action while REVERSECOUNT is less than or equal to 1000
PORTB = BACKWARD ' Bot moves backwards
IF PORTA.0 = 0 THEN ' If there is a black surface
MAINCOUNT = MAINCOUNT + 1 ' Add 1 to MAINCOUNT variable
GOTO MAIN ' Go back to the MAIN routine
ENDIF ' Ends the if statement
REVERSECOUNT = REVERSECOUNT + 1 ' Add 1 to REVERSECOUNT variable
WEND ' Ends the while statement
REVERSECOUNT = 0 ' Sets REVERSECOUNT back to 0
WHILE LEFTCOUNT <= 1000 ' Performs action while LEFTCOUNT is less than or equal to 100
PORTB = LEFTTURN ' Bot turns left
IF PORTA.0 = 0 THEN ' If there is a black surface
MAINCOUNT = MAINCOUNT + 1 ' Add 1 to MAINCOUNT variable
GOTO MAIN ' Go back to the MAIN routine
ENDIF ' Ends the if statement
LEFTCOUNT = LEFTCOUNT + 1 ' Add 1 to REVERSECOUNT variable
WEND ' Ends the while statement
LEFTCOUNT = 0 ' Sets LEFTCOUNT back to 0
IF PORTA.0 = 1 THEN ' If there is still a line
GOSUB DODGE2 ' Goes to DODGE2 Subroutine
ENDIF ' Ends if
IF PORTA.0 = 0 THEN ' If there is no line
RETURN ' Returns to previous routine
ENDIF ' Ends if
DODGE2:
WHILE RIGHTCOUNT <= 1000 ' Performs action while RIGHTCOUNT is less than or equal to 1000
PORTB = RIGHTTURN ' Bot moves backwards
IF PORTA.0 = 0 THEN ' If there is a black surface
MAINCOUNT = MAINCOUNT + 1 ' Add 1 to MAINCOUNT variable
GOTO MAIN ' Go back to the MAIN routine
ENDIF ' Ends the if statement
RIGHTCOUNT = RIGHTCOUNT + 1 ' Add 1 to RIGHTCOUNT variable
WEND ' Ends the while statement
RIGHTCOUNT = 0 ' Sets RIGHTCOUNT back to 0
WHILE REVERSECOUNT <= 1000 ' Performs action while REVERSECOUNT is less than or equal to 1000
PORTB = BACKWARD ' Bot moves backwards
IF PORTA.0 = 0 THEN ' If there is a black surface
MAINCOUNT = MAINCOUNT + 1 ' Add 1 to MAINCOUNT variable
GOTO MAIN ' Go back to the MAIN routine
ENDIF ' Ends the if statement
REVERSECOUNT = REVERSECOUNT + 1 ' Add 1 to REVERSECOUNT variable
WEND ' Ends the while statement
REVERSECOUNT = 0 ' Ends the while statement
IF PORTA.0 = 1 THEN ' If there is still a line
GOSUB DODGE ' Goes to DODGE2 Subroutine
ENDIF ' Ends if
IF PORTA.0 = 0 THEN ' If there is no line
RETURN ' Returns to previous routine
ENDIF ' Ends if
ATTACK:
WHILE PORTA.1 = 0 ' While bot sees another (bot)?
PORTB = FORWARD ' Bot moves forward
WEND ' End if
RETURN ' Returns to previous routine
TREE:
IF SEED < = 3 THEN ' Checks if SEED is less than or equal to 3
GOTO SEEK1 ' Goes to SEEK1
ENDIF ' Ends if statement
IF SEED < = 6 THEN ' SEED less than or equal to 6
GOTO SEEK2 ' Goes to SEEK2
ENDIF ' Ends if statement
IF SEED < = 10 THEN ' SEED less than or equal to 10
GOTO SEEK3 ' Goes to SEEK3
ENDIF ' Ends if statement