Mbeb + Stepping Motor

Mbeb + Stepping Motor.Stepper motor is a brushless DC motor that divides the full rotation angle of 360° into number of equal steps. The motor is rotated by applying certain sequence
 

Use Mbed microcontroller and stepping motor.

Code

#include “mbed.h”

DigitalOut a(dp24);
DigitalOut a_(dp25);
DigitalOut b(dp26);
DigitalOut b_(dp28);
int i=0;
void rotate(){
     if(i>3){
        i=0;
    }
    else if(i<0){
         i=3;
    }
    if(i==0){
        a=1;
        a_=0;
        b=0;
        b_=1;
    }
    else if(i==1){
        a=1;
        a_=0;
        b=1;
        b_=0;
    }
    else if(i==2){
        a=0;
        a_=1;
        b=1;
        b_=0;
    }
    else if(i==3){
        a=0;
        a_=1;
        b=0;
        b_=1;

    }      

   wait(0.005);
}
void cw(uint16_t step){
  for(int count=0;count<step;count++){
        i++;
        rotate();
    }
}
void ccw(uint16_t step){
  for(int count=0;count<step;count++){
        i–;
        rotate();
    }
}
int main() {
    while(1) {
        wait(2);
        cw(240);
        wait(1);
        cw(12);
        wait(1);
        cw(12);
        wait(1);
        cw(12);
        wait(1);
        cw(12);
        wait(1);

        wait(1);
        ccw(12);
        wait(1);
        ccw(12);
        wait(1);
        ccw(12);
        wait(1);
        ccw(12);
        wait(1);
        ccw(240);
    }
}

Sponsored Links: