![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Example of usage of encoder library
Dependencies: Encoder MODSERIAL mbed
Revision 1:8d99355e740b, committed 2013-10-02
- Comitter:
- vsluiter
- Date:
- Wed Oct 02 10:08:03 2013 +0000
- Parent:
- 0:836046040450
- Commit message:
- Example of Encoder library usage. Added comments.
Changed in this revision
diff -r 836046040450 -r 8d99355e740b Encoder.lib --- a/Encoder.lib Thu Sep 26 14:12:19 2013 +0000 +++ b/Encoder.lib Wed Oct 02 10:08:03 2013 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/vsluiter/code/Encoder/#c90b36abcbf8 +https://mbed.org/users/vsluiter/code/Encoder/#2dd7853c911a
diff -r 836046040450 -r 8d99355e740b MODSERIAL.lib --- a/MODSERIAL.lib Thu Sep 26 14:12:19 2013 +0000 +++ b/MODSERIAL.lib Wed Oct 02 10:08:03 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/Sissors/code/MODSERIAL/#9a41078f0488 +http://mbed.org/users/Sissors/code/MODSERIAL/#b04ce87dc424
diff -r 836046040450 -r 8d99355e740b main.cpp --- a/main.cpp Thu Sep 26 14:12:19 2013 +0000 +++ b/main.cpp Wed Oct 02 10:08:03 2013 +0000 @@ -1,14 +1,25 @@ #include "mbed.h" #include "encoder.h" +/** Use MODSERIAL to have non-blocking serial communication +* Not absolutely needed in this example, but it's a good habbit +*/ #include "MODSERIAL.h" int main() { + /** Make encoder object. + * First pin should be on PTAx or PTDx because those pins can be used as InterruptIn + * Second pin can be any digital input + */ Encoder motor1(PTD0,PTC9); + /*Use USB serial to send values*/ MODSERIAL pc(USBTX,USBRX); + /*Set baud rate to 115200*/ pc.baud(115200); - while(1) { + while(1) { //Loop + /**Wait to prevent buffer overflow, and to keep terminal readable (not scrolling too fast)*/ wait(0.2); + /** print position (integer) and speed (float) to the PC*/ pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed()); } } \ No newline at end of file