The motor encoder stores the degrees of rotation of the motor. Each motor has its own encoder which is updated through a rotation sensor inside the motor. The value of the encoder is reset either by turning the robot off, or by using the resetEncoder() function.
Connect one or motors to the motor ports. Connect a touch sensor to one of the sensor ports. Pressing the touch sensor will reset the encoders.
You can either rotate the motors by hand. Or apply power to the motors. To apply power to motors B and C, uncomment the lines below. setMotor( B, 20 ) setMotor( C, -20 )
You can start, then stop, then re-start the program. The motor encoders continue from their last recorded value. The encoders are not re-set each time you start the program. You could include the resetEncoder() functions at the beginning of your program if you want the encoders to be reset.
Moving robot in a square pattern
Make the robot move around a square. The robot will move straight for 2 seconds and then reset the gyro and turn 90 degrees counter-clockwise. The for() loop will repeat this action 4 times.