Code Help

I need help with writing a code that makes two motors spin for around one rotation every 5 seconds. I also want a servo motor that moves based on light sensor values.

This is how it kind of looks like right now.

while(1==1)
{
startmotor (motor1,15);
wait (1);
stopmotor(motor1);

startmotor(motor2,15)
wait(1);
stopmotor(motor1);

if (sensorvalue(lightsensor)>2000)
setServo(servo, -127);

if (sensorvalue(lightsensor)<2000)
setServo(servo, 127);

}

The problem is that only motor1 is spinning and its not stopping.

I also have slight problems with making the servo motor rotating a certain degree.

I don’t have too much time to look at the code itself, but, I would make sure that all of your motors, servos, and sensors are all set up correctly.

I can build a code for you, but I would like to know the following information:

  • Do you want both motors to spin simultaneously?
  • Do you want the robot to work when it’s connected to a remote, or do you want to make the robot to work when autonomous is activated?
  • Would you like me to label what each item/line does?

This is what I got, It activates when the remote is connected, and the two motors don’t operate simultaneously;


while(1==1)
 {
////////////////////////////////////////////////////////////////////
//                                          Motor Program                                        //
//////////////////////////////////////////////////////////////////
  motor[motor1]=15;
  wait1msec(1000);
  motor[motor1=0;
  motor[motor2]=15;
  wait1msec(1000);
  motor[motor2]=0;
///////////////////////////////////////////////////////////////////
//                                                           Servo Program                          //
/////////////////////////////////////////////////////////////////
  if(SensorValue[lightsensor]>2000)
   {
    setServo(servo, -127);//Maybe 'motor[servo]=-127;' would work if this doesn't//
    wait1msec(1000);
   }
  else
   {
    setServo(servo, 127);
    wait1msec(1000);
   }
 }