Gets user Input to turn the servo to certain degrees
servo.cpp
- Committer:
- hzelayasolano22
- Date:
- 2019-01-14
- Revision:
- 7:78973b67cd90
- Parent:
- 6:27284b61ae0c
File content as of revision 7:78973b67cd90:
#include "servo.h" PwmOut servo(p21); void setServo(){ servo.pulsewidth_us(1500); wait(2); } void moveServo(char a){ switch(a){ case 1: servo.pulsewidth_us(pulsewidth(-90)); break; case 2: servo.pulsewidth_us(pulsewidth(-67.5)); break; case 3: servo.pulsewidth_us(pulsewidth(-45)); break; case 4: servo.pulsewidth_us(pulsewidth(-22.5)); break; case 5: servo.pulsewidth_us(pulsewidth(0)); break; case 6: servo.pulsewidth_us(pulsewidth(22.5)); break; case 7: servo.pulsewidth_us(pulsewidth(45)); break; case 8: servo.pulsewidth_us(pulsewidth(67.5)); break; case 9: servo.pulsewidth_us(pulsewidth(90)); break; } } int pulsewidth(int a){ return 1500 + 10*a; }