Etienne Stransky
/
Lecture_telecommande
ok
main.cpp@0:00e3c8e6de5b, 2019-02-12 (annotated)
- Committer:
- stersky
- Date:
- Tue Feb 12 14:47:11 2019 +0000
- Revision:
- 0:00e3c8e6de5b
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stersky | 0:00e3c8e6de5b | 1 | #include "mbed.h" |
stersky | 0:00e3c8e6de5b | 2 | |
stersky | 0:00e3c8e6de5b | 3 | Timer chrono1; |
stersky | 0:00e3c8e6de5b | 4 | Timer chrono2; |
stersky | 0:00e3c8e6de5b | 5 | Timer chrono3; |
stersky | 0:00e3c8e6de5b | 6 | Timer chrono4; |
stersky | 0:00e3c8e6de5b | 7 | Timer chrono5; |
stersky | 0:00e3c8e6de5b | 8 | Timer chrono6; |
stersky | 0:00e3c8e6de5b | 9 | |
stersky | 0:00e3c8e6de5b | 10 | InterruptIn ch1(p23); |
stersky | 0:00e3c8e6de5b | 11 | InterruptIn ch2(p24); |
stersky | 0:00e3c8e6de5b | 12 | InterruptIn ch3(p25); |
stersky | 0:00e3c8e6de5b | 13 | InterruptIn ch4(p26); |
stersky | 0:00e3c8e6de5b | 14 | InterruptIn ch5(p29); |
stersky | 0:00e3c8e6de5b | 15 | InterruptIn ch6(p30); |
stersky | 0:00e3c8e6de5b | 16 | |
stersky | 0:00e3c8e6de5b | 17 | DigitalOut del(LED1); |
stersky | 0:00e3c8e6de5b | 18 | |
stersky | 0:00e3c8e6de5b | 19 | Serial PC(USBTX, USBRX); |
stersky | 0:00e3c8e6de5b | 20 | |
stersky | 0:00e3c8e6de5b | 21 | double tps_ch1=0,tps_ch2=0,tps_ch3=0,tps_ch4=0,tps_ch5=0,tps_ch6=0; |
stersky | 0:00e3c8e6de5b | 22 | |
stersky | 0:00e3c8e6de5b | 23 | void initial_PWMIn(void); |
stersky | 0:00e3c8e6de5b | 24 | |
stersky | 0:00e3c8e6de5b | 25 | void ch1_start() { |
stersky | 0:00e3c8e6de5b | 26 | chrono1.start(); |
stersky | 0:00e3c8e6de5b | 27 | } |
stersky | 0:00e3c8e6de5b | 28 | |
stersky | 0:00e3c8e6de5b | 29 | void ch1_stop() |
stersky | 0:00e3c8e6de5b | 30 | { |
stersky | 0:00e3c8e6de5b | 31 | chrono1.stop(); |
stersky | 0:00e3c8e6de5b | 32 | tps_ch1 = chrono1.read_us(); |
stersky | 0:00e3c8e6de5b | 33 | chrono1.reset(); |
stersky | 0:00e3c8e6de5b | 34 | } |
stersky | 0:00e3c8e6de5b | 35 | |
stersky | 0:00e3c8e6de5b | 36 | void ch2_start() { |
stersky | 0:00e3c8e6de5b | 37 | chrono2.start(); |
stersky | 0:00e3c8e6de5b | 38 | } |
stersky | 0:00e3c8e6de5b | 39 | |
stersky | 0:00e3c8e6de5b | 40 | void ch2_stop() |
stersky | 0:00e3c8e6de5b | 41 | { |
stersky | 0:00e3c8e6de5b | 42 | chrono2.stop(); |
stersky | 0:00e3c8e6de5b | 43 | tps_ch2 = chrono2.read_us(); |
stersky | 0:00e3c8e6de5b | 44 | chrono2.reset(); |
stersky | 0:00e3c8e6de5b | 45 | } |
stersky | 0:00e3c8e6de5b | 46 | |
stersky | 0:00e3c8e6de5b | 47 | void ch3_start() { |
stersky | 0:00e3c8e6de5b | 48 | chrono3.start(); |
stersky | 0:00e3c8e6de5b | 49 | } |
stersky | 0:00e3c8e6de5b | 50 | |
stersky | 0:00e3c8e6de5b | 51 | void ch3_stop() |
stersky | 0:00e3c8e6de5b | 52 | { |
stersky | 0:00e3c8e6de5b | 53 | chrono3.stop(); |
stersky | 0:00e3c8e6de5b | 54 | tps_ch3 = chrono3.read_us(); |
stersky | 0:00e3c8e6de5b | 55 | chrono3.reset(); |
stersky | 0:00e3c8e6de5b | 56 | } |
stersky | 0:00e3c8e6de5b | 57 | |
stersky | 0:00e3c8e6de5b | 58 | void ch4_start() { |
stersky | 0:00e3c8e6de5b | 59 | chrono4.start(); |
stersky | 0:00e3c8e6de5b | 60 | } |
stersky | 0:00e3c8e6de5b | 61 | |
stersky | 0:00e3c8e6de5b | 62 | void ch4_stop() |
stersky | 0:00e3c8e6de5b | 63 | { |
stersky | 0:00e3c8e6de5b | 64 | chrono4.stop(); |
stersky | 0:00e3c8e6de5b | 65 | tps_ch4 = chrono4.read_us(); |
stersky | 0:00e3c8e6de5b | 66 | chrono4.reset(); |
stersky | 0:00e3c8e6de5b | 67 | } |
stersky | 0:00e3c8e6de5b | 68 | |
stersky | 0:00e3c8e6de5b | 69 | void ch5_start() { |
stersky | 0:00e3c8e6de5b | 70 | chrono5.start(); |
stersky | 0:00e3c8e6de5b | 71 | } |
stersky | 0:00e3c8e6de5b | 72 | |
stersky | 0:00e3c8e6de5b | 73 | void ch5_stop() |
stersky | 0:00e3c8e6de5b | 74 | { |
stersky | 0:00e3c8e6de5b | 75 | chrono5.stop(); |
stersky | 0:00e3c8e6de5b | 76 | tps_ch5 = chrono5.read_us(); |
stersky | 0:00e3c8e6de5b | 77 | chrono5.reset(); |
stersky | 0:00e3c8e6de5b | 78 | } |
stersky | 0:00e3c8e6de5b | 79 | |
stersky | 0:00e3c8e6de5b | 80 | void ch6_start() { |
stersky | 0:00e3c8e6de5b | 81 | chrono6.start(); |
stersky | 0:00e3c8e6de5b | 82 | } |
stersky | 0:00e3c8e6de5b | 83 | |
stersky | 0:00e3c8e6de5b | 84 | void ch6_stop() |
stersky | 0:00e3c8e6de5b | 85 | { |
stersky | 0:00e3c8e6de5b | 86 | chrono6.stop(); |
stersky | 0:00e3c8e6de5b | 87 | tps_ch6 = chrono6.read_us(); |
stersky | 0:00e3c8e6de5b | 88 | chrono6.reset(); |
stersky | 0:00e3c8e6de5b | 89 | } |
stersky | 0:00e3c8e6de5b | 90 | |
stersky | 0:00e3c8e6de5b | 91 | int main() { |
stersky | 0:00e3c8e6de5b | 92 | |
stersky | 0:00e3c8e6de5b | 93 | PC.baud(460800); |
stersky | 0:00e3c8e6de5b | 94 | initial_PWMIn(); |
stersky | 0:00e3c8e6de5b | 95 | |
stersky | 0:00e3c8e6de5b | 96 | while(true) { |
stersky | 0:00e3c8e6de5b | 97 | PC.printf("Tps haut entree 1:%.lfus\n\r",tps_ch1); |
stersky | 0:00e3c8e6de5b | 98 | PC.printf("Tps haut entree 2:%.lfus\n\r",tps_ch2); |
stersky | 0:00e3c8e6de5b | 99 | PC.printf("Tps haut entree 3:%.lfus\n\r",tps_ch3); |
stersky | 0:00e3c8e6de5b | 100 | PC.printf("Tps haut entree 4:%.lfus\n\r",tps_ch4); |
stersky | 0:00e3c8e6de5b | 101 | PC.printf("Tps haut entree 5:%.lfus\n\r",tps_ch5); |
stersky | 0:00e3c8e6de5b | 102 | PC.printf("Tps haut entree 6:%.lfus\n\r\n\r",tps_ch6); |
stersky | 0:00e3c8e6de5b | 103 | |
stersky | 0:00e3c8e6de5b | 104 | if(tps_ch6 > 1200) del = 1; //Allume la led si ch6 en position haute |
stersky | 0:00e3c8e6de5b | 105 | if(tps_ch6 < 1200) del = 0; //Allume la led si ch6 en position basse |
stersky | 0:00e3c8e6de5b | 106 | wait(0.2); |
stersky | 0:00e3c8e6de5b | 107 | } |
stersky | 0:00e3c8e6de5b | 108 | } |
stersky | 0:00e3c8e6de5b | 109 | |
stersky | 0:00e3c8e6de5b | 110 | void initial_PWMIn(void) |
stersky | 0:00e3c8e6de5b | 111 | { |
stersky | 0:00e3c8e6de5b | 112 | ch1.rise(&ch1_start); |
stersky | 0:00e3c8e6de5b | 113 | ch1.fall(&ch1_stop); |
stersky | 0:00e3c8e6de5b | 114 | |
stersky | 0:00e3c8e6de5b | 115 | ch2.rise(&ch2_start); |
stersky | 0:00e3c8e6de5b | 116 | ch2.fall(&ch2_stop); |
stersky | 0:00e3c8e6de5b | 117 | |
stersky | 0:00e3c8e6de5b | 118 | ch3.rise(&ch3_start); |
stersky | 0:00e3c8e6de5b | 119 | ch3.fall(&ch3_stop); |
stersky | 0:00e3c8e6de5b | 120 | |
stersky | 0:00e3c8e6de5b | 121 | ch4.rise(&ch4_start); |
stersky | 0:00e3c8e6de5b | 122 | ch4.fall(&ch4_stop); |
stersky | 0:00e3c8e6de5b | 123 | |
stersky | 0:00e3c8e6de5b | 124 | ch5.rise(&ch5_start); |
stersky | 0:00e3c8e6de5b | 125 | ch5.fall(&ch5_stop); |
stersky | 0:00e3c8e6de5b | 126 | |
stersky | 0:00e3c8e6de5b | 127 | ch6.rise(&ch6_start); |
stersky | 0:00e3c8e6de5b | 128 | ch6.fall(&ch6_stop); |
stersky | 0:00e3c8e6de5b | 129 | |
stersky | 0:00e3c8e6de5b | 130 | chrono1.reset(); |
stersky | 0:00e3c8e6de5b | 131 | chrono2.reset(); |
stersky | 0:00e3c8e6de5b | 132 | chrono3.reset(); |
stersky | 0:00e3c8e6de5b | 133 | chrono4.reset(); |
stersky | 0:00e3c8e6de5b | 134 | chrono5.reset(); |
stersky | 0:00e3c8e6de5b | 135 | chrono6.reset(); |
stersky | 0:00e3c8e6de5b | 136 | } |