![](/media/cache/profiles/0996dd16b0020a17a26b94f4675fd3da.50x50_q85.png)
RC_reciever
Dependencies: mbed RC_reciever
main.cpp@2:8c428bae83a8, 2015-12-21 (annotated)
- Committer:
- higedura
- Date:
- Mon Dec 21 02:31:52 2015 +0000
- Revision:
- 2:8c428bae83a8
- Parent:
- 1:16b2e229b739
RC receiver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
higedura | 1:16b2e229b739 | 1 | #include "mbed.h" |
higedura | 1:16b2e229b739 | 2 | |
higedura | 1:16b2e229b739 | 3 | #define chan 6 // the numbers of channels |
higedura | 1:16b2e229b739 | 4 | |
higedura | 1:16b2e229b739 | 5 | Serial pc(USBTX, USBRX); |
higedura | 1:16b2e229b739 | 6 | DigitalOut led1(LED1); |
higedura | 1:16b2e229b739 | 7 | DigitalOut led2(LED2); |
higedura | 1:16b2e229b739 | 8 | DigitalOut led3(LED3); |
higedura | 1:16b2e229b739 | 9 | DigitalOut led4(LED4); |
higedura | 1:16b2e229b739 | 10 | |
higedura | 2:8c428bae83a8 | 11 | InterruptIn ch1(p17); // yaw |
higedura | 2:8c428bae83a8 | 12 | InterruptIn ch2(p18); // pitch |
higedura | 2:8c428bae83a8 | 13 | InterruptIn ch3(p19); // throttle |
higedura | 2:8c428bae83a8 | 14 | InterruptIn ch4(p20); // roll |
higedura | 1:16b2e229b739 | 15 | //InterruptIn ch5(p17); // aux1 |
higedura | 1:16b2e229b739 | 16 | //InterruptIn ch6(p18); // aux2 |
higedura | 2:8c428bae83a8 | 17 | |
higedura | 1:16b2e229b739 | 18 | void thro_up(); void roll_up(); void pitch_up(); void yaw_up(); void aux1_up(); void aux2_up(); |
higedura | 1:16b2e229b739 | 19 | void thro_down(); void roll_down(); void pitch_down(); void yaw_down(); void aux1_down(); void aux2_down(); |
higedura | 1:16b2e229b739 | 20 | |
higedura | 1:16b2e229b739 | 21 | Timer t_thro; Timer t_roll; Timer t_pitch; Timer t_yaw; Timer t_aux1; Timer t_aux2; |
higedura | 1:16b2e229b739 | 22 | |
higedura | 1:16b2e229b739 | 23 | // thro roll pitch yaw aux1 aux2 |
higedura | 1:16b2e229b739 | 24 | int pwm_pulse[chan] = {0, 0, 0, 0, 0, 0}; |
higedura | 1:16b2e229b739 | 25 | |
higedura | 1:16b2e229b739 | 26 | int main() { |
higedura | 1:16b2e229b739 | 27 | |
higedura | 1:16b2e229b739 | 28 | pc.baud(921600); |
higedura | 2:8c428bae83a8 | 29 | pc.printf("hello!\r\n\r\n"); |
higedura | 2:8c428bae83a8 | 30 | led1 =1; |
higedura | 2:8c428bae83a8 | 31 | wait(1); |
higedura | 2:8c428bae83a8 | 32 | led1 =0; |
higedura | 2:8c428bae83a8 | 33 | wait(1); |
higedura | 2:8c428bae83a8 | 34 | led1=1; |
higedura | 1:16b2e229b739 | 35 | // Reciever function |
higedura | 1:16b2e229b739 | 36 | ch1.rise(&yaw_up); ch1.fall(&yaw_down); |
higedura | 1:16b2e229b739 | 37 | ch2.rise(&pitch_up); ch2.fall(&pitch_down); |
higedura | 1:16b2e229b739 | 38 | ch3.rise(&thro_up); ch3.fall(&thro_down); |
higedura | 1:16b2e229b739 | 39 | ch4.rise(&roll_up); ch4.fall(&roll_down); |
higedura | 1:16b2e229b739 | 40 | //ch5.rise(&aux1_up); ch5.fall(&aux1_down); |
higedura | 1:16b2e229b739 | 41 | //ch6.rise(&aux2_up); ch6.fall(&aux2_down); |
higedura | 1:16b2e229b739 | 42 | |
higedura | 1:16b2e229b739 | 43 | while(1) { |
higedura | 1:16b2e229b739 | 44 | |
higedura | 2:8c428bae83a8 | 45 | for( int i=0;i<4;i++ ){ pc.printf("%d ", pwm_pulse[i]); } |
higedura | 2:8c428bae83a8 | 46 | pc.printf("\r\n\r\n"); |
higedura | 1:16b2e229b739 | 47 | |
higedura | 2:8c428bae83a8 | 48 | //ch1.enable_irq(); |
higedura | 2:8c428bae83a8 | 49 | //ch2.enable_irq(); |
higedura | 2:8c428bae83a8 | 50 | //ch3.enable_irq(); |
higedura | 2:8c428bae83a8 | 51 | //ch4.enable_irq(); |
higedura | 1:16b2e229b739 | 52 | |
higedura | 1:16b2e229b739 | 53 | wait(.1); |
higedura | 2:8c428bae83a8 | 54 | |
higedura | 2:8c428bae83a8 | 55 | //ch1.disable_irq(); |
higedura | 2:8c428bae83a8 | 56 | //ch2.disable_irq(); |
higedura | 2:8c428bae83a8 | 57 | //ch3.disable_irq(); |
higedura | 2:8c428bae83a8 | 58 | //ch4.disable_irq(); |
higedura | 1:16b2e229b739 | 59 | |
higedura | 1:16b2e229b739 | 60 | } |
higedura | 1:16b2e229b739 | 61 | } |
higedura | 1:16b2e229b739 | 62 | |
higedura | 1:16b2e229b739 | 63 | void thro_up(){ t_thro.start(); } |
higedura | 1:16b2e229b739 | 64 | void roll_up(){ t_roll.start(); } |
higedura | 1:16b2e229b739 | 65 | void pitch_up(){ t_pitch.start(); } |
higedura | 1:16b2e229b739 | 66 | void yaw_up(){ t_yaw.start(); } |
higedura | 1:16b2e229b739 | 67 | //void aux1_up(){ t_aux1.start(); } |
higedura | 1:16b2e229b739 | 68 | //void aux2_up(){ t_aux2.start(); } |
higedura | 1:16b2e229b739 | 69 | |
higedura | 1:16b2e229b739 | 70 | void thro_down(){ |
higedura | 1:16b2e229b739 | 71 | t_thro.stop(); |
higedura | 1:16b2e229b739 | 72 | pwm_pulse[0] = (int)(t_thro.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 73 | t_thro.reset(); |
higedura | 1:16b2e229b739 | 74 | } |
higedura | 1:16b2e229b739 | 75 | |
higedura | 1:16b2e229b739 | 76 | void roll_down(){ |
higedura | 1:16b2e229b739 | 77 | t_roll.stop(); |
higedura | 1:16b2e229b739 | 78 | pwm_pulse[1] = (int)(t_roll.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 79 | t_roll.reset(); |
higedura | 1:16b2e229b739 | 80 | } |
higedura | 1:16b2e229b739 | 81 | |
higedura | 1:16b2e229b739 | 82 | void pitch_down(){ |
higedura | 1:16b2e229b739 | 83 | t_pitch.stop(); |
higedura | 1:16b2e229b739 | 84 | pwm_pulse[2] = (int)(t_pitch.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 85 | t_pitch.reset(); |
higedura | 1:16b2e229b739 | 86 | } |
higedura | 1:16b2e229b739 | 87 | |
higedura | 1:16b2e229b739 | 88 | void yaw_down(){ |
higedura | 1:16b2e229b739 | 89 | t_yaw.stop(); |
higedura | 1:16b2e229b739 | 90 | pwm_pulse[3] = (int)(t_yaw.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 91 | t_yaw.reset(); |
higedura | 1:16b2e229b739 | 92 | } |
higedura | 1:16b2e229b739 | 93 | /* |
higedura | 1:16b2e229b739 | 94 | void aux1_down(){ |
higedura | 1:16b2e229b739 | 95 | t_aux1.stop(); |
higedura | 1:16b2e229b739 | 96 | pwm_pulse[4] = (int)(t_aux1.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 97 | t_aux1.reset(); |
higedura | 1:16b2e229b739 | 98 | } |
higedura | 1:16b2e229b739 | 99 | |
higedura | 1:16b2e229b739 | 100 | void aux2_down(){ |
higedura | 1:16b2e229b739 | 101 | t_aux2.stop(); |
higedura | 1:16b2e229b739 | 102 | pwm_pulse[5] = (int)(t_aux2.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 103 | t_aux2.reset(); |
higedura | 1:16b2e229b739 | 104 | } |
higedura | 1:16b2e229b739 | 105 | */ |