2016/03/06 servo Winston edit

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
winstonkuo
Date:
Sun Mar 06 13:38:44 2016 +0000
Commit message:
2016/03/06 servo by Winston

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 428e046afc89 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Mar 06 13:38:44 2016 +0000
@@ -0,0 +1,67 @@
+/*LAB_SERVO*/
+#include "mbed.h"
+
+PwmOut servo(A0);
+PwmOut pwm1(D7);
+
+DigitalOut myled(LED1);
+DigitalOut led1(D13);
+DigitalOut led2(D12);
+
+Ticker timer1;
+void timer1_interrupt(void);
+
+void init_TIMER(void);
+void init_IO(void); 
+void init_PWM(void);
+
+float servo_duty = 0.058;   //0.079 +(0.084/180)*angle, -90<angle<90
+bool servo_flag = false;
+
+int main() 
+{
+    init_TIMER();
+    init_IO();
+    init_PWM();
+    
+    while(1)
+    {
+        servo_duty += 0.00007;
+        
+        if(servo_flag == true)
+        {
+            servo.write(servo_duty);
+            servo_flag = false;
+        }
+        
+        if(servo_duty > 0.1)
+            break;
+        
+    }
+
+}
+
+void timer1_interrupt(void)
+{
+    servo_flag = true;
+}
+
+void init_TIMER(void)
+{
+    timer1.attach_us(&timer1_interrupt, 10000);//10ms interrupt period (100 Hz)
+}
+
+void init_IO(void)
+{
+    led1 = 0;
+    led2 = 1;
+}
+
+void init_PWM(void)
+{
+    servo.period_ms(20);        //pwm period 20ms
+    servo.write(servo_duty);
+    //pwm1.period_us(50);
+    //pwm1.write(0.5);
+    //TIM1->CCER |= 0x4;
+}
diff -r 000000000000 -r 428e046afc89 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Mar 06 13:38:44 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb
\ No newline at end of file