Dependencies:   mbed nucleo_rotary_encoder

Files at this revision

API Documentation at this revision

Comitter:
inst
Date:
Sun Aug 21 05:00:35 2016 +0000
Commit message:
mbed lib ?

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
rotary_encoder.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Aug 21 05:00:35 2016 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "rotary_encoder_a_phase.hpp"
+#include "rotary_encoder_ab_phase.hpp"
+
+int main() {
+    const size_t encoder_num = 3;
+    rotary_encoder* e[] = {
+        new rotary_encoder_a_phase( /* timer_type = */TIM1, /* pulse_per_revol = */100),
+        new rotary_encoder_ab_phase(/* timer_type = */TIM2, /* pulse_per_revol = */100),
+        new rotary_encoder_ab_phase(/* timer_type = */TIM3, /* pulse_per_revol = */100)
+    };
+    
+    for (size_t i = 0; i < encoder_num; ++i) {
+        e[i]->start();
+    }
+    
+    const float t = 2.0f;
+    
+    while (true) {
+        wait(t);
+        for (size_t i = 0; i < encoder_num; ++i) {
+            // 回転数/秒 に60を掛けて 回転数/分 にする
+            printf("%f, ", (e[i]->get_revol_num() / t) * 60.0f);
+            e[i]->stop();
+        }
+        printf("\n");
+        wait(t);
+        
+        for (size_t i = 0; i < encoder_num; ++i) {
+            e[i]->start();
+        }
+        wait(t);
+        
+        for (size_t i = 0; i < encoder_num; ++i) {
+            // 回転数/秒 に60を掛けて 回転数/分 にする
+            printf("%f, ", (e[i]->get_revol_num() / t) * 60.0f);
+            e[i]->stop();
+        }
+        printf("\n");
+    }
+    
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Aug 21 05:00:35 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/f9eeca106725
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rotary_encoder.lib	Sun Aug 21 05:00:35 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/inst/code/nucleo_rotary_encoder/#684e1604e5ea