dependent repository for sendFootSensorsPackets (The UDP packet repos)
Dependents: sendFootSensorsPacketsFinalUDP
Revision 0:e44491917262, committed 2016-07-01
- Comitter:
- mmellor
- Date:
- Fri Jul 01 18:53:27 2016 +0000
- Commit message:
- UDP Packet Sender (UDP packets constructed on the mbed side)
Changed in this revision
mcp3208.cpp | Show annotated file Show diff for this revision Revisions of this file |
mcp3208.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcp3208.cpp Fri Jul 01 18:53:27 2016 +0000 @@ -0,0 +1,31 @@ +// +// +// +#include "mcp3208.h" + + +MCP3208::MCP3208(PinName mosi, PinName miso, PinName clk, PinName cs) +: _spi(mosi,miso,clk), + _cs(cs), + _vref(5.0) +{ + _spi.frequency(2000000); + _spi.format(12,3); + _cs = 1; +} + +int +MCP3208::binary(int ch) +{ + _cs = 0; + int ret = _spi.write((0x18|ch)<<2); + int adb = _spi.write(0); + _cs = 1; + return adb; +} + +float +MCP3208::volt(int ch) +{ + return _vref * binary(ch) / 4095; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcp3208.h Fri Jul 01 18:53:27 2016 +0000 @@ -0,0 +1,22 @@ +// +// +// +#ifndef _MCP3208_H +#define _MCP3208_H + +#include <mbed.h> + +class MCP3208 { + protected: + SPI _spi; + DigitalOut _cs; + float _vref; + + public: + MCP3208(PinName mosi=p11, PinName miso=p12, PinName clk=p13, PinName cs=p14); + int binary(int ch); + float volt(int ch); + float vref(float v){return _vref=v;} +}; + +#endif //_MCP3208_H