Semafor za pjesake.

Dependencies:   mbed SeeedShieldBot BluetoothSerial buzzer

Fork of SABLJIC_SEMAFORPROJEKT by Stella Sabljic

Files at this revision

API Documentation at this revision

Comitter:
ssabljic
Date:
Thu Dec 02 21:08:00 2021 +0000
Child:
1:232c3adbe1ae
Commit message:
.

Changed in this revision

BluetoothSerial.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	Thu Dec 02 21:08:00 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/SeeedShieldBot.lib	Thu Dec 02 21:08:00 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	Thu Dec 02 21:08:00 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Reniboy/code/buzzer/#8db3a16ff066
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 02 21:08:00 2021 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h" // pozivanje  biblioteke
+#include "buzzer.h"
+
+DigitalOut Crveno(D4); //Postavljanje pinova D4 i D5 kao izlaz za signalizaciju diodama
+DigitalOut Zeleno(D5);
+
+InterruptIn Tipka(USER_BUTTON);//Deklaracija pina USER kao interupt
+Timeout Response; 
+Beep buzzer(D2);
+Ticker ticker;
+
+void sound() {
+    if(Zeleno == 1) {
+        buzzer.beep(400, 1.5);
+    } else if(Crveno == 1) {
+        buzzer.beep(200, 0.5);
+    }
+}
+
+
+bool Tipkalo = false;   //postavljanje početne vrijednosti
+                               
+void Tipkastisnuta() {  //potprogram za detekciju interupta
+    Tipkalo = true;
+}
+
+void semaforcrveno(){ //glavna funkcija koja radi cijelo vrijeme dok se ne stisne gumb
+   Zeleno = 0; 
+   Crveno=1;
+   } 
+
+void pjesackisemafor() { //funkcija koja pali semafor za pjesake nakon detektiranog vanjskog interupta
+
+    if(Tipkalo == true){      
+    Crveno = 0;
+    wait(0.1);
+    Zeleno = 1;
+    wait(3);
+    Response.attach(&semaforcrveno,2.0);  // naredba kojom se pokreče timeout timer   
+    Tipkalo=false; //vraća na pocetnu vrijednost
+    }
+ 
+  }     
+int main() { 
+
+    ticker.attach(&sound, 1.0); 
+    Tipka.fall(&Tipkastisnuta);  // naredba koja detektira interupt promjenom stanja     
+    
+    
+     while(true){    //beskonačna petlja koja pokreče funkciju  sve dok se ne promjeni stanje u podprogramu tipkalo čime se pokreće fnkcija za pjesacki semafor
+        if(!Tipka) {  
+            semaforcrveno(); 
+        } else {
+            pjesackisemafor();
+        }
+      }
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 02 21:08:00 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file