Output digital pulses of specified length and read the length of input pulses.
Dependents: SeeedUltrasoundRangeFinder RangeFinder senplussd Sprint3_Sonar ... more
Pulse.h
00001 /* Copyright (c) 2012 Nick Ryder, University of Oxford 00002 * nick.ryder@physics.ox.ac.uk 00003 * 00004 * MIT License 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00007 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00008 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00009 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in all copies or 00013 * substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00016 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00017 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00018 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00020 */ 00021 00022 #ifndef MBED_PULSE_H 00023 #define MBED_PULSE_H 00024 00025 #include "mbed.h" 00026 00027 /** Pulse Input/Output Class(es) 00028 */ 00029 00030 class PulseInOut { 00031 public: 00032 /** Create a PulseInOut object connected to the specified pin 00033 * @param pin i/o pin to connect to 00034 */ 00035 PulseInOut(PinName); 00036 ~PulseInOut(); 00037 /** Set the value of the pin 00038 * @param val Value to set, 0 for LOW, otherwise HIGH 00039 */ 00040 void write(int val); 00041 /** Send a pulse of a given value for a specified time 00042 * @param val Value to set, 0 for LOW, otherwise HIGH 00043 * @param time Length of pulse in microseconds 00044 */ 00045 void write_us(int val, int time); 00046 /** Return the length of the next HIGH pulse in microsconds 00047 */ 00048 int read_high_us(); 00049 /** Return the length of the next HIGH pulse in microseconds or -1 if longer than timeout 00050 * @param timeout Time before pulse reading aborts and returns -1, in microseconds 00051 */ 00052 int read_high_us(int timeout); 00053 /** Return the length of the next LOW pulse in microsconds 00054 */ 00055 int read_low_us(); 00056 /** Return the length of the next LOW pulse in microseconds or -1 if longer than timeout 00057 * @param timeout Time before pulse reading aborts and returns -1, in microseconds 00058 */ 00059 int read_low_us(int timeout); 00060 /** Return the length of the next pulse in microsconds 00061 */ 00062 int read_us(); 00063 /** Return the length of the next pulse in microseconds or -1 if longer than timeout 00064 * @param timeout Time before pulse reading aborts and returns -1, in microseconds 00065 */ 00066 int read_us(int timeout); 00067 private: 00068 int startval; 00069 Timer pulsetime, runtime; 00070 DigitalInOut io; 00071 }; 00072 00073 #endif
Generated on Tue Jul 12 2022 19:05:50 by
