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

Files at this revision

API Documentation at this revision

Comitter:
djukicic
Date:
Sun Feb 21 17:27:16 2021 +0000
Child:
1:add66fe63d7c
Commit message:
/

Changed in this revision

BluetoothSerial.lib Show annotated file Show diff for this revision Revisions of this file
LED.lib Show annotated file Show diff for this revision Revisions of this file
SeeedShieldBot.lib Show annotated file Show diff for this revision Revisions of this file
buzzer.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BluetoothSerial.lib	Sun Feb 21 17:27:16 2021 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/yihui/code/BluetoothSerial/#f56002898ee8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LED.lib	Sun Feb 21 17:27:16 2021 +0000
@@ -0,0 +1,1 @@
+LED#827af283d6f0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SeeedShieldBot.lib	Sun Feb 21 17:27:16 2021 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/components/code/SeeedShieldBot/#9fd1722259a1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/buzzer.lib	Sun Feb 21 17:27:16 2021 +0000
@@ -0,0 +1,1 @@
+buzzer#f563386d7c59
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Feb 21 17:27:16 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file