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.h
00001 #include "mbed.h" 00002 00003 #ifndef SONAR_H 00004 #define SONAR_H 00005 /*** @file Driver for Maxbotix sonar modules 00006 * Uses pulse width input to read range results. 00007 * @author Daniel Casner <http://www.danielcasner.org> 00008 * 00009 * Known Issues: 00010 * If a timer rollover occures during a sample, the driver will drop that sample. 00011 */ 00012 00013 /** Object representation of a sonar instance 00014 */ 00015 class Sonar { 00016 public: 00017 /** Sets up the driver and starts taking measurements 00018 * @param input The pin to read pulses from 00019 * @param t A running timer instance used to measure pulse width. 00020 * Note that the timer must have been started or results will be 00021 * invalid. 00022 */ 00023 Sonar(PinName input, Timer& t); 00024 00025 /// Returns range in cm as int 00026 int read(); 00027 00028 /// Returns the range in CM as an int 00029 operator int(); 00030 00031 private: 00032 /// Inturrupt at start of pulse 00033 void pulseStart(); 00034 /// Interrupt at end of pulse 00035 void pulseStop(); 00036 00037 /// Interrupt driver for the input pin 00038 InterruptIn interrupt; 00039 /// Reference to global timer instance 00040 Timer& time; 00041 /// Time of the start of the current pulse 00042 int pulseStartTime; 00043 /// The most recent sample 00044 int range; 00045 }; 00046 00047 #endif
Generated on Thu Jul 14 2022 20:44:41 by
1.7.2
