Prog.
Dependencies: mbed
Alarme1.cpp@0:b8f807c6ee61, 2016-11-24 (annotated)
- Committer:
- xCrocoDiffusion
- Date:
- Thu Nov 24 07:41:42 2016 +0000
- Revision:
- 0:b8f807c6ee61
Programme test alarme syntoni
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xCrocoDiffusion | 0:b8f807c6ee61 | 1 | #include "mbed.h" |
xCrocoDiffusion | 0:b8f807c6ee61 | 2 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 3 | PwmOut ledalim(p21); |
xCrocoDiffusion | 0:b8f807c6ee61 | 4 | PwmOut led1 (p22); |
xCrocoDiffusion | 0:b8f807c6ee61 | 5 | PwmOut led2 (p23); |
xCrocoDiffusion | 0:b8f807c6ee61 | 6 | PwmOut led3(p24); |
xCrocoDiffusion | 0:b8f807c6ee61 | 7 | PwmOut led4(p25); |
xCrocoDiffusion | 0:b8f807c6ee61 | 8 | DigitalOut buzzer(p26); |
xCrocoDiffusion | 0:b8f807c6ee61 | 9 | AnalogIn J1 (p15); |
xCrocoDiffusion | 0:b8f807c6ee61 | 10 | AnalogIn J2 (p16); |
xCrocoDiffusion | 0:b8f807c6ee61 | 11 | AnalogIn J3( p17); |
xCrocoDiffusion | 0:b8f807c6ee61 | 12 | AnalogIn J4 (p18); |
xCrocoDiffusion | 0:b8f807c6ee61 | 13 | Serial pc(USBTX, USBRX); |
xCrocoDiffusion | 0:b8f807c6ee61 | 14 | Ticker bz; |
xCrocoDiffusion | 0:b8f807c6ee61 | 15 | Ticker by; |
xCrocoDiffusion | 0:b8f807c6ee61 | 16 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 17 | bool buz; |
xCrocoDiffusion | 0:b8f807c6ee61 | 18 | int u1; |
xCrocoDiffusion | 0:b8f807c6ee61 | 19 | int u2; |
xCrocoDiffusion | 0:b8f807c6ee61 | 20 | int u3; |
xCrocoDiffusion | 0:b8f807c6ee61 | 21 | int u4; |
xCrocoDiffusion | 0:b8f807c6ee61 | 22 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 23 | void attime () |
xCrocoDiffusion | 0:b8f807c6ee61 | 24 | { |
xCrocoDiffusion | 0:b8f807c6ee61 | 25 | if(buz==true) { |
xCrocoDiffusion | 0:b8f807c6ee61 | 26 | buzzer=!buzzer; |
xCrocoDiffusion | 0:b8f807c6ee61 | 27 | } else buz=0; |
xCrocoDiffusion | 0:b8f807c6ee61 | 28 | } |
xCrocoDiffusion | 0:b8f807c6ee61 | 29 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 30 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 31 | int main(void) |
xCrocoDiffusion | 0:b8f807c6ee61 | 32 | { |
xCrocoDiffusion | 0:b8f807c6ee61 | 33 | bz.attach_us(&attime,440); |
xCrocoDiffusion | 0:b8f807c6ee61 | 34 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 35 | buzzer=true; |
xCrocoDiffusion | 0:b8f807c6ee61 | 36 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 37 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 38 | u1=0; |
xCrocoDiffusion | 0:b8f807c6ee61 | 39 | u2=0; |
xCrocoDiffusion | 0:b8f807c6ee61 | 40 | u3=0; |
xCrocoDiffusion | 0:b8f807c6ee61 | 41 | u4=0; |
xCrocoDiffusion | 0:b8f807c6ee61 | 42 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 43 | while(1) { |
xCrocoDiffusion | 0:b8f807c6ee61 | 44 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 45 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 46 | /////////////////////////////J1/////////////////////////////////////////////////// |
xCrocoDiffusion | 0:b8f807c6ee61 | 47 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 48 | pc.printf("%f\r\n",J1.read()); |
xCrocoDiffusion | 0:b8f807c6ee61 | 49 | wait(0.1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 50 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 51 | if((J1.read()<0.1)&& (u1!=1)) { // Court-Circuit (0) |
xCrocoDiffusion | 0:b8f807c6ee61 | 52 | ledalim.period(1.0f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 53 | ledalim.write(0.95f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 54 | led1.period(1.0f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 55 | led1.write(0.95f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 56 | buz=true; |
xCrocoDiffusion | 0:b8f807c6ee61 | 57 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 58 | u1=1; |
xCrocoDiffusion | 0:b8f807c6ee61 | 59 | } |
xCrocoDiffusion | 0:b8f807c6ee61 | 60 | if((J1.read()<0.3) && (J1.read()>0.2)&&(u1!=2)) { // Narmol (4.7k) |
xCrocoDiffusion | 0:b8f807c6ee61 | 61 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 62 | ledalim.period(3.0f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 63 | ledalim.write(0.5f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 64 | led1.period(3.0f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 65 | led1.write(0.5f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 66 | buz=false; |
xCrocoDiffusion | 0:b8f807c6ee61 | 67 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 68 | u1=2; |
xCrocoDiffusion | 0:b8f807c6ee61 | 69 | } |
xCrocoDiffusion | 0:b8f807c6ee61 | 70 | if((J1.read()<0.4)&&(J1.read()>0.3)&& (u1!=3)) { // Intrusion (9.4k) |
xCrocoDiffusion | 0:b8f807c6ee61 | 71 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 72 | ledalim.period(1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 73 | ledalim.write(0.1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 74 | led1.period(1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 75 | led1.write(0.4); |
xCrocoDiffusion | 0:b8f807c6ee61 | 76 | buz=true; |
xCrocoDiffusion | 0:b8f807c6ee61 | 77 | u1=3; |
xCrocoDiffusion | 0:b8f807c6ee61 | 78 | } |
xCrocoDiffusion | 0:b8f807c6ee61 | 79 | if((J1.read()>0.5) && (u1!=4)) { // Fil Coupé (OL) |
xCrocoDiffusion | 0:b8f807c6ee61 | 80 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 81 | ledalim.period(1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 82 | ledalim.write(0.1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 83 | led1.period(1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 84 | led1.write(0.1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 85 | buz=true; |
xCrocoDiffusion | 0:b8f807c6ee61 | 86 | u1=4; |
xCrocoDiffusion | 0:b8f807c6ee61 | 87 | } |
xCrocoDiffusion | 0:b8f807c6ee61 | 88 | ///////////////////////////////J2///////////////////////////////////////////////// |
xCrocoDiffusion | 0:b8f807c6ee61 | 89 | pc.printf("%f\r\n",J2.read()); |
xCrocoDiffusion | 0:b8f807c6ee61 | 90 | wait(0.1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 91 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 92 | if((J2.read()<0.1)&& (u1!=1)) { // Court-Circuit (0) |
xCrocoDiffusion | 0:b8f807c6ee61 | 93 | ledalim.period(1.0f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 94 | ledalim.write(0.95f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 95 | led2.period(1.0f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 96 | led2.write(0.95f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 97 | buz=true; |
xCrocoDiffusion | 0:b8f807c6ee61 | 98 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 99 | u2=1; |
xCrocoDiffusion | 0:b8f807c6ee61 | 100 | } |
xCrocoDiffusion | 0:b8f807c6ee61 | 101 | if((J2.read()<0.3) && (J2.read()>0.2)&&(u1!=2)) { // Narmol (4.7k) |
xCrocoDiffusion | 0:b8f807c6ee61 | 102 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 103 | ledalim.period(3.0f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 104 | ledalim.write(0.5f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 105 | led2.period(3.0f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 106 | led2.write(0.5f); |
xCrocoDiffusion | 0:b8f807c6ee61 | 107 | buz=false; |
xCrocoDiffusion | 0:b8f807c6ee61 | 108 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 109 | u2=2; |
xCrocoDiffusion | 0:b8f807c6ee61 | 110 | } |
xCrocoDiffusion | 0:b8f807c6ee61 | 111 | if((J2.read()<0.4)&&(J2.read()>0.3)&& (u1!=3)) { // Intrusion (9.4k) |
xCrocoDiffusion | 0:b8f807c6ee61 | 112 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 113 | ledalim.period(1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 114 | ledalim.write(0.1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 115 | led2.period(1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 116 | led2.write(0.4); |
xCrocoDiffusion | 0:b8f807c6ee61 | 117 | buz=true; |
xCrocoDiffusion | 0:b8f807c6ee61 | 118 | u2=3; |
xCrocoDiffusion | 0:b8f807c6ee61 | 119 | } |
xCrocoDiffusion | 0:b8f807c6ee61 | 120 | if((J2.read()>0.5) && (u1!=4)) { // Fil Coupé (OL) |
xCrocoDiffusion | 0:b8f807c6ee61 | 121 | |
xCrocoDiffusion | 0:b8f807c6ee61 | 122 | ledalim.period(1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 123 | ledalim.write(0.1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 124 | led2.period(1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 125 | led2.write(0.1); |
xCrocoDiffusion | 0:b8f807c6ee61 | 126 | buz=true; |
xCrocoDiffusion | 0:b8f807c6ee61 | 127 | u2=4; |
xCrocoDiffusion | 0:b8f807c6ee61 | 128 | } |
xCrocoDiffusion | 0:b8f807c6ee61 | 129 | } |
xCrocoDiffusion | 0:b8f807c6ee61 | 130 | } |