Gets user Input to turn the servo to certain degrees
servo.cpp@7:78973b67cd90, 2019-01-14 (annotated)
- Committer:
- hzelayasolano22
- Date:
- Mon Jan 14 00:35:57 2019 +0000
- Revision:
- 7:78973b67cd90
- Parent:
- 6:27284b61ae0c
FINISHED and IT WORKS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hzelayasolano22 | 2:9d9717796ab2 | 1 | #include "servo.h" |
hzelayasolano22 | 2:9d9717796ab2 | 2 | PwmOut servo(p21); |
hzelayasolano22 | 2:9d9717796ab2 | 3 | |
hzelayasolano22 | 7:78973b67cd90 | 4 | void setServo(){ |
hzelayasolano22 | 2:9d9717796ab2 | 5 | servo.pulsewidth_us(1500); |
hzelayasolano22 | 2:9d9717796ab2 | 6 | wait(2); |
hzelayasolano22 | 2:9d9717796ab2 | 7 | } |
hzelayasolano22 | 2:9d9717796ab2 | 8 | |
hzelayasolano22 | 2:9d9717796ab2 | 9 | void moveServo(char a){ |
hzelayasolano22 | 2:9d9717796ab2 | 10 | switch(a){ |
hzelayasolano22 | 7:78973b67cd90 | 11 | case 1: servo.pulsewidth_us(pulsewidth(-90)); break; |
hzelayasolano22 | 7:78973b67cd90 | 12 | case 2: servo.pulsewidth_us(pulsewidth(-67.5)); break; |
hzelayasolano22 | 7:78973b67cd90 | 13 | case 3: servo.pulsewidth_us(pulsewidth(-45)); break; |
hzelayasolano22 | 7:78973b67cd90 | 14 | case 4: servo.pulsewidth_us(pulsewidth(-22.5)); break; |
hzelayasolano22 | 7:78973b67cd90 | 15 | case 5: servo.pulsewidth_us(pulsewidth(0)); break; |
hzelayasolano22 | 7:78973b67cd90 | 16 | case 6: servo.pulsewidth_us(pulsewidth(22.5)); break; |
hzelayasolano22 | 7:78973b67cd90 | 17 | case 7: servo.pulsewidth_us(pulsewidth(45)); break; |
hzelayasolano22 | 7:78973b67cd90 | 18 | case 8: servo.pulsewidth_us(pulsewidth(67.5)); break; |
hzelayasolano22 | 7:78973b67cd90 | 19 | case 9: servo.pulsewidth_us(pulsewidth(90)); break; |
hzelayasolano22 | 2:9d9717796ab2 | 20 | } |
hzelayasolano22 | 2:9d9717796ab2 | 21 | |
hzelayasolano22 | 3:5b6a55afc60a | 22 | } |
hzelayasolano22 | 3:5b6a55afc60a | 23 | |
hzelayasolano22 | 3:5b6a55afc60a | 24 | int pulsewidth(int a){ |
hzelayasolano22 | 3:5b6a55afc60a | 25 | return 1500 + 10*a; |
hzelayasolano22 | 3:5b6a55afc60a | 26 | } |