Gets user Input to turn the servo to certain degrees

Dependencies:   mbed

Committer:
hzelayasolano22
Date:
Sun Jan 13 22:33:48 2019 +0000
Revision:
6:27284b61ae0c
Parent:
3:5b6a55afc60a
Child:
7:78973b67cd90
fixed angles for servo;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hzelayasolano22 2:9d9717796ab2 1 #include "servo.h"
hzelayasolano22 2:9d9717796ab2 2 PwmOut servo(p21);
hzelayasolano22 2:9d9717796ab2 3
hzelayasolano22 2:9d9717796ab2 4 void setServo();
hzelayasolano22 2:9d9717796ab2 5 servo.period(0.020);
hzelayasolano22 2:9d9717796ab2 6 servo.pulsewidth_us(1500);
hzelayasolano22 2:9d9717796ab2 7 wait(2);
hzelayasolano22 2:9d9717796ab2 8 }
hzelayasolano22 2:9d9717796ab2 9
hzelayasolano22 2:9d9717796ab2 10 void moveServo(char a){
hzelayasolano22 2:9d9717796ab2 11 switch(a){
hzelayasolano22 2:9d9717796ab2 12 case 1: servo.pulsdewidth_us(pulsewidth(-90)); break;
hzelayasolano22 6:27284b61ae0c 13 case 2: servo.pulsdewidth_us(pulsewidth(-67.5)); break;
hzelayasolano22 6:27284b61ae0c 14 case 3: servo.pulsdewidth_us(pulsewidth(-45)); break;
hzelayasolano22 6:27284b61ae0c 15 case 4: servo.pulsdewidth_us(pulsewidth(-22.5)); break;
hzelayasolano22 6:27284b61ae0c 16 case 5: servo.pulsdewidth_us(pulsewidth(0)); break;
hzelayasolano22 6:27284b61ae0c 17 case 6: servo.pulsdewidth_us(pulsewidth(22.5)); break;
hzelayasolano22 6:27284b61ae0c 18 case 7: servo.pulsdewidth_us(pulsewidth(45)); break;
hzelayasolano22 6:27284b61ae0c 19 case 8: servo.pulsdewidth_us(pulsewidth(67.5)); break;
hzelayasolano22 6:27284b61ae0c 20 case 9: servo.pulsdewidth_us(pulsewidth(90)); break;
hzelayasolano22 2:9d9717796ab2 21 }
hzelayasolano22 2:9d9717796ab2 22
hzelayasolano22 3:5b6a55afc60a 23 }
hzelayasolano22 3:5b6a55afc60a 24
hzelayasolano22 3:5b6a55afc60a 25 int pulsewidth(int a){
hzelayasolano22 3:5b6a55afc60a 26 return 1500 + 10*a;
hzelayasolano22 3:5b6a55afc60a 27 }