-

Dependencies:   mbed

Vatro.cpp

Committer:
dkakarigi
Date:
2021-02-04
Revision:
0:b85fc380ef49

File content as of revision 0:b85fc380ef49:

#include "mbed.h" 


InterruptIn prekid (USER_BUTTON); 
AnalogIn senzor(PA_0);            
Serial pc(USBTX, USBRX);          
float ispis;                      
Ticker blink;                     
PwmOut zvuk(D2);             
DigitalOut led(D3);         
int restart;                      

 

void flip()
{

    led=!led; 
}

void pwm() 
{
    zvuk.period(0.001031); 
    zvuk=0.5; 
    wait(0.5); 


}
void pwm_off()  
{
    zvuk=0.0;  
    wait(0.5);  


}


void zaustavi()  
{
    blink.detach();  
    led=0;  
    zvuk =0.0; 
    restart=1; 

}

void alarm() 
{
    prekid.rise(&zaustavi);  
    blink.attach(&flip,0.5);  
    pwm();  
    pwm_off(); 


}

int main() 
{

    restart=0; 

    while (1) 

    {
        ispis=senzor;  
        pc.printf("%f \n\r",ispis); 

        if(ispis>=0.6&&restart==0) { 


            alarm(); 

        }

        if(ispis>=0.6) { 
            blink.detach();  
            led=0; 

        }
    }



}