A Library for MCP3008
Dependents: Nucleo_MCP3008_Test ProjetoBB KIK01 MASTER_SPI_MCP3008
Diff: mcp3008.cpp
- Revision:
- 2:96130c28149e
- Parent:
- 1:49d7a43f1368
- Child:
- 3:a9e08cdf0b95
--- a/mcp3008.cpp Sun Jun 18 19:37:35 2017 +0000 +++ b/mcp3008.cpp Sun Jun 18 19:58:42 2017 +0000 @@ -21,24 +21,7 @@ float MCP3008::read_input(int channel) { - /* - int command_high = START_BIT | MODE_SINGLE | ((channel & 0x04) >> 2); - int command_low = (channel & 0x03) << 6; - */ - int command_high = START_BIT; - int command_low = MODE_SINGLE | ((channel & 0x07) << 4); - - select(); - - // Odd writing requirements, see the datasheet for details - m_bus.write(command_high); - int high_byte = m_bus.write(command_low) & 0x03; - int low_byte = m_bus.write(0); - - deselect(); - - int conv_result = (high_byte << 8) | low_byte; - + int conv_result = read_input_u16(channel); return ((float)conv_result) / 1024; }