![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Semafor
Diff: main.cpp
- Revision:
- 0:bcbee14067e6
- Child:
- 1:f929a0c362e7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Sep 04 09:27:49 2022 +0000 @@ -0,0 +1,52 @@ +#include "mbed.h" +#include "svijetlasemafora.h" + +class Pjesaci { +public: + Pjesaci(PinName pin) : led(pin) { + led = 0; + } + void flip() { + if(crveniLed==1){ + led = !led; + } + else{ + led=0; + } + } +private: + DigitalOut led; +}; + +InterruptIn tipkalo(D7); +Pjesaci pjesaciLed(LED1); +Ticker t; + +void prekid(void){ + if(zeleniLed==1){ + pomocna=1; + } +} + +int main() +{ + t.attach(callback(&pjesaciLed, &Pjesaci::flip), 0.5); + tipkalo.mode(PullUp); + tipkalo.fall(&prekid); + + while (true) { + if(brojac==0){ + crveno(10000); + } + if(brojac==1){ + crvenozuto(2000); + } + if(brojac==2){ + zeleno(7000); + } + if(brojac==3){ + zuto(3000); + } + thread_sleep_for(10); + } +}