![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Semafor
main.cpp@1:f929a0c362e7, 23 months ago (annotated)
- Committer:
- zradic
- Date:
- Sun Sep 04 10:06:33 2022 +0000
- Revision:
- 1:f929a0c362e7
- Parent:
- 0:bcbee14067e6
...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zradic | 0:bcbee14067e6 | 1 | #include "mbed.h" |
zradic | 0:bcbee14067e6 | 2 | #include "svijetlasemafora.h" |
zradic | 0:bcbee14067e6 | 3 | |
zradic | 0:bcbee14067e6 | 4 | class Pjesaci { |
zradic | 0:bcbee14067e6 | 5 | public: |
zradic | 0:bcbee14067e6 | 6 | Pjesaci(PinName pin) : led(pin) { |
zradic | 0:bcbee14067e6 | 7 | led = 0; |
zradic | 0:bcbee14067e6 | 8 | } |
zradic | 0:bcbee14067e6 | 9 | void flip() { |
zradic | 1:f929a0c362e7 | 10 | if(brojac==0){ |
zradic | 0:bcbee14067e6 | 11 | led = !led; |
zradic | 0:bcbee14067e6 | 12 | } |
zradic | 0:bcbee14067e6 | 13 | else{ |
zradic | 0:bcbee14067e6 | 14 | led=0; |
zradic | 0:bcbee14067e6 | 15 | } |
zradic | 0:bcbee14067e6 | 16 | } |
zradic | 0:bcbee14067e6 | 17 | private: |
zradic | 0:bcbee14067e6 | 18 | DigitalOut led; |
zradic | 0:bcbee14067e6 | 19 | }; |
zradic | 0:bcbee14067e6 | 20 | |
zradic | 0:bcbee14067e6 | 21 | InterruptIn tipkalo(D7); |
zradic | 0:bcbee14067e6 | 22 | Pjesaci pjesaciLed(LED1); |
zradic | 0:bcbee14067e6 | 23 | Ticker t; |
zradic | 0:bcbee14067e6 | 24 | |
zradic | 0:bcbee14067e6 | 25 | void prekid(void){ |
zradic | 0:bcbee14067e6 | 26 | if(zeleniLed==1){ |
zradic | 0:bcbee14067e6 | 27 | pomocna=1; |
zradic | 0:bcbee14067e6 | 28 | } |
zradic | 0:bcbee14067e6 | 29 | } |
zradic | 0:bcbee14067e6 | 30 | |
zradic | 0:bcbee14067e6 | 31 | int main() |
zradic | 0:bcbee14067e6 | 32 | { |
zradic | 0:bcbee14067e6 | 33 | t.attach(callback(&pjesaciLed, &Pjesaci::flip), 0.5); |
zradic | 0:bcbee14067e6 | 34 | tipkalo.mode(PullUp); |
zradic | 0:bcbee14067e6 | 35 | tipkalo.fall(&prekid); |
zradic | 0:bcbee14067e6 | 36 | |
zradic | 0:bcbee14067e6 | 37 | while (true) { |
zradic | 0:bcbee14067e6 | 38 | if(brojac==0){ |
zradic | 0:bcbee14067e6 | 39 | crveno(10000); |
zradic | 0:bcbee14067e6 | 40 | } |
zradic | 0:bcbee14067e6 | 41 | if(brojac==1){ |
zradic | 0:bcbee14067e6 | 42 | crvenozuto(2000); |
zradic | 0:bcbee14067e6 | 43 | } |
zradic | 0:bcbee14067e6 | 44 | if(brojac==2){ |
zradic | 0:bcbee14067e6 | 45 | zeleno(7000); |
zradic | 0:bcbee14067e6 | 46 | } |
zradic | 0:bcbee14067e6 | 47 | if(brojac==3){ |
zradic | 0:bcbee14067e6 | 48 | zuto(3000); |
zradic | 0:bcbee14067e6 | 49 | } |
zradic | 0:bcbee14067e6 | 50 | thread_sleep_for(10); |
zradic | 0:bcbee14067e6 | 51 | } |
zradic | 0:bcbee14067e6 | 52 | } |