Eurobot 2013 IR testbench

Dependencies:   mbed-rtos mbed

Committer:
xiaxia686
Date:
Wed Nov 14 16:53:28 2012 +0000
Revision:
0:5ebe36076172
Child:
1:818904abef3d
Eurobot2013 IR Testbench;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xiaxia686 0:5ebe36076172 1 /* mbed PwmIn Library
xiaxia686 0:5ebe36076172 2 * Copyright (c) 2008-2010, sford
xiaxia686 0:5ebe36076172 3 *
xiaxia686 0:5ebe36076172 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
xiaxia686 0:5ebe36076172 5 * of this software and associated documentation files (the "Software"), to deal
xiaxia686 0:5ebe36076172 6 * in the Software without restriction, including without limitation the rights
xiaxia686 0:5ebe36076172 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
xiaxia686 0:5ebe36076172 8 * copies of the Software, and to permit persons to whom the Software is
xiaxia686 0:5ebe36076172 9 * furnished to do so, subject to the following conditions:
xiaxia686 0:5ebe36076172 10 *
xiaxia686 0:5ebe36076172 11 * The above copyright notice and this permission notice shall be included in
xiaxia686 0:5ebe36076172 12 * all copies or substantial portions of the Software.
xiaxia686 0:5ebe36076172 13 *
xiaxia686 0:5ebe36076172 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
xiaxia686 0:5ebe36076172 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
xiaxia686 0:5ebe36076172 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
xiaxia686 0:5ebe36076172 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
xiaxia686 0:5ebe36076172 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
xiaxia686 0:5ebe36076172 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
xiaxia686 0:5ebe36076172 20 * THE SOFTWARE.
xiaxia686 0:5ebe36076172 21 */
xiaxia686 0:5ebe36076172 22
xiaxia686 0:5ebe36076172 23 #include "PwmIn.h"
xiaxia686 0:5ebe36076172 24
xiaxia686 0:5ebe36076172 25 PwmIn::PwmIn(PinName p) : _p(p) {
xiaxia686 0:5ebe36076172 26 _p.rise(this, &PwmIn::rise);
xiaxia686 0:5ebe36076172 27 _p.fall(this, &PwmIn::fall);
xiaxia686 0:5ebe36076172 28 _period = 0.0;
xiaxia686 0:5ebe36076172 29 _pulsewidth = 0.0;
xiaxia686 0:5ebe36076172 30 _t.start();
xiaxia686 0:5ebe36076172 31 }
xiaxia686 0:5ebe36076172 32
xiaxia686 0:5ebe36076172 33 float PwmIn::period() {
xiaxia686 0:5ebe36076172 34 return _period;
xiaxia686 0:5ebe36076172 35 }
xiaxia686 0:5ebe36076172 36
xiaxia686 0:5ebe36076172 37 float PwmIn::pulsewidth() {
xiaxia686 0:5ebe36076172 38 return _pulsewidth;
xiaxia686 0:5ebe36076172 39 }
xiaxia686 0:5ebe36076172 40
xiaxia686 0:5ebe36076172 41 float PwmIn::dutycycle() {
xiaxia686 0:5ebe36076172 42 return _pulsewidth / _period;
xiaxia686 0:5ebe36076172 43 }
xiaxia686 0:5ebe36076172 44
xiaxia686 0:5ebe36076172 45 void PwmIn::rise() {
xiaxia686 0:5ebe36076172 46 _period = _t.read();
xiaxia686 0:5ebe36076172 47 _t.reset();
xiaxia686 0:5ebe36076172 48 }
xiaxia686 0:5ebe36076172 49
xiaxia686 0:5ebe36076172 50 void PwmIn::fall() {
xiaxia686 0:5ebe36076172 51 _pulsewidth = _t.read();
xiaxia686 0:5ebe36076172 52 }