Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Servo ServoArm mbed
Fork of PES_Official by
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 }
Generated on Sun Jul 17 2022 01:45:57 by
