Gyro Sensorin käyttöönotto
Tämän esimerkin avulla saat robotin pysähtymään kun sillä on kiihtyvyyttä. Tarkemmat ohjeet: http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NGY1044
#pragma config(Sensor, S2, GYRO, sensorI2CHiTechnicGyro) #include "drivers/HTGYRO-driver.h" task main () { int rotation=0; nxtDisplayTextLine(0, "HT Gyro"); nxtDisplayTextLine(1, "Test 1"); wait1Msec(2000); eraseDisplay(); time1[T1] = 0; while(true) { if (time1[T1] > 1000) { time1[T1] = 0; } if(HTGYROreadRot(GYRO)<-15 && HTGYROreadRot(GYRO)>-40) //between sensor values -15 and -40 { //will get rotation value 1 rotation=1; } else { rotation=2; //else it will be 2 } if (rotation==1) //when rotation value is 1 it will move { motor[motorA]=30; motor[motorB]=30; } if (rotation==2) //when rotation value is 2, robot will stop { motor[motorA]=0; motor[motorB]=0; } eraseDisplay(); nxtDisplayTextLine(1, "Reading"); // Read the current calibration offset and display it nxtDisplayTextLine(2, "Scale: %4d", HTGYROreadCal(GYRO)); nxtDisplayClearTextLine(4); // Read the current rotational speed and display it nxtDisplayTextLine(4, "Gyro: %4d", HTGYROreadRot(GYRO)); wait1Msec(10); } }