...
Kulma-anturin käyttöönotto
Tämän esimerkin ..avulla näet anturin mittaaman:
1) nykyisen kulman alkukulmaan nähden(0-360 astetta)
2) kokonaiskulman
3) kierrosnopeuden (RPM)
Code Block |
---|
#pragma config(Sensor, S2, ANGLE, sensorI2CCustom)
#include "drivers/HTANG-driver.h"
task main () {
nxtDisplayCenteredTextLine(3, "WAIT A MOMENT!");
wait1Msec(3000);
eraseDisplay();
nxtDisplayCenteredTextLine(0, "HiTechnic Angle"); // Just graphics for the display
nxtDisplayTextLine(1, "-------------------");
nxtDisplayTextLine(5, "-------------------");
while (true) {
if (nNxtButtonPressed == kLeftButton) { //left button resets angle value
HTANGresetAngle(ANGLE);
while (nNxtButtonPressed != kNoButton) EndTimeSlice();
} else if (nNxtButtonPressed == kRightButton) { //right button resets all
HTANGresetAccumulatedAngle(ANGLE);
while (nNxtButtonPressed != kNoButton) EndTimeSlice();
}
nxtDisplayTextLine(2, "Ang: %7d deg", HTANGreadAngle(ANGLE)); // Read the current angle,
nxtDisplayTextLine(3, "Tot: %7d deg", HTANGreadAccumulatedAngle(ANGLE)); // total angle and
nxtDisplayTextLine(4, "RPM: %7d", HTANGreadRPM(ANGLE)); // RPM and display them
nxtDisplayTextLine(6, " <-Reset Angle");
nxtDisplayTextLine(7, " Reset Total->");
wait1Msec(50);
}
} |
Code Block |
koodi
|