-
Dependencies: mbed
Diff: Vatro.cpp
- Revision:
- 0:b85fc380ef49
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Vatro.cpp Thu Feb 04 21:16:43 2021 +0000 @@ -0,0 +1,84 @@ +#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; + + } + } + + + +}