Interface to Analog devices AD5258 digital I2C potentiometer

Files at this revision

API Documentation at this revision

Comitter:
RodColeman
Date:
Mon Nov 11 11:00:35 2013 +0000
Child:
1:64570234d7b5
Commit message:
Initial untested version

Changed in this revision

AD5258.cpp Show annotated file Show diff for this revision Revisions of this file
AD5258.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AD5258.cpp	Mon Nov 11 11:00:35 2013 +0000
@@ -0,0 +1,21 @@
+#include "AD5258.h"
+#include "mbed.h"
+ 
+AD5258::AD5258(PinName sda, PinName scl, int address)
+        : _i2c(sda, scl) {
+    _address = address;
+}
+ 
+int AD5258::read() {
+    char foo[1];
+    _i2c.read(_address, foo, 1);
+    return foo[0];
+}
+ 
+void AD5258::write(int data) {
+    char foo[2];
+    foo[0] = 00;
+    foo[1] = data;
+    _i2c.write(_address, foo, 2);
+}
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AD5258.h	Mon Nov 11 11:00:35 2013 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+ 
+#ifndef MBED_AD5258_H
+#define MBED_AD5258_H
+ 
+// Interface to the AD5258 I2C 6-Bit digital Potentiometer
+
+class AD5258 {
+public:
+    /** Create an instance of the AD5258 connected to specfied I2C pins, with the specified address.
+     *
+     * @param sda The I2C data pin
+     * @param scl The I2C clock pin
+     * @param address The I2C address for this AD5258
+     */
+    AD5258(PinName sda, PinName scl, int address);
+ 
+    /** Read the RDAC value
+     *
+     * @return The 6-bit value read
+     */
+    int read();
+    
+    /** Write to the IO pins
+     * 
+     * @param data The 6-bits value: 0x00 to 0x3F to write to the pots RDAC
+     */
+    void write(int data);
+ 
+private:
+    I2C _i2c;
+    int _address;
+};
+ 
+#endif
\ No newline at end of file