han back
/
CLEO_SERVO
SMART CLEO Servo
Diff: main.cpp
- Revision:
- 0:751077e5fa50
diff -r 000000000000 -r 751077e5fa50 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Sep 28 03:26:38 2017 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" + +PinName pin_SERVO = PA_5; + +PwmOut Servo(pin_SERVO); + +void Servo_angle(int16_t angle); + +int main() { + Servo.period_ms(20); + + while(1) { + // 0 ~ 180 + for(int i=0; i<=180; i++) + { + Servo_angle(i); + wait(0.02); + } + // 180 ~ 0 + for(int i=180; i>=0; i--) + { + Servo_angle(i); + wait(0.02); + } + } +} + +void Servo_angle(int16_t angle) +{ + int16_t Angle = 600 + (angle * 10); + Servo.pulsewidth_us(Angle); +}