servos

Dependencies:   Servo mbed

main.cpp

Committer:
m215910
Date:
2018-10-11
Revision:
0:4e3507ef1416

File content as of revision 0:4e3507ef1416:

    
    
    //#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;}
            }}