Servo example

Dependencies:   Stepper mbed Servo UniServ

Committer:
boro
Date:
Mon Mar 25 13:31:53 2019 +0000
Revision:
0:7e83e43a76b2
Servo example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
boro 0:7e83e43a76b2 1 #include "mbed.h"
boro 0:7e83e43a76b2 2 #include "UniServ.h"
boro 0:7e83e43a76b2 3 #include "Servo.h"
boro 0:7e83e43a76b2 4 #include "Stepper.h"
boro 0:7e83e43a76b2 5
boro 0:7e83e43a76b2 6 // test code for servo and stepper motors
boro 0:7e83e43a76b2 7
boro 0:7e83e43a76b2 8 Servo S0(PB_2);
boro 0:7e83e43a76b2 9 Servo S1(PC_8);
boro 0:7e83e43a76b2 10 Servo S2(PC_6);
boro 0:7e83e43a76b2 11 Servo S3(PB_12);
boro 0:7e83e43a76b2 12
boro 0:7e83e43a76b2 13 int main()
boro 0:7e83e43a76b2 14 {
boro 0:7e83e43a76b2 15
boro 0:7e83e43a76b2 16 // initialise and test Servo
boro 0:7e83e43a76b2 17 S0.Enable(1000,20000);
boro 0:7e83e43a76b2 18 S1.Enable(1000,20000);
boro 0:7e83e43a76b2 19 S2.Enable(1000,20000);
boro 0:7e83e43a76b2 20 S3.Enable(1000,20000);
boro 0:7e83e43a76b2 21
boro 0:7e83e43a76b2 22 printf("initialization succesfull\r\n");
boro 0:7e83e43a76b2 23 /*
boro 0:7e83e43a76b2 24 for (int pos = 775; pos < 2150; pos += 25) {
boro 0:7e83e43a76b2 25 S2.SetPosition(pos);
boro 0:7e83e43a76b2 26 printf("pos = %d\r\n",pos);
boro 0:7e83e43a76b2 27 wait(0.1);
boro 0:7e83e43a76b2 28 }*/
boro 0:7e83e43a76b2 29
boro 0:7e83e43a76b2 30 int i = 500;
boro 0:7e83e43a76b2 31
boro 0:7e83e43a76b2 32 while(1) {
boro 0:7e83e43a76b2 33 /*
boro 0:7e83e43a76b2 34 S2.SetPosition(1500);
boro 0:7e83e43a76b2 35 pwm_motor3.write(0.1f);
boro 0:7e83e43a76b2 36 wait(1);
boro 0:7e83e43a76b2 37 S2.SetPosition(900);
boro 0:7e83e43a76b2 38 pwm_motor3.write(0.0f);
boro 0:7e83e43a76b2 39 wait(1);
boro 0:7e83e43a76b2 40 */
boro 0:7e83e43a76b2 41 printf("position %d\r\n",i);
boro 0:7e83e43a76b2 42 S2.SetPosition(i);
boro 0:7e83e43a76b2 43 i=i+50;
boro 0:7e83e43a76b2 44
boro 0:7e83e43a76b2 45 wait(1.0f);
boro 0:7e83e43a76b2 46
boro 0:7e83e43a76b2 47 }
boro 0:7e83e43a76b2 48 }