Simple wrapper object for LTC2606 1CH 16Bit DAC. Instantiate DacLtc2606 object instance passing reference to mbed.I2C object instance. Call write() method on DacLtc2606 instance passing 16Bit integer (0 [Off] to 32767/-32768 [Half-On] to -1 [Full-On]) to set DAC output.
DacLtc2606.cpp
- Committer:
- rkimble
- Date:
- 2012-09-13
- Revision:
- 0:896aaf4b80d0
- Child:
- 1:5924632f3344
File content as of revision 0:896aaf4b80d0:
#include "DacLtc2606.h" #include "mbed.h" DacLtc2606::DacLtc2606(I2C i2c) : _i2c(i2c) { } bool DacLtc2606::write(int value) { int opR; char args[3]; args[0] = _command; args[1] = (value >> 8) & 0xFF; args[2] = value & 0xFF; opR = _i2c.write(_slave, args, 3, false); return (opR == 0) ? true : false; } bool DacLtc2606::write(double percent) { if((percent >= 0.0) & (percent <= 1.0)) { int value = 0; if(percent < 0.5) { value = 32767.0 * (percent * 2); } else { value = -32768.0 * ((1.0 - percent) * 2); if(value == 0) {value = -1;} } return write(value); } return false; }