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.
Fork of MaxbotixDriver by
sonar.cpp
00001 #include "sonar.h" 00002 00003 Sonar::Sonar(PinName input, Timer& t) : 00004 interrupt(input), 00005 time(t), 00006 pulseStartTime(0), 00007 range(0) { 00008 interrupt.rise(this, &Sonar::pulseStart); 00009 interrupt.fall(this, &Sonar::pulseStop); 00010 } 00011 00012 int Sonar::read() { 00013 return range; 00014 } 00015 00016 Sonar::operator int() { 00017 return read(); 00018 } 00019 00020 void Sonar::pulseStart() { 00021 pulseStartTime = time.read_us(); 00022 } 00023 00024 void Sonar::pulseStop() { 00025 int endTime = time.read_us(); 00026 if (endTime < pulseStartTime) return; // Escape if there's been a roll over 00027 range = (endTime - pulseStartTime) / 58; // 58uS per CM 00028 }
Generated on Thu Jul 14 2022 20:44:41 by
1.7.2
