Program se sastoji od 6 LED od kojih 5 LED prikazuju stanje na semaforima (automobili i pješaci). U pozadini se nalazi 1 LED koja govori da se program izvršava ispravno. Buzzer signalizira siguran prolaz pješaka. Integrirano tipkalo služi za HW interrupt gdje se prekida izvodenje programa i pali se treptajuće žuto svjetlo. U radu se koristi pločica NUCLEO-F072RB.

Dependencies:   mbed LED SeeedShieldBot BluetoothSerial buzzer

https://os.mbed.com/media/uploads/djukicic/schema.png

Revision:
0:d702e04aa0e3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Feb 21 17:27:16 2021 +0000
@@ -0,0 +1,118 @@
+#include "mbed.h"
+#include "led.h"
+#include "buzzer.h"
+
+Beep buzzer(D7);
+
+LED led1(D4); // crvena auto
+LED led2(D3); // zuta
+LED led3(D2); // zelena auto
+LED led4(D6); // crvena pjesak
+LED led5(D5); // zelena pjesak
+LED led6(D8); // plava
+Ticker blu;
+InterruptIn button(USER_BUTTON);
+Timer automobil;
+Timer pjesak;
+Timer flipper;
+Timer zuta;
+Timer debounce;
+
+float hi=440.00;
+float lo=1;
+int b;
+float freq[28] = {hi,lo,hi,lo,hi,lo,hi,lo,hi,lo,hi,lo,hi,lo,hi,lo,hi,lo,hi,lo,hi,lo,hi,lo,hi,lo,hi,lo};
+float fast_tempo[28] = {4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4};
+float slow_tempo[28] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
+
+//Funkcija hardverskog interrupta
+
+void flip()
+{
+    if(debounce.read_ms()>200) {
+        automobil.stop();
+        pjesak.stop();
+        led1.status(0);
+        led3.status(0);
+        led4.status(0);
+        led5.status(0);
+        int i;
+        for(i=0; i<20; i++) {
+            led2.flip();
+            wait(0.5);
+        }
+    }
+        
+    if(automobil.read()>15 && pjesak.read_ms()>200)
+        {
+        led1.status(1);
+        led2.status(0);
+        led3.status(0);
+        led4.status(0);
+        led5.status(1);   
+        }
+    automobil.start();
+    pjesak.start();
+    debounce.reset();
+}
+
+void blu1()
+    {
+    led6.flip();
+    }
+
+ 
+int main()
+{
+    pjesak.reset();
+    automobil.reset();
+    debounce.start();
+    button.rise(&flip);
+    blu.attach(&blu1,0.1);
+    
+    while(1) {
+
+//Početno stanje LED-ica
+        led1.status(0);
+        led2.status(0);
+        led3.status(1);
+        led4.status(1);
+        led5.status(0);
+
+        buzzer.beep(freq[b], slow_tempo[b]);
+           b++;
+
+        automobil.start();
+        
+//Nakon 13 sekundi upali žuto svjetlo za automobile i gasi se zeleno
+        if (automobil.read() > 13) {
+             led3.flip();
+             led2.flip();
+        }
+           wait(1/slow_tempo[b]);        
+        
+//Nakon 15 sekundi upali crveno za automobile i zeleno za pješake
+        
+        if(automobil.read()>15) {
+            automobil.stop();
+            led1.flip();
+            led2.flip();
+            led4.flip();
+            led5.flip();
+            pjesak.reset();
+            pjesak.start();
+            while(pjesak.read()<8) {
+                if (pjesak.read() > 6)
+                    led2.flip();
+                    for(b=0; b<8; b++) {
+                    buzzer.beep(freq[b], fast_tempo[b]);
+                    wait(1/fast_tempo[b]);
+                    }
+            }
+            automobil.reset();
+            pjesak.stop();
+            b=0;
+        }
+    }
+    return 0;
+}
\ No newline at end of file