DCmotor rotation depends on pin switch

Dependencies:   mbed

Fork of HelloWorld by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
goutami
Date:
Fri Nov 25 16:58:29 2016 +0000
Parent:
1:03c191369089
Commit message:
DCmotor rotation based on switch pin

Changed in this revision

DCmotor.cpp Show annotated file Show diff for this revision Revisions of this file
DCmotor.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 03c191369089 -r 2187486a8fea DCmotor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DCmotor.cpp	Fri Nov 25 16:58:29 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);
+    }
+}
\ No newline at end of file
diff -r 03c191369089 -r 2187486a8fea DCmotor.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DCmotor.h	Fri Nov 25 16:58:29 2016 +0000
@@ -0,0 +1,15 @@
+#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);
+};
+ 
\ No newline at end of file
diff -r 03c191369089 -r 2187486a8fea main.cpp
--- a/main.cpp	Sun Jan 01 20:57:57 2012 +0000
+++ b/main.cpp	Fri Nov 25 16:58:29 2016 +0000
@@ -1,12 +1,9 @@
 #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();
+}
\ No newline at end of file
diff -r 03c191369089 -r 2187486a8fea mbed.bld
--- a/mbed.bld	Sun Jan 01 20:57:57 2012 +0000
+++ b/mbed.bld	Fri Nov 25 16:58:29 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/078e4b97a13e
+http://mbed.org/users/mbed_official/code/mbed/builds/d75b3fe1f5cb
\ No newline at end of file