MCP4018 library
See https://developer.mbed.org/users/yasuyuki/notebook/MCP4018/
Revision 0:f32b8e382343, committed 2014-11-08
- Comitter:
- yasuyuki
- Date:
- Sat Nov 08 12:14:31 2014 +0000
- Commit message:
- release
Changed in this revision
MCP4018.cpp | Show annotated file Show diff for this revision Revisions of this file |
MCP4018.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r f32b8e382343 MCP4018.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MCP4018.cpp Sat Nov 08 12:14:31 2014 +0000 @@ -0,0 +1,29 @@ +//********************** +// MCP4018.cpp for mbed +// +// MCP4018 mcp4018(P0_5,P0_4); +// or +// I2C i2c(P0_5,P0_4); +// MCP4018 mcp4018(i2c); +// +// (C)Copyright 2014 All rights reserved by Y.Onodera +// http://einstlab.web.fc2.com +//********************** + +#include "mbed.h" +#include "MCP4018.h" + +MCP4018::MCP4018 (PinName sda, PinName scl) : _i2c(sda, scl) { +} +MCP4018::MCP4018 (I2C& p_i2c) : _i2c(p_i2c) { +} + + +void MCP4018::put(unsigned char a) +{ + + buf[0]=0x7F & a; + _i2c.write(MCP4018_ADDR, buf, 1); + +} +
diff -r 000000000000 -r f32b8e382343 MCP4018.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MCP4018.h Sat Nov 08 12:14:31 2014 +0000 @@ -0,0 +1,31 @@ +//********************** +// MCP4018.h for mbed +// +// (C)Copyright 2014 All rights reserved by Y.Onodera +// http://einstlab.web.fc2.com +//********************** + +#ifndef MCP4018_H_ +#define MCP4018_H_ + +#define MCP4018_ADDR 0x5E + +#include "mbed.h" + + +class MCP4018{ +public: + MCP4018 (PinName sda, PinName scl); + MCP4018 (I2C& p_i2c); + void put(unsigned char a); + +protected: + + I2C _i2c; + + char buf[2]; + +}; + +#endif /* MCP4018_H_ */ +