Gets user Input to turn the servo to certain degrees
servo.cpp@3:5b6a55afc60a, 2019-01-13 (annotated)
- Committer:
- hzelayasolano22
- Date:
- Sun Jan 13 22:04:47 2019 +0000
- Revision:
- 3:5b6a55afc60a
- Parent:
- 2:9d9717796ab2
- Child:
- 6:27284b61ae0c
Finished Servo.cpp functions
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 | 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 | 2:9d9717796ab2 | 13 | case 2: servo.pulsdewidth_us(pulsewidth(-90)); break; |
hzelayasolano22 | 2:9d9717796ab2 | 14 | case 3: servo.pulsdewidth_us(pulsewidth(-90)); break; |
hzelayasolano22 | 2:9d9717796ab2 | 15 | case 4: servo.pulsdewidth_us(pulsewidth(-90)); break; |
hzelayasolano22 | 2:9d9717796ab2 | 16 | case 4: servo.pulsdewidth_us(pulsewidth(-90)); break; |
hzelayasolano22 | 2:9d9717796ab2 | 17 | case 5: servo.pulsdewidth_us(pulsewidth(-90)); break; |
hzelayasolano22 | 2:9d9717796ab2 | 18 | case 6: servo.pulsdewidth_us(pulsewidth(-90)); break; |
hzelayasolano22 | 2:9d9717796ab2 | 19 | case 7: servo.pulsdewidth_us(pulsewidth(-90)); break; |
hzelayasolano22 | 2:9d9717796ab2 | 20 | case 8: servo.pulsdewidth_us(pulsewidth(-90)); break; |
hzelayasolano22 | 2:9d9717796ab2 | 21 | case 9: servo.pulsdewidth_us(pulsewidth(-90)); break; |
hzelayasolano22 | 2:9d9717796ab2 | 22 | } |
hzelayasolano22 | 2:9d9717796ab2 | 23 | |
hzelayasolano22 | 3:5b6a55afc60a | 24 | } |
hzelayasolano22 | 3:5b6a55afc60a | 25 | |
hzelayasolano22 | 3:5b6a55afc60a | 26 | int pulsewidth(int a){ |
hzelayasolano22 | 3:5b6a55afc60a | 27 | return 1500 + 10*a; |
hzelayasolano22 | 3:5b6a55afc60a | 28 | } |