this isn't working the servo just twitches

Dependencies:   Servo mbed Motor

main.cpp

Committer:
Ty
Date:
2014-10-23
Revision:
2:c754297f78ff
Parent:
1:7fa77283f89e

File content as of revision 2:c754297f78ff:

// Ty LaFramboise, Jin Soo Park, Kevin Saxton
//Project 1
//Professor Piepmeier


#include "mbed.h"
#include "Servo.h"
#include "Motor.h"
DigitalIn sw1(p16);
 Motor m(p26,p29,p30);
  float motspeed=.4;
int count = 0;
int count2 = 0;
Servo launchservo(p21);
BusOut lights(p5, p6, p7, p8);
DigitalIn sw4(p19);
Servo myservo1(p22);                        //inititalize motors and servo
DigitalIn sw2(p17);
DigitalIn sw3(p18);
float servopos; //current position of servos
    float waittime=0.02;
int launchswitch;
int main()
{
    float i;
    launchservo=0;
    while(1) {
        //DC Motor
        while (count < 5 && sw1 !=0) {//DC Motor gets power to turn counter clockwise
            m.speed(motspeed);
            wait(.08);
            m.speed(0.0);
            wait(.3);
            count ++;
        }
        while (count2 < 5 && sw1 !=0) {//DC Motor gets power to turn clockwise
            m.speed(-motspeed);
            wait(.08);
            m.speed(0.0);
            wait(.3);
            count2 ++;
 
        }
        count=0;
        count2=0;
        if(sw1==0) {
 
        }
            // riser servo
            if(sw2==1) {
            servopos=0.5;
            while(sw2==1) {
                servopos+=0.0025;
                wait(waittime);
                myservo1=servopos;
                
            }
        }
        if(sw3==1) {
            servopos=myservo1;
 
            while(sw3==1) {
                servopos-=0.0025;
                wait(waittime);
                myservo1=servopos;
            }
}
        //launch servo
        if(sw4) {
            lights=15;// LED light countdown
            wait(.5);
            lights=14;
            wait(.5);
            lights=12;
            wait(.5);
            lights=8;
            wait(.5);
            lights=0;
            wait(.5);
            printf("a\n");
            for (i=0; i<=1.0; i+=.01) {
                launchservo=i;//Turns the servo releasing the plane
               printf("b\n"); 
                wait(.01);
                

            }

        }

    }
}