hello
Fork of MCP4725 by
Diff: mcp4725.cpp
- Revision:
- 5:3e6ffce1eea2
- Parent:
- 0:3214e3bbf25c
- Child:
- 6:35e3e80b804c
--- a/mcp4725.cpp Sun Nov 03 11:37:55 2013 +0000 +++ b/mcp4725.cpp Thu Nov 07 19:05:29 2013 +0000 @@ -1,10 +1,8 @@ #include "mcp4725.h" #include "mbed.h" -MCP4725::MCP4725(PinName sda, PinName scl, BusFrequency bus_frequency, int device_address_bits) +MCP4725::MCP4725(PinName sda, PinName scl, BusFrequency bus_frequency, int device_address_bits): _i2c_interface(sda, scl) { - _i2c_interface = new I2C(sda, scl); - //Set the frequency int freq=0; switch(bus_frequency) @@ -19,7 +17,7 @@ freq = 3400000; break; } - _i2c_interface->frequency(freq); + _i2c_interface.frequency(freq); // Assemble the full I2C device address. _device_address = 0xC0; // Prime the full device address with the device code. @@ -32,7 +30,7 @@ int result; // Read the raw data from the device. - result = _i2c_interface->read(_device_address, data, sizeof(data)/sizeof(*data), false); + result = _i2c_interface.read(_device_address, data, sizeof(data)/sizeof(*data), false); // Parse the raw data, extracting our fields. Refer to MCP4725 ref manual, section 6.2 if (result == 0) @@ -76,5 +74,5 @@ data[2] = (dac_value<<4); // Now write them to the device. - return _i2c_interface->write(_device_address, data, sizeof(data)/sizeof(*data), false); + return _i2c_interface.write(_device_address, data, sizeof(data)/sizeof(*data), false); } \ No newline at end of file