モータを回すよ

Files at this revision

API Documentation at this revision

Comitter:
m2130
Date:
Wed Feb 02 11:25:12 2022 +0000
Commit message:
moving motors

Changed in this revision

motor.cpp Show annotated file Show diff for this revision Revisions of this file
motor.hpp Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a773f39e5d7a motor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor.cpp	Wed Feb 02 11:25:12 2022 +0000
@@ -0,0 +1,21 @@
+#include "motor.hpp"
+
+Motor::Motor(PinName MP, PinName MM): mp(MP), mm(MM){
+    mp.period_us(2048);
+    mm.period_us(2048);
+}
+
+void Motor::out(double pwm){
+    if(pwm > 0.0){
+        mp = pwm > 0.5 ? 0.5 : pwm;
+        mm = 0.0;
+    }
+    else if(pwm == 0){
+        mp = 0.0;
+        mm = 0.0;
+    }
+    else{
+        mp = 0.0;
+        mm = -pwm > 0.5 ? 0.5 : -pwm;
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r a773f39e5d7a motor.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor.hpp	Wed Feb 02 11:25:12 2022 +0000
@@ -0,0 +1,13 @@
+#ifndef Motor_H 
+#define Motor_H
+#include "mbed.h"
+
+class Motor{
+public:
+    Motor(PinName MP, PinName MM);
+    void out(double pwm);
+private:
+    PwmOut mp;
+    PwmOut mm;
+};
+#endif 
\ No newline at end of file