servos

Dependencies:   Servo mbed

servos.cpp

Committer:
m215910
Date:
2018-10-12
Revision:
1:46040c1dc16d
Parent:
main.cpp@ 0:4e3507ef1416

File content as of revision 1:46040c1dc16d:

    
    
    //#include "Motor.h" //must change line 31 in Motor.cpp according to Lab
    #include "mbed.h"
    #include "Servo.h"
    
    
    float pos = rand()/(float)RAND_MAX; //allows the servo to start at a random position 
    float pos2 = rand()/(float)RAND_MAX;
    Servo servo1(p21);
    Servo servo2(p22);
    DigitalIn sw1(p16);
    int sw1state;
    int i=1;
    
    int main() {
         
        servo1.calibrate(0.0009, 90.0); //need to calibrate the servos so they don't freak out
        servo2.calibrate(0.0009, 90.0);
        servo1=pos; //used to help calibrate
        servo2=pos2;
        
        while(1) {
        pos=0;
        pos2=0;
        sw1state=sw1.read();
        
        if((sw1state) == 1) { //if switch is on move servos quickly to other angle
            servo1 = i;
            servo2 = i;}
        if((sw1state) == 0) { //if switch is off move back
            servo1 = 0;
            servo2 = 0;}
            }}