dio

Dependencies:   mbed mbed-rtos beep hcsr04

main.cpp

Committer:
CiroSamu
Date:
2019-03-27
Revision:
2:33e2a092cab6
Parent:
1:13556d8b4a34
Child:
3:272fb57c7fcb

File content as of revision 2:33e2a092cab6:

#include "mbed.h"
#include "rtos.h"
#include "hcsr04.h"
#include "beep.h"
/******************************/
//bluetooth
Serial pc(USBTX, USBRX);//tx e rx
/******************************/
//sensori ad ultrasuoni
HCSR04 sensor1(D15, D14);    //istanza oggetti "sensori"
HCSR04 sensor2(D12, D13);
//HCSR04 sensor3(D11, D9);
/******************************/

Thread thread_sensori; // istanzia oggetto thread 

bool occupata[2] = {false};
/******************************/ 
 
//sensore semaforo 1
/******************************/
void sensori(){
        sensor1.start();
        wait_ms(100);
        sensor2.start();         //partono i sensori
        wait_ms(100);                           
        sensor1.get_dist_cm();
        sensor2.get_dist_cm();
        if(sensor1.get_dist_cm() < 5 && occupata[0] ==  false)    //se uno dei sensori capta una distanza minore 10
            occupata[0] = true;
        else
            occupata[0] = false;
            
        if(sensor2.get_dist_cm() < 5 && occupata[1] == false)      //se uno dei sensori capta una distanza minore a 10 e gianello è false
            occupata[1] = true;
        else
            occupata[1] = false;
  }          

int main(){
    pc.printf("prova");
    while(true) {
        
       sensori();
     //  blue.printf("prova");
        //if (mybutton) { 
        for (int i = 0; i < 2; i++)
           pc.printf("%d", occupata[i]);
    }
    
    
    
   
   
}


//void thread sensori() {
    
    
//}