RoboCatz.com

Program 3 (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 driveForward() {
  syncMotors( 2, 3 );
  sleep(5000)
}
function hello() {
  alert('something')
};


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('the swing task!')
syncMotors( 2, 3, 30 );
sleep(2000)
stopAllMotors();
sleep(2000)
sleep(2000)
target = 25
gain = 4
while(touchSensorValue()==0) {
  drawText(10,10, lightSensorValue())
  syncMotors(2, 3, 25, (lightSensorValue()-target) * gain)
  sleep(100)
}

    break

  case 2:
    alert('the block challenge')
    setLED(5)
//This program will start motor 2 at 30% power
//Variable i with sleep(100) is used to count 2 seconds
// After the for() loop, the encoder is reset
// The while() loop repeats this process infinitely
// setMotor(1,60);
// trust me, i dont know what im doing.
  resetEncoder(1)
while( touchSensorValue() == 0 ) {

    clearScreen()
    drawText(10,10,encoderValue(1))
    sleep(100)
  
}
encoder=encoderValue(1)
alert(encoder)
syncMotors( 2, 3, 60 )
//sleep(encoder*30)
driveForward(encoder)
syncMotors( 2, 3, -60 )
sleep(encoder*25)
syncMotors( 2, 3, 30, -200 )
sleep(1000)
syncMotors( 2, 3, -60)
 sleep(4000)
stopAllMotors()

    break

  case 3:
    alert('You selected DOWN')
    setLED(6)
syncMotors( 2,3 );
resetEncoder( 2 );
while( encoderValue( 2)<1072 ) {
syncMotors( 2,3, 50 );
}
while( encoderValue( 2)>0 ) {
syncMotors( 2,3, 50 );
}
    sleep(2000)
    break
// i dont no y im here. i just want 2 go 2 the liburary. and im guessing so does dada.bcause there will b food there
  }
}