NXC  Version 1.2.1 r5
 All Data Structures Files Functions Variables Groups Pages

This is an example of how to use the CurrentTick and MotorRotationCount functions.

// Display RPM of motor attached to the port MOTOR while running at full speed.
// The program runs continously until stopped by pressing the gray NXT button.
// Requires NXT firmware 1.28 or later (uses floating point arithmetic).
// CurrentTick returns milliseconds in a long integer.
// MotorRotationCount returns degrees in a long integer.
#define MOTOR OUT_A
#define FULL_SPEED 100
#define DEG_TO_RPM 166.6667 // converts degrees per millisecond to RPM
long prev_tick;
long prev_deg = 0;
string rpm_msg()
long dt = CurrentTick() - prev_tick;
long deg = MotorRotationCount(MOTOR) - prev_deg;
float rpm = deg * DEG_TO_RPM / dt;
prev_deg = MotorRotationCount(MOTOR);
prev_tick = CurrentTick();
return FormatNum("RPM: %5.1f", rpm);
task main()
prev_tick = CurrentTick();
while (true)
Wait(MS_500); // update display every 0.5 seconds
TextOut(0, LCD_LINE2, rpm_msg(), true);