Gets user Input to turn the servo to certain degrees

Dependencies:   mbed

servo.cpp

Committer:
hzelayasolano22
Date:
2019-01-13
Revision:
3:5b6a55afc60a
Parent:
2:9d9717796ab2
Child:
6:27284b61ae0c

File content as of revision 3:5b6a55afc60a:

#include "servo.h"
PwmOut servo(p21);

void setServo();
    servo.period(0.020);
    servo.pulsewidth_us(1500);
    wait(2);
    }
    
void moveServo(char a){
    switch(a){
        case 1: servo.pulsdewidth_us(pulsewidth(-90)); break;
        case 2: servo.pulsdewidth_us(pulsewidth(-90)); break;
        case 3: servo.pulsdewidth_us(pulsewidth(-90)); break;
        case 4: servo.pulsdewidth_us(pulsewidth(-90)); break;
        case 4: servo.pulsdewidth_us(pulsewidth(-90)); break;
        case 5: servo.pulsdewidth_us(pulsewidth(-90)); break;
        case 6: servo.pulsdewidth_us(pulsewidth(-90)); break;
        case 7: servo.pulsdewidth_us(pulsewidth(-90)); break;
        case 8: servo.pulsdewidth_us(pulsewidth(-90)); break;
        case 9: servo.pulsdewidth_us(pulsewidth(-90)); break;
        }
    
    }

int pulsewidth(int a){
  return 1500 + 10*a;
}