Example of usage of encoder library

Dependencies:   Encoder MODSERIAL mbed

Committer:
vsluiter
Date:
Wed Oct 02 10:08:03 2013 +0000
Revision:
1:8d99355e740b
Parent:
0:836046040450
Example of Encoder library usage. Added comments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:836046040450 1 #include "mbed.h"
vsluiter 0:836046040450 2 #include "encoder.h"
vsluiter 1:8d99355e740b 3 /** Use MODSERIAL to have non-blocking serial communication
vsluiter 1:8d99355e740b 4 * Not absolutely needed in this example, but it's a good habbit
vsluiter 1:8d99355e740b 5 */
vsluiter 0:836046040450 6 #include "MODSERIAL.h"
vsluiter 0:836046040450 7
vsluiter 0:836046040450 8
vsluiter 0:836046040450 9 int main() {
vsluiter 1:8d99355e740b 10 /** Make encoder object.
vsluiter 1:8d99355e740b 11 * First pin should be on PTAx or PTDx because those pins can be used as InterruptIn
vsluiter 1:8d99355e740b 12 * Second pin can be any digital input
vsluiter 1:8d99355e740b 13 */
vsluiter 0:836046040450 14 Encoder motor1(PTD0,PTC9);
vsluiter 1:8d99355e740b 15 /*Use USB serial to send values*/
vsluiter 0:836046040450 16 MODSERIAL pc(USBTX,USBRX);
vsluiter 1:8d99355e740b 17 /*Set baud rate to 115200*/
vsluiter 0:836046040450 18 pc.baud(115200);
vsluiter 1:8d99355e740b 19 while(1) { //Loop
vsluiter 1:8d99355e740b 20 /**Wait to prevent buffer overflow, and to keep terminal readable (not scrolling too fast)*/
vsluiter 0:836046040450 21 wait(0.2);
vsluiter 1:8d99355e740b 22 /** print position (integer) and speed (float) to the PC*/
vsluiter 0:836046040450 23 pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed());
vsluiter 0:836046040450 24 }
vsluiter 0:836046040450 25 }