Interface to Analog devices AD5258 digital I2C potentiometer
AD5258.cpp@0:8920c7d857d8, 2013-11-11 (annotated)
- Committer:
- RodColeman
- Date:
- Mon Nov 11 11:00:35 2013 +0000
- Revision:
- 0:8920c7d857d8
- Child:
- 1:64570234d7b5
Initial untested version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RodColeman | 0:8920c7d857d8 | 1 | #include "AD5258.h" |
RodColeman | 0:8920c7d857d8 | 2 | #include "mbed.h" |
RodColeman | 0:8920c7d857d8 | 3 | |
RodColeman | 0:8920c7d857d8 | 4 | AD5258::AD5258(PinName sda, PinName scl, int address) |
RodColeman | 0:8920c7d857d8 | 5 | : _i2c(sda, scl) { |
RodColeman | 0:8920c7d857d8 | 6 | _address = address; |
RodColeman | 0:8920c7d857d8 | 7 | } |
RodColeman | 0:8920c7d857d8 | 8 | |
RodColeman | 0:8920c7d857d8 | 9 | int AD5258::read() { |
RodColeman | 0:8920c7d857d8 | 10 | char foo[1]; |
RodColeman | 0:8920c7d857d8 | 11 | _i2c.read(_address, foo, 1); |
RodColeman | 0:8920c7d857d8 | 12 | return foo[0]; |
RodColeman | 0:8920c7d857d8 | 13 | } |
RodColeman | 0:8920c7d857d8 | 14 | |
RodColeman | 0:8920c7d857d8 | 15 | void AD5258::write(int data) { |
RodColeman | 0:8920c7d857d8 | 16 | char foo[2]; |
RodColeman | 0:8920c7d857d8 | 17 | foo[0] = 00; |
RodColeman | 0:8920c7d857d8 | 18 | foo[1] = data; |
RodColeman | 0:8920c7d857d8 | 19 | _i2c.write(_address, foo, 2); |
RodColeman | 0:8920c7d857d8 | 20 | } |
RodColeman | 0:8920c7d857d8 | 21 |