Kompassin käyttöönotto
Tässä esimerkissä robotti kääntyy 90 astetta, jonka jälkeen se ajaa sekunnin eteenpäin.
#pragma config(Sensor, S2, COMPASS, sensorI2CHiTechnicCompass) task main() { wait1Msec(2000); int degrees = 90; // 90 degrees int goal = (SensorValue[COMPASS] + degrees) % 360; // 'goal' is current compass sensor reading + degrees // use modulus(%) 360 to keep the goal within the bounds // of the compassSensor (1 to 360 degrees, 0 is 360). */ while(SensorValue[COMPASS] != goal) // while the compassSensor sensor reading has not reach the goal: { // turn RIGHT in place motor[motorA] = -10; // set motorB to speed -10 motor[motorB] = 10; // set motorB to speed 10 } // stop the robot: motor[motorA] = 0; // set motorA and motorB to speed 0 motor[motorB] = 0; wait1Msec(1000); }