PRAWIRA

Files at this revision

API Documentation at this revision

Comitter:
alienbernamaihsan
Date:
Mon Sep 16 10:06:48 2019 +0000
Commit message:
PRAWIRA; ;

Changed in this revision

Motor.cpp Show annotated file Show diff for this revision Revisions of this file
Motor.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 86d90c65f83b Motor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.cpp	Mon Sep 16 10:06:48 2019 +0000
@@ -0,0 +1,17 @@
+#include "Motor.h"
+
+Motor::Motor(PinName dright, PinName dleft, PinName pwmpin): dright_(dright), dleft_(dleft), pwmpin_(pwmpin) {
+    pwmpin_.period_us(50);  
+}
+
+void Motor::setpwm(float inputpwm) {
+    if (inputpwm >= 0) {
+        dright_ = 1;
+        dleft_ = 0;
+        pwmpin_.write(inputpwm);
+    } else {
+        dright_ = 0;
+        dleft_ = 1;
+        pwmpin_.write(-1 * inputpwm);
+    }  
+}
\ No newline at end of file
diff -r 000000000000 -r 86d90c65f83b Motor.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.h	Mon Sep 16 10:06:48 2019 +0000
@@ -0,0 +1,18 @@
+#ifndef MOTOR_H
+#define MOTOR_H
+
+#include "mbed.h"
+
+class Motor {
+    
+public :
+    Motor(PinName dright , PinName dleft, PinName pwmpin);
+    void setpwm(float inputpwm);
+        
+private :
+    PwmOut pwmpin_;
+    DigitalOut dright_;
+    DigitalOut dleft_;   
+};
+
+#endif
\ No newline at end of file