Servo example

Dependencies:   Stepper mbed Servo UniServ

main.cpp

Committer:
boro
Date:
2019-03-25
Revision:
0:7e83e43a76b2

File content as of revision 0:7e83e43a76b2:

#include "mbed.h"
#include "UniServ.h"
#include "Servo.h"
#include "Stepper.h"

// test code for servo and stepper motors

Servo  S0(PB_2);
Servo  S1(PC_8);
Servo  S2(PC_6);
Servo  S3(PB_12);

int main()
{

    // initialise and test Servo
    S0.Enable(1000,20000);
    S1.Enable(1000,20000);
    S2.Enable(1000,20000);
    S3.Enable(1000,20000);

    printf("initialization succesfull\r\n");
    /*
    for (int pos = 775; pos < 2150; pos += 25) {
        S2.SetPosition(pos);
        printf("pos = %d\r\n",pos);
        wait(0.1);
    }*/
    
    int i = 500;
    
    while(1) {
        /*
        S2.SetPosition(1500);
        pwm_motor3.write(0.1f);
        wait(1);
        S2.SetPosition(900);
        pwm_motor3.write(0.0f);
        wait(1);
        */
        printf("position %d\r\n",i);
        S2.SetPosition(i);
        i=i+50;
        
        wait(1.0f);
        
    }
}