Ohms law basic calculations for calculating R2 in voltage divider when R1 is known and to calculate voltage drop ratio when both R1 and R2 are known.
ohms.cpp
- Committer:
- joeata2wh
- Date:
- 2016-03-07
- Revision:
- 0:fe642275688d
- Child:
- 2:1c29960a42c6
- Child:
- 3:b4592b0ae1e3
File content as of revision 0:fe642275688d:
#include "mbed.h" //#include "ohms.h" float volDivideCalcRatio(long r1, long r2) { return ((float) r2 / (float) (r1 + r2)); } float voltDivideAdjVolt(float vin, long r1, long r2) { float ratio = ((float) r2 / (float) (r1 + r2)); return vin / ratio; } long calcResistV(long refResistR1, float maxV, float measuredV) { float VDrop = maxV - measuredV; float dropRatio = measuredV / VDrop; return (long) (refResistR1 * dropRatio); } /* adjVoltDivide::adjVoltDivide(long r1, long r2, float refVolt) { _r1 = r1; _r2 = r2; _refVolt = refVolt; _ratio = volDivideRatio(r1, r2); } float adjVoltDivide::read(AnalogIn apin) { return apin.read() / _ratio; } uint16_t adjVoltDivide::read_u16(AnalogIn apin) { return (int) ((float) apin.read_u16() / _ratio); } */