Library with PCF8591 support for the experiments for LPC812 MAX

Dependents:   lpc812_exp_solution_analog-in lpc812_exp_solution_7-segment lpc812_exp_solution_7-segment-shift lpc812_exp_solution_pwm ... more

Fork of lpc812_exp_lib_PCF8591 by EmbeddedArtists AB

Committer:
embeddedartists
Date:
Fri Nov 22 14:59:28 2013 +0000
Revision:
4:a7d0ee55d5cd
Parent:
3:53bf66c0e0f6
Updated docs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:4ee0a6513a17 1 #ifndef PCF8591_H
embeddedartists 0:4ee0a6513a17 2 #define PCF8591_H
embeddedartists 0:4ee0a6513a17 3
embeddedartists 0:4ee0a6513a17 4 /**
embeddedartists 0:4ee0a6513a17 5 * Interface to the PCF8591 chip (http://www.nxp.com/documents/data_sheet/PCF8591.pdf)
embeddedartists 0:4ee0a6513a17 6 * which has four 8-bit analog inputs and one 8-bit analog output.
embeddedartists 0:4ee0a6513a17 7 *
embeddedartists 0:4ee0a6513a17 8 * @code
embeddedartists 0:4ee0a6513a17 9 * #include "mbed.h"
embeddedartists 0:4ee0a6513a17 10 *
embeddedartists 4:a7d0ee55d5cd 11 * PCF8591 adc;
embeddedartists 0:4ee0a6513a17 12 *
embeddedartists 0:4ee0a6513a17 13 * int main(void) {
embeddedartists 0:4ee0a6513a17 14 *
embeddedartists 0:4ee0a6513a17 15 * while(1) {
embeddedartists 3:53bf66c0e0f6 16 * // read analog value
embeddedartists 4:a7d0ee55d5cd 17 * int val = adc.read(PCF8591::A0);
embeddedartists 0:4ee0a6513a17 18 *
embeddedartists 0:4ee0a6513a17 19 * // do something with value...
embeddedartists 0:4ee0a6513a17 20 * }
embeddedartists 0:4ee0a6513a17 21 * }
embeddedartists 0:4ee0a6513a17 22 * @endcode
embeddedartists 0:4ee0a6513a17 23 */
embeddedartists 0:4ee0a6513a17 24 class PCF8591 {
embeddedartists 0:4ee0a6513a17 25 public:
embeddedartists 0:4ee0a6513a17 26
embeddedartists 0:4ee0a6513a17 27 enum AnalogIn {
embeddedartists 0:4ee0a6513a17 28 A0,
embeddedartists 0:4ee0a6513a17 29 A1,
embeddedartists 0:4ee0a6513a17 30 A2,
embeddedartists 0:4ee0a6513a17 31 A3
embeddedartists 0:4ee0a6513a17 32 };
embeddedartists 0:4ee0a6513a17 33
embeddedartists 0:4ee0a6513a17 34
embeddedartists 0:4ee0a6513a17 35 /** Create an interface to the PCF8591 chip
embeddedartists 0:4ee0a6513a17 36 *
embeddedartists 0:4ee0a6513a17 37 *
embeddedartists 0:4ee0a6513a17 38 * @param sda the I2C SDA pin
embeddedartists 0:4ee0a6513a17 39 * @param scl the I2C SCL pin
embeddedartists 0:4ee0a6513a17 40 * @param i2cAddr the upper 7 bits of the chip's address
embeddedartists 0:4ee0a6513a17 41 */
embeddedartists 0:4ee0a6513a17 42 PCF8591(PinName sda = P0_10, PinName scl = P0_11, int i2cAddr = 0x9E);
embeddedartists 0:4ee0a6513a17 43
embeddedartists 0:4ee0a6513a17 44 /** Reads one value for the specified analog port
embeddedartists 0:4ee0a6513a17 45 *
embeddedartists 0:4ee0a6513a17 46 * @param port the analog in to read (A0..A3)
embeddedartists 0:4ee0a6513a17 47 *
embeddedartists 0:4ee0a6513a17 48 * @returns
embeddedartists 0:4ee0a6513a17 49 * the value on success (0..255)
embeddedartists 0:4ee0a6513a17 50 * -1 on failure
embeddedartists 0:4ee0a6513a17 51 */
embeddedartists 0:4ee0a6513a17 52 int read(AnalogIn port);
embeddedartists 0:4ee0a6513a17 53
embeddedartists 0:4ee0a6513a17 54 private:
embeddedartists 0:4ee0a6513a17 55 I2C m_i2c;
embeddedartists 0:4ee0a6513a17 56 int m_addr;
embeddedartists 0:4ee0a6513a17 57 };
embeddedartists 0:4ee0a6513a17 58
embeddedartists 0:4ee0a6513a17 59 #endif
embeddedartists 0:4ee0a6513a17 60