fate VAR word 'random what-to-do-next variable choice VAR byte 'selector for branch ticks VAR byte 'amount of time to continue a course mot_L VAR word 'left-motor speed mot_R VAR word 'right-motor speed Lp CON 1 'I/O pin which the left motor is 'on. change accordingly Rp CON 0 'I/O pin which the right motor is 'on. change accordingly hafSec con 25 'Approx. number of ticks in a 1/2 second '==Main Program Loop again: 'Repeat Forever random fate 'Pick a Random Number choice = fate & %1111 'The most sensible random drives are made of mostly 'forward motion with occasional stops and turns. Since 'choice falls in a range of 0-15, we want most choices 'to be straight ahead. To do this, we use a branch 'instruction with 5 choices for left/right/stop; the 'remaining 11 choices drop through to drive forward. branch choice,[left,right,wastaway,right,left] mot_L = 925: mot_R = 949 'Drive forward. 'Adjust these values to 100 above, or below 'the value which stops the motors. (just make sure 'that they both go forward. run: for ticks = 1 to hafsec 'Run motors for 1/2 second pulsout Lp, mot_L 'Output control pulses pulsout Rp, mot_R pause 15 'Wait 15ms. next 'Complete 1/2-sec cycle. goto again 'Repeat Main Loop left: 'Set for left turn mot_L = 825: mot_R = 949 'give mot_R a value to move forward (typically '100 above the stopping point. give mot_L 'the value to stop it. goto run right: 'Set for right turn. mot_L = 925: mot_R = 849 'give mot_R a value to stop it. give mot_L '100 above the stopping point (make sure it 'goes forward.) goto run wastaway: 'Set for a full stop. mot_L = 825: mot_R = 849 'set both motors on their stopping points. goto run