Dependents:   RobotBase

Revision:
0:89910534fad4
Child:
1:46cf8d086b38
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2CMotor.cpp	Thu Jul 02 00:57:59 2015 +0000
@@ -0,0 +1,26 @@
+#include "I2CMotor.h"
+#include "mbed.h"
+
+I2CMotor::I2CMotor( I2C* i2c, char address ) : I2CDevice( i2c, address ){
+    mActionType = BRAKE;
+    mDuty       = 0;
+    
+    char dutyLimit[ 2 ];
+    
+    ( ( I2CDevice* )this )->read( ( char* )dutyLimit, ( size_t )2 );
+    
+    mMinDuty = dutyLimit[ 0 ];
+    mMinDuty /= 255.0f;
+    
+    mMaxDuty = dutyLimit[ 1 ];
+    mMaxDuty /= 255.0f;
+}
+
+
+void I2CMotor::write(){
+    char trans[] = {
+        static_cast< char >( mActionType ),
+        static_cast< char >( mDuty * 255.0f )
+    };
+    mI2C->write( mAddress, trans, 2 );
+}