han back
/
CLEO_SERVO
SMART CLEO Servo
main.cpp@0:751077e5fa50, 2017-09-28 (annotated)
- Committer:
- SMART_CLEO
- Date:
- Thu Sep 28 03:26:38 2017 +0000
- Revision:
- 0:751077e5fa50
SMART_CLEO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SMART_CLEO | 0:751077e5fa50 | 1 | #include "mbed.h" |
SMART_CLEO | 0:751077e5fa50 | 2 | |
SMART_CLEO | 0:751077e5fa50 | 3 | PinName pin_SERVO = PA_5; |
SMART_CLEO | 0:751077e5fa50 | 4 | |
SMART_CLEO | 0:751077e5fa50 | 5 | PwmOut Servo(pin_SERVO); |
SMART_CLEO | 0:751077e5fa50 | 6 | |
SMART_CLEO | 0:751077e5fa50 | 7 | void Servo_angle(int16_t angle); |
SMART_CLEO | 0:751077e5fa50 | 8 | |
SMART_CLEO | 0:751077e5fa50 | 9 | int main() { |
SMART_CLEO | 0:751077e5fa50 | 10 | Servo.period_ms(20); |
SMART_CLEO | 0:751077e5fa50 | 11 | |
SMART_CLEO | 0:751077e5fa50 | 12 | while(1) { |
SMART_CLEO | 0:751077e5fa50 | 13 | // 0 ~ 180 |
SMART_CLEO | 0:751077e5fa50 | 14 | for(int i=0; i<=180; i++) |
SMART_CLEO | 0:751077e5fa50 | 15 | { |
SMART_CLEO | 0:751077e5fa50 | 16 | Servo_angle(i); |
SMART_CLEO | 0:751077e5fa50 | 17 | wait(0.02); |
SMART_CLEO | 0:751077e5fa50 | 18 | } |
SMART_CLEO | 0:751077e5fa50 | 19 | // 180 ~ 0 |
SMART_CLEO | 0:751077e5fa50 | 20 | for(int i=180; i>=0; i--) |
SMART_CLEO | 0:751077e5fa50 | 21 | { |
SMART_CLEO | 0:751077e5fa50 | 22 | Servo_angle(i); |
SMART_CLEO | 0:751077e5fa50 | 23 | wait(0.02); |
SMART_CLEO | 0:751077e5fa50 | 24 | } |
SMART_CLEO | 0:751077e5fa50 | 25 | } |
SMART_CLEO | 0:751077e5fa50 | 26 | } |
SMART_CLEO | 0:751077e5fa50 | 27 | |
SMART_CLEO | 0:751077e5fa50 | 28 | void Servo_angle(int16_t angle) |
SMART_CLEO | 0:751077e5fa50 | 29 | { |
SMART_CLEO | 0:751077e5fa50 | 30 | int16_t Angle = 600 + (angle * 10); |
SMART_CLEO | 0:751077e5fa50 | 31 | Servo.pulsewidth_us(Angle); |
SMART_CLEO | 0:751077e5fa50 | 32 | } |