Hever Zelaya Solano / ServorKeyboard

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers servo.cpp Source File

servo.cpp

00001 #include "servo.h"
00002 PwmOut servo(p21);
00003 
00004 void setServo(){
00005     servo.pulsewidth_us(1500);
00006     wait(2);
00007     }
00008     
00009 void moveServo(char a){
00010     switch(a){
00011         case 1: servo.pulsewidth_us(pulsewidth(-90)); break;
00012         case 2: servo.pulsewidth_us(pulsewidth(-67.5)); break;
00013         case 3: servo.pulsewidth_us(pulsewidth(-45)); break;
00014         case 4: servo.pulsewidth_us(pulsewidth(-22.5)); break;
00015         case 5: servo.pulsewidth_us(pulsewidth(0)); break;
00016         case 6: servo.pulsewidth_us(pulsewidth(22.5)); break;
00017         case 7: servo.pulsewidth_us(pulsewidth(45)); break;
00018         case 8: servo.pulsewidth_us(pulsewidth(67.5)); break;
00019         case 9: servo.pulsewidth_us(pulsewidth(90)); break;
00020         }
00021     
00022     }
00023 
00024 int pulsewidth(int a){
00025   return 1500 + 10*a;
00026 }