Q

Dependents:   PROJ515_USS_GPS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SRF05.cpp Source File

SRF05.cpp

00001 #include "SRF05.h"     // Contains Libraries, Definitions & Function Prototypes
00002 
00003 // Constructor
00004 SRF05::SRF05(PinName TrigPin,PinName EchoPin):
00005     trigger(TrigPin), echo(EchoPin)
00006 {
00007     pulsetime.stop();
00008     pulsetime.reset();
00009     echo.rise(this,&SRF05::isr_rise);
00010     echo.fall(this,&SRF05::isr_fall);
00011     trigger = 0;
00012 }
00013 
00014 // Starting the sensor
00015 void SRF05::start(void)
00016 {
00017     trigger=1;
00018     wait_us(10);
00019     trigger=0;
00020 }
00021 
00022 // Return signal start
00023 void SRF05::isr_rise(void)
00024 {
00025     pulsetime.start();
00026 }
00027 
00028 // Return signal end
00029 void SRF05::isr_fall(void)
00030 {
00031     pulsetime.stop();
00032     pulsedur = pulsetime.read_us();
00033     distance = (pulsedur*343)/20000;
00034     distance = distance/100;
00035     pulsetime.reset();
00036 }
00037 
00038 // Get distance
00039 float SRF05::get_dist()
00040 {
00041     return distance;
00042 }