![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
My modifications/additions to the code
Dependencies: ADXL345 ADXL345_I2C IMUfilter ITG3200 Servo fishgait mbed-rtos mbed pixy_cam
Fork of robotic_fish_ver_4_8 by
PwmIn.cpp
- Committer:
- sandwich
- Date:
- 2014-07-11
- Revision:
- 25:4f2f441eceec
- Parent:
- 22:807d5467fbf6
File content as of revision 25:4f2f441eceec:
#include "PwmIn.h" PwmIn::PwmIn(PinName p, float dutyMin, float dutyMax) : _p(p) { _p.rise(this, &PwmIn::rise); _p.fall(this, &PwmIn::fall); _period = 20000; _pulsewidth = 0; _t.start(); _risen = false; _dutyMin = dutyMin; _dutyMax = dutyMax; _dutyDelta = dutyMax - dutyMin; } float PwmIn::period() { return float(_period)/1000000; } float PwmIn::pulsewidth() { return float(_pulsewidth)/1000000; } float PwmIn::dutycycle() { return float(_pulsewidth) / float(_period); } float PwmIn::dutycyclescaledup() { float duty = float(_pulsewidth) / float(_period); float dutyAdjusted = (duty > _dutyMin) ? ((duty-_dutyMin)/_dutyDelta) : 0.0; return (dutyAdjusted < 1.0) ? dutyAdjusted : 1.0; } void PwmIn::rise() { _tmp = _t.read_us(); if(_tmp > 19000) { _period = _tmp; _risen = true; _t.reset(); } } void PwmIn::fall() { _tmp = _t.read_us(); if(_tmp > 500 && _tmp < 5000 && _risen == true) { _pulsewidth = _tmp; _risen = false; } }