liblary for stepping_motor stepping_moter name(pin,pin,pin,pin);φ1,φ2,~φ1,~φ2 name.step_moter(act step,wait time per step)

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stepping_moter.cpp Source File

stepping_moter.cpp

00001 #include"mbed.h"
00002 #include"stepping_moter.h"
00003 
00004     stepping_moter::stepping_moter(PinName p1,PinName p2,PinName p3,PinName p4) :   _d(p1,p2,p3,p4){
00005         _d=0;
00006         }
00007 
00008 void stepping_moter::step_moter(int deg_set,double wait_time){
00009     unsigned int end=1;
00010     static int deg_m=0,i;
00011 while(end){
00012     if(deg_m<deg_set){
00013         if (i==3) i=0;
00014         else i+=1;
00015     deg_m+=1;
00016     }//if
00017     else if(deg_m>deg_set){
00018         if (i==0) i=3;
00019         else i-=1;
00020     deg_m-=1;
00021     }
00022     else if(deg_m==deg_set){
00023     end=0;
00024     }
00025 
00026     switch(i){
00027     case 0:
00028     _d=9;
00029     break;
00030     case 1:
00031     _d=3;
00032     break;
00033     case 2:
00034     _d=6;
00035     break;
00036     case 3:
00037     _d=12;
00038     break;
00039     }//switch
00040     
00041     wait(wait_time);
00042     }//while
00043     }//step_moter