このライブラリは模型用のDCモータをmbedで直接制御します。 モータは正転、反転動作が可能です。 モータの回転速度は可変できます。 This library is directly controlled by a DC motor for model mbed. Motor forward rotation, inversion operation is possible. The motor speed is adjustable.

Dependents:   adxl335_motor_direction

Revision:
0:ade473623320
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DcMotorDirectDrive.cpp	Mon Dec 05 12:09:54 2011 +0000
@@ -0,0 +1,54 @@
+/**********************************************************
+
+*    DcMotorDirectDrive.cpp
+*    Dc motor direct drive library
+*
+**********************************************************/
+#define _DCMOTORDIRECTDRIVE_C
+
+#include "types.h"
+#include "mbed.h"
+#include "DcMotorDirectDrive.h"
+
+
+
+
+/** DC motor direct drive object connected to the specified DigtalOutput pin
+ */
+DcMotorDirectDrive::DcMotorDirectDrive(PinName pwmPin, PinName referencePin) :
+ _pwmPin(pwmPin), _referencePin(referencePin){
+ 
+    // pwm setting
+    _referencePin = 0;
+    _pwmPin.period_us(Z_pwmPeriod);  // pwm period 0.1[ms](10[kHz])
+    _pwmPin.write(0.0);
+        
+}
+
+    
+
+
+/**************************************
+* main
+**************************************/
+void DcMotorDirectDrive::DcMotorDirectDrive_main(float request) {
+    if(request > Z_stopRange){
+        // normal rotation
+        _referencePin = 0;
+        _pwmPin.write(request);
+    }
+    else if(request < -Z_stopRange){
+        // reversal rotation
+        _referencePin = 1;
+        _pwmPin.write(1.0f + request);
+        
+    }
+    else{
+        // stop
+        _referencePin = 0;
+        _pwmPin.write(0.0);        
+    }   
+ 
+}
+
+