hiro ng / stepping_moter

Files at this revision

API Documentation at this revision

Comitter:
paasukusai
Date:
Tue May 15 03:45:15 2012 +0000
Commit message:
act_stepping_motor

Changed in this revision

stepping_moter.cpp Show annotated file Show diff for this revision Revisions of this file
stepping_moter.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stepping_moter.cpp	Tue May 15 03:45:15 2012 +0000
@@ -0,0 +1,43 @@
+#include"mbed.h"
+#include"stepping_moter.h"
+
+    stepping_moter::stepping_moter(PinName p1,PinName p2,PinName p3,PinName p4) :   _d(p1,p2,p3,p4){
+        _d=0;
+        }
+
+void stepping_moter::step_moter(int deg_set,double wait_time){
+    unsigned int end=1;
+    static int deg_m=0,i;
+while(end){
+    if(deg_m<deg_set){
+        if (i==3) i=0;
+        else i+=1;
+    deg_m+=1;
+    }//if
+    else if(deg_m>deg_set){
+        if (i==0) i=3;
+        else i-=1;
+    deg_m-=1;
+    }
+    else if(deg_m==deg_set){
+    end=0;
+    }
+
+    switch(i){
+    case 0:
+    _d=9;
+    break;
+    case 1:
+    _d=3;
+    break;
+    case 2:
+    _d=6;
+    break;
+    case 3:
+    _d=12;
+    break;
+    }//switch
+    
+    wait(wait_time);
+    }//while
+    }//step_moter
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stepping_moter.h	Tue May 15 03:45:15 2012 +0000
@@ -0,0 +1,13 @@
+#ifndef MBED_STEPPING_MOTER_H
+#define MBED_STEPPING_MOTER_H
+
+class stepping_moter{
+public:
+    stepping_moter(PinName p1,PinName p2,PinName p3,PinName p4);
+    void step_moter(int deg_set, double wait_time);
+    
+    private:
+    BusOut _d;
+};//class
+
+#endif
\ No newline at end of file