lo slave
Dependencies: HCSR04 beep mbed-rtos mbed
Revision 0:18d34f88c0c1, committed 2017-04-28
- Comitter:
- huntR
- Date:
- Fri Apr 28 19:36:47 2017 +0000
- Commit message:
- slave
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HCSR04.lib Fri Apr 28 19:36:47 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/prabhuvd/code/HCSR04/#71da0dbf4400
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beep.lib Fri Apr 28 19:36:47 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/dreschpe/code/beep/#d8e14429a95f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Apr 28 19:36:47 2017 +0000 @@ -0,0 +1,152 @@ +#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'; +/******************************/ + +//sensore semaforo 1 +/******************************/ +void sensori(void const *args){ + while(true){ + sensor1.start(); + sensor2.start(); + wait_ms(100); + if (sensor1.get_dist_cm() < 10||sensor2.get_dist_cm() < 10){ + wait(5); + sensor1.start(); + + sensor2.start(); + wait_ms(100); + if (sensor1.get_dist_cm()< 10||sensor2.get_dist_cm()< 10){ + blue.putc('1'); + semafori(); + } + if(blue.readable()){ + riceviBlue = blue.getc(); + } + if(riceviBlue == '1') + { + riceviBlue = '0'; + semafori(); + } + } + + + } +} +/******************************/ + +//sensore semaforo 2 +/******************************/ + + +/******************************/ + +int main(){ + //inizializzazione + /******************************/ + rossoP=1; + verdeP=0; + gialloP=0; + gialloC=0; + rossoC=0; + verdeC=1; + blue.baud(38400); + Thread th1(sensori); + /******************************/ + while(1) { + if(blue.readable()){ + riceviBlue = blue.getc(); + } + if(riceviBlue == '1') + { + riceviBlue = '0'; + semafori(); + } + + } +} +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); //per far si che arrivi il segnale al bluetooth del slave mandato dal master +} +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,10); + 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=='A'); + //rosso ai pedoni e verde alle automobili + gialloP=0; + rossoP=1; + rossoC=0; + verdeC=1; + wait_ms(5000); + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Fri Apr 28 19:36:47 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Apr 28 19:36:47 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f \ No newline at end of file