NXT encoder velocity

Hi guys, I am coming here to find some answer on my question about NXT encoder velocity.

I wrote library where I read encoder and where I move motor on specify encoder value but i can not figure out how could I measure velocity. I read already a lot on Internet but I could not write anything useful.

I hope somebody could help me! Thank you !

To make my library work you have to just add to setup function attacheinterrupt (RISING) and create interrupt function where you will call method update.

int motorIN1 = 9;
int motorIN2 = 8;

int eneblePin = 11;


MotorNXT motorNXT(motorIN1, motorIN2, eneblePin, 3, 12);

void encode() {
	motorNXT.update();
	Serial.println(motorNXT.getPosition());
}

void setup() {
	attachInterrupt(1, encode, RISING);
	Serial.begin(115200);
}
void loop() {
}

MotorNXT.cpp (1.6 KB)

MotorNXT.h (644 Bytes)