Example of usage of encoder library

Dependencies:   Encoder MODSERIAL mbed

Files at this revision

API Documentation at this revision

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

Encoder.lib Show annotated file Show diff for this revision Revisions of this file
MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- 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
--- 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
--- 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