Il master

Dependencies:   HCSR04 beep mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
huntR
Date:
Fri Apr 28 19:35:48 2017 +0000
Commit message:
Master

Changed in this revision

HCSR04.lib Show annotated file Show diff for this revision Revisions of this file
beep.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-rtos.lib 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
diff -r 000000000000 -r 650a24681467 HCSR04.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.lib	Fri Apr 28 19:35:48 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/prabhuvd/code/HCSR04/#71da0dbf4400
diff -r 000000000000 -r 650a24681467 beep.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beep.lib	Fri Apr 28 19:35:48 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/dreschpe/code/beep/#d8e14429a95f
diff -r 000000000000 -r 650a24681467 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Apr 28 19:35:48 2017 +0000
@@ -0,0 +1,155 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "hcsr04.h"
+#include "beep.h"
+/******************************/
+//bluetooth
+Serial blue(D10,D2);//tx e rx
+/******************************/
+//sensori ad ultrasuoni
+HCSR04 sensor1(D15, D14);
+HCSR04 sensor2(D12, D13);
+HCSR04 sensor3(D11, D9);
+/******************************/
+//dichiarazioni led
+//Led per le macchine
+DigitalOut rossoC(PA_0);
+DigitalOut gialloC(D5);
+DigitalOut verdeC(D3);
+/******************************/
+//led per i pedoni
+DigitalOut rossoP(D6);
+DigitalOut gialloP(D7);
+DigitalOut verdeP(D8);
+/******************************/
+//buzzer
+Beep buzzer(D4);
+/******************************/
+/******************************/
+//dichiarazione funzioni
+void giallo();
+void semafori();
+/******************************/
+//variabili
+int i=0;
+char riceviBlue = '0';
+bool gianello= false;
+bool visto = false;
+/******************************/ 
+ 
+//sensore semaforo 1
+/******************************/
+void sensori(){
+    while(!visto && !gianello){
+        sensor1.start();
+        wait_ms(100);
+        sensor2.start();
+        wait_ms(100);
+        if(sensor1.get_dist_cm()<10||sensor2.get_dist_cm()<10){
+            wait(4);
+            sensor1.start();
+            wait_ms(100);
+            sensor2.start();
+            wait_ms(100);
+            if(sensor1.get_dist_cm()<10||sensor2.get_dist_cm()<10&&!gianello){
+               visto = true;
+                blue.putc('A');                
+                wait_ms(100);
+                semafori();
+                visto=false;
+            }
+        }
+    }     
+}
+/******************************/
+//controllo borini 
+/******************************/
+void borini (void const *args){
+    while(true){
+        if(blue.readable()){
+            riceviBlue = blue.getc();
+        }
+        if(riceviBlue == 'B')
+        {
+            gianello=true;
+            riceviBlue='0';
+            semafori();
+            riceviBlue='0';
+            gianello=false;
+            visto=false;
+        }
+    }
+}
+/******************************/
+int main(){
+   //inizializzazione
+   /******************************/
+   rossoP=1;
+   verdeP=0;
+   gialloP=0;
+   gialloC=0;
+   rossoC=0;
+   verdeC=1;
+   blue.baud(38400);
+   /******************************/
+Thread th1(borini);  
+    while(1){
+       if(!gianello){
+            sensori();
+        }
+    }  
+}
+void giallo(){
+    int n;
+    int cont =0;
+    do{
+            n=0;
+            verdeP=0;
+            gialloP=1;       
+           //bippata del buzzer
+           /******************************/
+            for(i=0;i<10;i++){
+                buzzer.beep(1500,50);
+                wait_ms(200);
+                buzzer.nobeep();
+                buzzer.beep(2000,50);
+                wait_ms(200);
+                buzzer.nobeep();                                
+            } 
+            /******************************/
+            sensor3.start();
+            wait_ms(100);
+            if(sensor3.get_dist_cm()<48){
+               cont++;
+               if(cont<=2)
+                blue.putc('L');
+               n=1;               
+            }
+            wait_ms(100);            
+    }while(n==1&&cont<=2);
+    blue.putc('0');      
+    wait_ms(200);
+}
+void semafori(){
+    //giallo per le macchine, rosso per i pedoni       
+            verdeC=0;
+            gialloC=1;
+            rossoC=0;
+            wait(4);
+            //rosso per le macchine, verde per i pedoni
+            buzzer.beep(1200,50);  
+            gialloC=0;
+            rossoC=1;            
+            rossoP=0;
+            verdeP=1;            
+            wait(10);
+            buzzer.nobeep();
+            //giallo per i pedoni e rosso per le macchine   
+            giallo();
+            //rosso ai pedoni e verde alle automobili
+            gialloP=0;
+            rossoP=1; 
+            rossoC=0;
+            verdeC=1;
+            wait_ms(5000);
+}
\ No newline at end of file
diff -r 000000000000 -r 650a24681467 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Apr 28 19:35:48 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
diff -r 000000000000 -r 650a24681467 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Apr 28 19:35:48 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f
\ No newline at end of file