zhaw_st16b_pes2_10 / Mbed 2 deprecated PES_Official-TestF

Dependencies:   Servo ServoArm mbed

Fork of PES_Official by zhaw_st16b_pes2_10

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Ultraschall.cpp Source File

Ultraschall.cpp

00001 #include "Ultraschall.h"
00002  
00003  
00004 Ultraschall::Ultraschall(PinName TrigPin,PinName EchoPin):
00005     trigger(TrigPin), echo(EchoPin)
00006 {
00007     pulsetime.stop();
00008     pulsetime.reset();
00009     echo.rise(this,&Ultraschall::isr_rise);
00010     echo.fall(this,&Ultraschall::isr_fall);
00011     trigger=0;
00012 }
00013  
00014 Ultraschall::~Ultraschall()
00015 {
00016 }
00017  
00018 void Ultraschall::isr_rise(void)
00019 {
00020     pulsetime.start();
00021 }
00022 void Ultraschall::start(void)
00023 {
00024     trigger=1;
00025     wait_us(10);
00026     trigger=0;
00027 }
00028  
00029 void Ultraschall::isr_fall(void)
00030 {
00031     pulsetime.stop();
00032     pulsedur = pulsetime.read_us();
00033     distance= (pulsedur*343)/20000;
00034     pulsetime.reset();
00035 }
00036  
00037 void Ultraschall::rise (void (*fptr)(void))
00038 {
00039     echo.rise(fptr);
00040 }
00041 void Ultraschall::fall (void (*fptr)(void))
00042 {
00043     echo.fall(fptr);
00044 }
00045  
00046 unsigned int Ultraschall::get_dist_cm()
00047 {
00048     return distance;
00049 }
00050 unsigned int Ultraschall::get_pulse_us()
00051 {
00052     return pulsedur;
00053 }