MCP4018 library
MCP4018.cpp@0:f32b8e382343, 2014-11-08 (annotated)
- Committer:
- yasuyuki
- Date:
- Sat Nov 08 12:14:31 2014 +0000
- Revision:
- 0:f32b8e382343
release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yasuyuki | 0:f32b8e382343 | 1 | //********************** |
yasuyuki | 0:f32b8e382343 | 2 | // MCP4018.cpp for mbed |
yasuyuki | 0:f32b8e382343 | 3 | // |
yasuyuki | 0:f32b8e382343 | 4 | // MCP4018 mcp4018(P0_5,P0_4); |
yasuyuki | 0:f32b8e382343 | 5 | // or |
yasuyuki | 0:f32b8e382343 | 6 | // I2C i2c(P0_5,P0_4); |
yasuyuki | 0:f32b8e382343 | 7 | // MCP4018 mcp4018(i2c); |
yasuyuki | 0:f32b8e382343 | 8 | // |
yasuyuki | 0:f32b8e382343 | 9 | // (C)Copyright 2014 All rights reserved by Y.Onodera |
yasuyuki | 0:f32b8e382343 | 10 | // http://einstlab.web.fc2.com |
yasuyuki | 0:f32b8e382343 | 11 | //********************** |
yasuyuki | 0:f32b8e382343 | 12 | |
yasuyuki | 0:f32b8e382343 | 13 | #include "mbed.h" |
yasuyuki | 0:f32b8e382343 | 14 | #include "MCP4018.h" |
yasuyuki | 0:f32b8e382343 | 15 | |
yasuyuki | 0:f32b8e382343 | 16 | MCP4018::MCP4018 (PinName sda, PinName scl) : _i2c(sda, scl) { |
yasuyuki | 0:f32b8e382343 | 17 | } |
yasuyuki | 0:f32b8e382343 | 18 | MCP4018::MCP4018 (I2C& p_i2c) : _i2c(p_i2c) { |
yasuyuki | 0:f32b8e382343 | 19 | } |
yasuyuki | 0:f32b8e382343 | 20 | |
yasuyuki | 0:f32b8e382343 | 21 | |
yasuyuki | 0:f32b8e382343 | 22 | void MCP4018::put(unsigned char a) |
yasuyuki | 0:f32b8e382343 | 23 | { |
yasuyuki | 0:f32b8e382343 | 24 | |
yasuyuki | 0:f32b8e382343 | 25 | buf[0]=0x7F & a; |
yasuyuki | 0:f32b8e382343 | 26 | _i2c.write(MCP4018_ADDR, buf, 1); |
yasuyuki | 0:f32b8e382343 | 27 | |
yasuyuki | 0:f32b8e382343 | 28 | } |
yasuyuki | 0:f32b8e382343 | 29 |