servo Helloworld

Dependencies:   Servo_Test mbed Motor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Continuously sweep the servo through it's full range
00002 #include "mbed.h"
00003 #include "Servo.h"
00004 #include "Motor.h"
00005 
00006 Servo myservo(PC_6);
00007 DigitalIn mybut(USER_BUTTON);
00008 Serial pc (USBTX,USBRX);
00009 Motor motor1(PA_8,PC_15,PB_0);
00010 Motor motor2(PA_11,PA_5,PA_6);
00011 
00012 int main() {
00013     pc.baud(9600);
00014     while(1){
00015         motor1.speed(-0.6);
00016         motor2.speed(0.96);
00017         myservo.position(-60);
00018         //pc.printf("My But : %.d \n",mybut);
00019         while(mybut==0) {
00020             
00021             for(int i=-90; i<=-60; i++) {
00022                 myservo.position(i);
00023                 wait(0.025);
00024             }
00025             for(int i=-60; i>-90; i--) {
00026                 myservo.position(i);
00027                 wait(0.005);
00028             }
00029         }
00030     }
00031 }