han back
/
CLEO_SERVO
SMART CLEO Servo
Revision 0:751077e5fa50, committed 2017-09-28
- Comitter:
- SMART_CLEO
- Date:
- Thu Sep 28 03:26:38 2017 +0000
- Commit message:
- SMART_CLEO
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed-os.lib | Show annotated file Show diff for this revision Revisions of this file |
--- /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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Sep 28 03:26:38 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#ca661f9d28526ca8f874b05432493a489c9671ea