UNFINISHED

Dependencies:   HCSR04 SRF05 mbed

Distance.h

Committer:
Charlie_He
Date:
2018-06-08
Revision:
0:4ca3e247b86a
Child:
1:60c79e942c98

File content as of revision 0:4ca3e247b86a:

#include "mbed.h"
#include "HCSR04.h"
#include "SRF05.h"
#include "gyro.h"
SRF05 Usound1(p26,p15);
HCSR04 Usound2(p25,p16);
Ticker t1;
int n=0;
void distancedetectL()
{
    float u= Usound1.read();
    if(7<=u<=20)  {
        n+=1;
        if (n>=3)
        {
            //turnL();
            change(90);
            //driveit();
            n=0;
            }
        }
    }
void distancedetectR()
{
    float u= Usound2.read_cm();
    if(7<=u<=20)  {
        n+=1;
        if (n>=3)
        {
            //turnL();
            change(90);
            //driveit();
            n=0;
            }
        }
    }
void enable1()
{
   t1.detach();
   t1.attach(&distancedetectR,0.4);
    }  
void enable2()
{
   t1.detach();
   t1.attach(&distancedetectL,0.4);
    }