![](/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
PwmReader.cpp
- Committer:
- sandwich
- Date:
- 2014-07-11
- Revision:
- 25:4f2f441eceec
- Parent:
- 7:e005cfaff8d1
File content as of revision 25:4f2f441eceec:
#include "PwmReader.h" //Constructors PwmReader::PwmReader(PinName pwmInPort, float min, float max) { if (min > max) { error("PwmReader min value greater than max value!"); } di = new InterruptIn(pwmInPort); pwmMin = min; pwmMax = max; lastRise = 0; period = 0; duty = 0.0; di->mode(PullDown); di->rise(this,&PwmReader::pwmRise); // attach the address of the flip function to the rising edge di->fall(this,&PwmReader::pwmFall); t.start(); } PwmReader::~PwmReader() { delete di; t.stop(); } // public methods float PwmReader::getDuty() { float smallDelta = (duty > pwmMin) ? (duty - pwmMin) : 0.0; float dutyAdjusted = smallDelta / (pwmMax-pwmMin); return dutyAdjusted; } // private methods void PwmReader::pwmRise() { int rise = t.read_us(); if( (lastRise > 0) && (rise > lastRise) ) { period = rise - lastRise; } lastRise = rise; } void PwmReader::pwmFall() { int fall = t.read_us(); if(period > 0 ) { int delta = fall - lastRise; duty = float(delta)/float(period); } }