kikaikou_ibunshi / Mbed 2 deprecated 5_4

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
komachiangel72
Date:
Wed Oct 30 06:30:25 2019 +0000
Commit message:
agemasu

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 30 06:30:25 2019 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+
+//モータードライバー+回転数計測プログラム
+
+InterruptIn enc(A5);
+DigitalOut led(LED1);
+
+int counter =0;
+
+void event_handler(void){
+    counter++;
+    led =!led;
+}
+
+
+PwmOut AIN1(A1);
+PwmOut AIN2(A2);
+ 
+void motorStop(PwmOut IN1,PwmOut IN2) {
+    IN1 = 1;
+    IN2 = 1;
+}
+ 
+void motorForward(PwmOut IN1,PwmOut IN2,float duty) {
+    motorStop(IN1,IN2);
+    IN1 = duty;
+    IN2 = 0;
+}
+ 
+void motorReverse(PwmOut IN1,PwmOut IN2,float duty) {
+    motorStop(IN1,IN2);
+    IN1 = 0;
+    IN2 = duty;
+}
+ 
+
+int main() {
+
+    while(1) {
+        enc.rise(&event_handler);
+        enc.fall(&event_handler);
+        
+        for(float duty=1.0 ; duty>0 ;duty-=0.1){
+        
+        motorForward(AIN1,AIN2,duty);
+        printf("\nduty:%f\n",duty);
+        wait(5);
+        counter = 0;
+        wait(1);
+        printf("%d\n",counter/24);       
+        motorStop(AIN1,AIN2);
+        wait(1);
+        }
+        
+        for(float duty=1.0 ; duty>0 ;duty-=0.1){
+        
+        motorReverse(AIN1,AIN2,duty);
+        printf("\nduty:%f\n",duty);
+        wait(5);
+        counter = 0;
+        wait(1);
+        printf("%d\n",counter/24);//スリットが12個、0から1までで一回1から0までで一回計測するので12の二倍     
+        motorStop(AIN1,AIN2);
+        wait(1);
+        }
+ 
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 30 06:30:25 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file