da completare (non funzionante)

Dependencies:   mbed Servo mbed-rtos beep hcsr04 TextLCD

Committer:
CiroSamu
Date:
Thu Mar 28 16:03:20 2019 +0000
Revision:
6:0088253be231
Parent:
5:8eb27286a3e3
Child:
7:8ad50e27d002
funziona!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
huntR 0:650a24681467 1 #include "mbed.h"
huntR 0:650a24681467 2 #include "rtos.h"
huntR 0:650a24681467 3 #include "hcsr04.h"
huntR 0:650a24681467 4 #include "beep.h"
CiroSamu 4:48754f3702d7 5 #define trigger1 D15
CiroSamu 4:48754f3702d7 6 #define echo1 D14
CiroSamu 4:48754f3702d7 7 #define trigger2 D12
CiroSamu 4:48754f3702d7 8 #define echo2 D13
huntR 0:650a24681467 9 /******************************/
huntR 0:650a24681467 10 //bluetooth
CiroSamu 2:33e2a092cab6 11 Serial pc(USBTX, USBRX);//tx e rx
huntR 0:650a24681467 12 /******************************/
huntR 0:650a24681467 13 //sensori ad ultrasuoni
CiroSamu 4:48754f3702d7 14 HCSR04 sensor1(trigger1, echo1);
CiroSamu 4:48754f3702d7 15 HCSR04 sensor2(trigger2, echo2);
CiroSamu 2:33e2a092cab6 16 //HCSR04 sensor3(D11, D9);
huntR 0:650a24681467 17 /******************************/
CiroSamu 5:8eb27286a3e3 18 DigitalIn mybutton(USER_BUTTON);
CiroSamu 5:8eb27286a3e3 19 //Thread thread_sensori; // istanzia oggetto thread
altoimperatore 1:13556d8b4a34 20
CiroSamu 5:8eb27286a3e3 21 bool occupata[3] = {false,false,false};
huntR 0:650a24681467 22 /******************************/
CiroSamu 5:8eb27286a3e3 23 void button_thread(void const *args){
CiroSamu 6:0088253be231 24 bool sos= false;
CiroSamu 6:0088253be231 25 //false== libero
CiroSamu 6:0088253be231 26 //true== occupato
CiroSamu 4:48754f3702d7 27 while(1){
CiroSamu 4:48754f3702d7 28 if (mybutton==0){
CiroSamu 6:0088253be231 29
CiroSamu 6:0088253be231 30
CiroSamu 5:8eb27286a3e3 31 int i=0;
CiroSamu 6:0088253be231 32 sos = false;
CiroSamu 5:8eb27286a3e3 33 do{
CiroSamu 5:8eb27286a3e3 34 i++;
CiroSamu 5:8eb27286a3e3 35 if(occupata[i]== false){
CiroSamu 6:0088253be231 36 pc.printf("il parcheggio numero %d e libero\t",i);
CiroSamu 6:0088253be231 37 sos=true;
CiroSamu 6:0088253be231 38 // if(occupata[1]==true && occupata[2]==true) //sos = !sos;
CiroSamu 6:0088253be231 39 }/*else if(sos==false && i==2){
CiroSamu 6:0088253be231 40 pc.printf("tutti i parcheggi sono occupati");
CiroSamu 6:0088253be231 41 break;
CiroSamu 6:0088253be231 42 }//else if(occupata[1]==true && occupata[2]==true) pc.printf("tutti i parcheggi sono occupati");
CiroSamu 6:0088253be231 43 */
CiroSamu 6:0088253be231 44 }while(i<2);
CiroSamu 6:0088253be231 45 // if(occupata[1]==true && occupata[2]==true) pc.printf("tutti i parcheggi sono occupati");
CiroSamu 6:0088253be231 46 if(sos==false) pc.printf("tutti i parcheggi sono occupati");
CiroSamu 6:0088253be231 47
CiroSamu 5:8eb27286a3e3 48 }
CiroSamu 4:48754f3702d7 49
CiroSamu 4:48754f3702d7 50
CiroSamu 4:48754f3702d7 51 }
CiroSamu 5:8eb27286a3e3 52 }
huntR 0:650a24681467 53 //sensore semaforo 1
huntR 0:650a24681467 54 /******************************/
huntR 0:650a24681467 55 void sensori(){
CiroSamu 5:8eb27286a3e3 56 float distanza1;
CiroSamu 5:8eb27286a3e3 57 float distanza2;
huntR 0:650a24681467 58 sensor1.start();
huntR 0:650a24681467 59 wait_ms(100);
CiroSamu 5:8eb27286a3e3 60 sensor2.start(); //partono i sensori
CiroSamu 5:8eb27286a3e3 61 wait_ms(100);
CiroSamu 5:8eb27286a3e3 62 distanza1= sensor1.get_dist_cm() ;
CiroSamu 5:8eb27286a3e3 63 distanza2=sensor2.get_dist_cm();
CiroSamu 6:0088253be231 64 //pc.printf("%.0fcm\r\n%.0fcm\r\n", distanza1,distanza2);
CiroSamu 6:0088253be231 65 if(sensor1.get_dist_cm() < 10.0 && occupata[1] == false) //se uno dei sensori capta una distanza minore 10
altoimperatore 1:13556d8b4a34 66 occupata[1] = true;
altoimperatore 1:13556d8b4a34 67 else
altoimperatore 1:13556d8b4a34 68 occupata[1] = false;
CiroSamu 5:8eb27286a3e3 69
CiroSamu 6:0088253be231 70 if(sensor2.get_dist_cm() < 10.0 && occupata[2] == false) //se uno dei sensori capta una distanza minore a 10 e gianello è false
CiroSamu 5:8eb27286a3e3 71 occupata[2] = true;
CiroSamu 5:8eb27286a3e3 72 else
CiroSamu 5:8eb27286a3e3 73 occupata[2] = false;
CiroSamu 2:33e2a092cab6 74 }
altoimperatore 1:13556d8b4a34 75
huntR 0:650a24681467 76 int main(){
CiroSamu 4:48754f3702d7 77 // pc.printf("prova");
altoimperatore 3:272fb57c7fcb 78 //while(true) {
CiroSamu 4:48754f3702d7 79 //Thread button_th(button_thread);
CiroSamu 5:8eb27286a3e3 80 //int i=0;
CiroSamu 5:8eb27286a3e3 81
CiroSamu 5:8eb27286a3e3 82 Thread button_th(button_thread);
CiroSamu 5:8eb27286a3e3 83 while(1){
CiroSamu 5:8eb27286a3e3 84 sensori();
CiroSamu 5:8eb27286a3e3 85 }
CiroSamu 5:8eb27286a3e3 86 }
CiroSamu 2:33e2a092cab6 87