RC_reciever

Dependencies:   mbed RC_reciever

Dependents:   RC_reciever

Revision:
0:18d415e9d13b
Child:
1:16b2e229b739
diff -r 000000000000 -r 18d415e9d13b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Dec 04 14:40:04 2012 +0000
@@ -0,0 +1,105 @@
+#include "mbed.h"
+#include "TextLCD.h"
+ 
+#define chan    6         // the numbers of channels
+
+Serial pc(USBTX, USBRX);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+/*
+InterruptIn ch1(p26);       // yaw
+InterruptIn ch2(p25);       // pitch
+InterruptIn ch3(p24);       // throttle
+InterruptIn ch4(p23);       // roll
+InterruptIn ch5(p22);       // aux1
+InterruptIn ch6(p21);       // aux2
+*/
+InterruptIn ch1(p5);       // yaw
+InterruptIn ch2(p6);       // pitch
+InterruptIn ch3(p7);       // throttle
+InterruptIn ch4(p8);       // roll
+InterruptIn ch5(p9);       // aux1
+InterruptIn ch6(p10);       // aux2
+TextLCD lcd(p24, p26, p27, p28, p29, p30);
+
+void thro_up();     void roll_up();     void pitch_up();    void yaw_up();      void aux1_up();      void aux2_up();
+void thro_down();   void roll_down();   void pitch_down();  void yaw_down();    void aux1_down();    void aux2_down();
+
+Timer t_thro;       Timer t_roll;       Timer t_pitch;      Timer t_yaw;      Timer t_aux1;      Timer t_aux2;
+
+// thro roll pitch yaw aux1 aux2
+int pwm_pulse[chan]      =   {0, 0, 0, 0, 0, 0};
+
+int main() {
+    
+    pc.baud(921600);
+
+    lcd.locate(0, 0);   lcd.printf("StarBoard Orange");
+    lcd.locate(0, 1);   lcd.printf("mbed NXP LPC1768");
+    wait(1);            lcd.cls();
+    
+    // Reciever function
+    ch1.rise(&yaw_up);      ch1.fall(&yaw_down);
+    ch2.rise(&pitch_up);    ch2.fall(&pitch_down);
+    ch3.rise(&thro_up);     ch3.fall(&thro_down);
+    ch4.rise(&roll_up);     ch4.fall(&roll_down);
+    ch5.rise(&aux1_up);     ch5.fall(&aux1_down);
+    ch6.rise(&aux2_up);     ch6.fall(&aux2_down);
+
+    while(1) {
+        
+        //for(int i=0;i<chan;i++){    pc.printf("%f ",pwm_pulse[i]);  }
+        //pc.printf("\r\n");
+        lcd.locate(0, 0);
+        lcd.printf("%4d %4d %4d",pwm_pulse[0], pwm_pulse[1], pwm_pulse[2]);
+        lcd.locate(0, 1);
+        lcd.printf("%4d %4d %4d",pwm_pulse[3], pwm_pulse[4], pwm_pulse[5]);
+        lcd.cls();
+                
+    }
+}
+
+void thro_up(){     t_thro.start();   }
+void roll_up(){     t_roll.start();   }
+void pitch_up(){    t_pitch.start();  }
+void yaw_up(){      t_yaw.start();    }
+void aux1_up(){     t_aux1.start();   }
+void aux2_up(){     t_aux2.start();   }
+
+void thro_down(){
+    t_thro.stop();
+    pwm_pulse[0]    =   (int)(t_thro.read()*1000000-1000);
+    t_thro.reset();
+}
+
+void roll_down(){
+    t_roll.stop();
+    pwm_pulse[1]    =   (int)(t_roll.read()*1000000-1000);
+    t_roll.reset();
+}
+
+void pitch_down(){
+    t_pitch.stop();
+    pwm_pulse[2]    =   (int)(t_pitch.read()*1000000-1000);
+    t_pitch.reset();
+}
+
+void yaw_down(){
+    t_yaw.stop();
+    pwm_pulse[3]    =   (int)(t_yaw.read()*1000000-1000);
+    t_yaw.reset();
+}
+
+void aux1_down(){
+    t_aux1.stop();
+    pwm_pulse[4]    =   (int)(t_aux1.read()*1000000-1000);
+    t_aux1.reset();
+}
+
+void aux2_down(){
+    t_aux2.stop();
+    pwm_pulse[5]    =   (int)(t_aux2.read()*1000000-1000);
+    t_aux2.reset();
+}