slave funzionante

Dependencies:   HCSR04 beep mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
huntR
Date:
Fri Apr 28 19:45:21 2017 +0000
Commit message:
slave funzionante

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 ffca8ab7f43f HCSR04.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.lib	Fri Apr 28 19:45:21 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/prabhuvd/code/HCSR04/#71da0dbf4400
diff -r 000000000000 -r ffca8ab7f43f beep.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beep.lib	Fri Apr 28 19:45:21 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/dreschpe/code/beep/#d8e14429a95f
diff -r 000000000000 -r ffca8ab7f43f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Apr 28 19:45:21 2017 +0000
@@ -0,0 +1,160 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "hcsr04.h"
+#include "beep.h"
+//dichiarazioni let e sensori
+//sensori ad ultrasuoni
+/******************************/
+//bluetooth
+Serial blue(D10,D2);
+/******************************/
+HCSR04 sensor1(D15, D14);
+HCSR04 sensor2(D12, D13);
+//HCSR04 sensor3(D11, D9);
+/******************************/
+//Led per le macchine
+DigitalOut rossoC(PA_0);//led
+DigitalOut gialloC(D5);
+DigitalOut verdeC(D3);
+/******************************/
+//buzzer
+Beep buzzer(D4);
+/******************************/
+//led per i pedoni
+DigitalOut rossoP(D6);
+DigitalOut gialloP(D7);
+DigitalOut verdeP(D8);
+/******************************/
+/******************************/
+//dichiarazione funzioni
+void giallo();
+void semafori();
+/******************************/
+int i=0;
+char riceviBlue = '0';
+bool gianello=false;
+bool visto = false;
+int cont =0;
+/******************************/
+
+//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('B');                
+                wait_ms(100);
+                semafori();
+                visto=false;
+            }
+        }
+    }     
+}
+/******************************/
+
+//controllo borini
+/******************************/
+void iezzo (void const *args){
+    while(true){
+        if(blue.readable()){
+            riceviBlue = blue.getc();
+        }
+        if(riceviBlue == 'A')
+        {
+            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(iezzo);
+   /******************************/
+    while(1){
+        if(!gianello){
+            wait_ms(500);
+            sensori();
+        }
+    }  
+}
+void giallo(){
+    //giallo per i pedoni e rosso per le macchine  
+    
+    int n;
+    do{
+            n=0;
+            verdeP=0;
+            gialloP=1;       
+           //bippata del buzzer
+           /******************************/
+            for(i=0;i<10;i++){
+                buzzer.beep(500,0.1);
+                gialloP=1;
+                wait_ms(200);
+                buzzer.nobeep();
+                buzzer.beep(1000,0.1);
+                gialloP=1;
+                gialloP=1;
+                wait_ms(200);
+                buzzer.nobeep();                                
+                gialloP=1;
+            } 
+            /******************************/                       
+            wait_ms(100);                 
+    }while(n==1);
+    wait_ms(100);   
+}
+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
+            do{   
+                giallo();
+                riceviBlue=blue.getc();
+                
+            }while(riceviBlue=='L');
+            cont = 0;
+            //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 ffca8ab7f43f mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Apr 28 19:45:21 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
diff -r 000000000000 -r ffca8ab7f43f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Apr 28 19:45:21 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f
\ No newline at end of file