DC_Motor_rotation using switch

Dependencies:   mbed

Fork of HelloWorld by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
deepakdtelgar
Date:
Thu Dec 01 11:50:12 2016 +0000
Parent:
1:03c191369089
Commit message:
DC_Motor_rotation using switch

Changed in this revision

DC_Motor.cpp Show annotated file Show diff for this revision Revisions of this file
DC_Motor.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DC_Motor.cpp	Thu Dec 01 11:50:12 2016 +0000
@@ -0,0 +1,19 @@
+#include "Dcmotor.h"
+#include "mbed.h"
+ 
+Dcmotor::Dcmotor(PinName1 pin1,PinName2 pin2) : pins(pin1,pin2) {
+    pins = 0;
+}
+ 
+void Dcmotor::Dc() {
+    if(pinnm==0)
+    {
+        pins=1;
+        wait(0.2);
+    }
+    if(pinnm==1)
+    {
+        pins=2;
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DC_Motor.h	Thu Dec 01 11:50:12 2016 +0000
@@ -0,0 +1,14 @@
+#ifndef MBED_Dcmotor_H
+#define MBED_Dcmotor_H
+ 
+#include "mbed.h"
+ 
+class Dcmotor {
+public:
+    DigitalIn pinnm(pin);
+    Dcmotor(PinName1 pin1,PinName2 pin2);
+    void Dc();
+  
+private:  
+    BusOut pins(pin1,pin2);
+};
--- a/main.cpp	Sun Jan 01 20:57:57 2012 +0000
+++ b/main.cpp	Thu Dec 01 11:50:12 2016 +0000
@@ -1,12 +1,10 @@
 #include "mbed.h"
-
-DigitalOut myled(LED1);
-
+#include "Dcmotor.h"
+ 
+Dcmotor Rotation;
+ 
 int main() {
-    while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
-    }
+    Rotation.Dc();
+    Rotation.Dc();
 }
+