RoboCatz.com

Program 1 (Fall 2019)


The code below is a set of functions, variables, constants, and algorithms that are the work of RoboCatz for the Fall 2019 season.


function driveFoward(degrees){
	syncMotors(2,3,50);
	resetEncoder(2);
	while(encoderValue(2) < degrees) {
		drawText(0,0,encoderValue(2));
	}
	stopAllMotors()
}


function driveBackward(degrees){
	syncMotors(2,3,-50);
	resetEncoder(2);
	while(abs(encoderValue(2)) < degrees) {
		drawText(0,0,encoderValue(2));
	}
	stopAllMotors()
}
function turn(degrees){
	syncMotors( 2, 3,- 50, -80);
	sleep(degrees)
}


while(true) {
  setLED(0)
  clearScreen()

  rect(10,10,160,60)
  drawText(15,30,'Press a key to')
  drawText(15,45,'  select a program')

  keyPressed=waitForPress()

  switch(keyPressed)
  {

  case 1:
    alert('You selected UP')
    alert('hi')
    resetEncoder( 2 );
 	motorCount= encoderValue(2)
    drawText( 50, 50, encoderValue( 2 )-motorCount);
 	// while(true){ sleep(500);}
	syncMotors( 2, 3, 40 );
	while( abs( encoderValue( 2 )-motorCount) < 1055) {
		drawText( 50, 50, encoderValue( 2 )-motorCount);
	}
	stopAllMotors();
	sleep(1000);
	// Find the line
	syncMotors( 2, 3, 40 );
	while( lightSensorValue()>2) {
	}
	stopAllMotors();
	// Treehouse
	driveFoward(25);
	stopAllMotors();
	driveBackward(1000);
	// Turn
	syncMotors( 2, 3, -40,-100 );
	sleep(1000)
	driveBackward(1250);
	stopAllMotors();
    break

  case 2:
	alert('You selected ENTER')
	driveFoward(1300);
	driveBackward(700)
	turn(500)
	driveBackward(1500)
	stopAllMotors();
	break

  case 3:
    alert('You selected DOWN')
	syncMotors( 2, 3, 60 );
    sleep(1500)
    syncMotors( 2, 3, -60 );
    sleep(1000)
	syncMotors( 2, 3, 90, -90 );
	sleep(1750)
	syncMotors( 2, 3, 60 );
	sleep(750)
    stopAllMotors();
	break
 

  case 4:
    alert('You selected RIGHT')
    /*stopAllMotors();
    syncMotors(2,3);
	resetEncoder(2);

	while(encoderValue(2)<720 ) {  
	    clearScreen()
	    drawText(10,10,encoderValue(2))
	    sleep(10)
	}
	stopAllMotors()*/
	driveFoward(1170)
	stopAllMotors();
    setMotor(1,-100);
	resetEncoder(1);

	while(abs(encoderValue(1))<150 ) {  
	    clearScreen()
	    drawText(10,10,encoderValue(1))
	    sleep(10)
	}
	stopAllMotors()
	sleep(100)
    driveBackward(2000)
   break
	
 case 5:
	alert('You selected LEFT')
	while(lightSensorValue()>5) {
		driveFoward()  
		clearScreen()
		drawText(10, 10, lightSensorValue())
		sleep( 100 )
	}
	break
  }
}