No.9 Robotics / Mbed 2 deprecated Robotics_Servo_control

Dependencies:   mbed

Fork of Robotics_Lab_Servo by LDSC_Robotics

Files at this revision

API Documentation at this revision

Comitter:
dg0704
Date:
Thu Mar 10 06:32:13 2016 +0000
Parent:
3:71a807b38a3e
Child:
5:d495dc55f709
Commit message:
add angle_ref

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Mar 10 06:22:25 2016 +0000
+++ b/main.cpp	Thu Mar 10 06:32:13 2016 +0000
@@ -17,7 +17,9 @@
 DigitalOut led1(LED1);
 DigitalOut led2(D12);
 
+// timer variables
 Ticker timer1;
+int timer1_counter;
 void timer1_interrupt(void);
 
 void init_TIMER(void);
@@ -43,12 +45,20 @@
     init_TIMER();
     while(1)
     {
-        ;
+        if(timer1_counter == 100)
+        {
+            timer1_counter = 0;
+            angle_ref += 15;
+            if (angle_ref == 45)
+                break;               
+        }
     }       
 }
 
 void timer1_interrupt(void)
 {
+    timer1_counter ++;
+    
     angle_read = (adc.read() - 0.45f) / 0.48f * 180.0f;   //0.21 ~ 0.69 respect to -90 ~ +90 degree
     angle_check = angle_read;
     
@@ -70,12 +80,12 @@
 void init_TIMER(void)
 {
     timer1.attach_us(&timer1_interrupt, 10000);//10ms interrupt period (100 Hz)
+    timer1_counter = 0;
 }
        
 void init_IO(void)
 {
-    led1 = 0;
-    led2 = 1;
+    angle_ref = -45;
 }         
    
 void init_PWM(void)