Prog.

Dependencies:   mbed

Alarme1.cpp

Committer:
xCrocoDiffusion
Date:
2016-11-24
Revision:
0:b8f807c6ee61

File content as of revision 0:b8f807c6ee61:

#include "mbed.h"

PwmOut ledalim(p21);
PwmOut led1 (p22);
PwmOut led2 (p23);
PwmOut led3(p24);
PwmOut led4(p25);
DigitalOut buzzer(p26);
AnalogIn J1 (p15);
AnalogIn J2 (p16);
AnalogIn J3( p17);
AnalogIn J4 (p18);
Serial pc(USBTX, USBRX);
Ticker bz;
Ticker by;

bool buz;
int u1;
int u2;
int u3;
int u4;

void attime ()
    {
    if(buz==true) {
        buzzer=!buzzer;
    } else buz=0;
}


int main(void)
    {
    bz.attach_us(&attime,440);

    buzzer=true;


u1=0;
u2=0;
u3=0;
u4=0;

    while(1) {


/////////////////////////////J1///////////////////////////////////////////////////
  
        pc.printf("%f\r\n",J1.read());
        wait(0.1);
        
        if((J1.read()<0.1)&& (u1!=1)) {                       // Court-Circuit (0)
            ledalim.period(1.0f);
            ledalim.write(0.95f);
            led1.period(1.0f);
            led1.write(0.95f);
            buz=true;

            u1=1;
        }
        if((J1.read()<0.3) && (J1.read()>0.2)&&(u1!=2)) {    //  Narmol (4.7k)

            ledalim.period(3.0f);
            ledalim.write(0.5f);
            led1.period(3.0f);
            led1.write(0.5f);
            buz=false;

            u1=2;
        }
        if((J1.read()<0.4)&&(J1.read()>0.3)&& (u1!=3)) {      // Intrusion (9.4k)

            ledalim.period(1);
            ledalim.write(0.1);
            led1.period(1);
            led1.write(0.4);
            buz=true;
            u1=3;
        }
        if((J1.read()>0.5) && (u1!=4)) {                       // Fil Coupé (OL)

            ledalim.period(1);
            ledalim.write(0.1);
            led1.period(1);
            led1.write(0.1);
            buz=true;
            u1=4;
            }
///////////////////////////////J2/////////////////////////////////////////////////
        pc.printf("%f\r\n",J2.read());
        wait(0.1);
        
            if((J2.read()<0.1)&& (u1!=1)) {                       // Court-Circuit (0)
            ledalim.period(1.0f);
            ledalim.write(0.95f);
            led2.period(1.0f);
            led2.write(0.95f);
            buz=true;

            u2=1;
        }
        if((J2.read()<0.3) && (J2.read()>0.2)&&(u1!=2)) {    //  Narmol (4.7k)

            ledalim.period(3.0f);
            ledalim.write(0.5f);
            led2.period(3.0f);
            led2.write(0.5f);
            buz=false;

            u2=2;
        }
        if((J2.read()<0.4)&&(J2.read()>0.3)&& (u1!=3)) {      // Intrusion (9.4k)

            ledalim.period(1);
            ledalim.write(0.1);
            led2.period(1);
            led2.write(0.4);
            buz=true;
            u2=3;
        }
        if((J2.read()>0.5) && (u1!=4)) {                       // Fil Coupé (OL)

            ledalim.period(1);
            ledalim.write(0.1);
            led2.period(1);
            led2.write(0.1);
            buz=true;
            u2=4;
            }
    }
}