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
PCF8591.h@3:53bf66c0e0f6, 2013-11-15 (annotated)
- Committer:
- embeddedartists
- Date:
- Fri Nov 15 10:35:09 2013 +0000
- Revision:
- 3:53bf66c0e0f6
- Parent:
- 0:4ee0a6513a17
- Child:
- 4:a7d0ee55d5cd
Updated docs
Who changed what in which revision?
User | Revision | Line number | New 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 | * #include "LcdController.h" |
embeddedartists | 0:4ee0a6513a17 | 11 | * |
embeddedartists | 0:4ee0a6513a17 | 12 | * PCF8591 pcf; |
embeddedartists | 0:4ee0a6513a17 | 13 | * |
embeddedartists | 0:4ee0a6513a17 | 14 | * int main(void) { |
embeddedartists | 0:4ee0a6513a17 | 15 | * |
embeddedartists | 0:4ee0a6513a17 | 16 | * while(1) { |
embeddedartists | 3:53bf66c0e0f6 | 17 | * // read analog value |
embeddedartists | 3:53bf66c0e0f6 | 18 | * int val = pcf.read(PCF8591::A0); |
embeddedartists | 0:4ee0a6513a17 | 19 | * |
embeddedartists | 0:4ee0a6513a17 | 20 | * // do something with value... |
embeddedartists | 0:4ee0a6513a17 | 21 | * } |
embeddedartists | 0:4ee0a6513a17 | 22 | * } |
embeddedartists | 0:4ee0a6513a17 | 23 | * @endcode |
embeddedartists | 0:4ee0a6513a17 | 24 | */ |
embeddedartists | 0:4ee0a6513a17 | 25 | class PCF8591 { |
embeddedartists | 0:4ee0a6513a17 | 26 | public: |
embeddedartists | 0:4ee0a6513a17 | 27 | |
embeddedartists | 0:4ee0a6513a17 | 28 | enum AnalogIn { |
embeddedartists | 0:4ee0a6513a17 | 29 | A0, |
embeddedartists | 0:4ee0a6513a17 | 30 | A1, |
embeddedartists | 0:4ee0a6513a17 | 31 | A2, |
embeddedartists | 0:4ee0a6513a17 | 32 | A3 |
embeddedartists | 0:4ee0a6513a17 | 33 | }; |
embeddedartists | 0:4ee0a6513a17 | 34 | |
embeddedartists | 0:4ee0a6513a17 | 35 | |
embeddedartists | 0:4ee0a6513a17 | 36 | /** Create an interface to the PCF8591 chip |
embeddedartists | 0:4ee0a6513a17 | 37 | * |
embeddedartists | 0:4ee0a6513a17 | 38 | * |
embeddedartists | 0:4ee0a6513a17 | 39 | * @param sda the I2C SDA pin |
embeddedartists | 0:4ee0a6513a17 | 40 | * @param scl the I2C SCL pin |
embeddedartists | 0:4ee0a6513a17 | 41 | * @param i2cAddr the upper 7 bits of the chip's address |
embeddedartists | 0:4ee0a6513a17 | 42 | */ |
embeddedartists | 0:4ee0a6513a17 | 43 | PCF8591(PinName sda = P0_10, PinName scl = P0_11, int i2cAddr = 0x9E); |
embeddedartists | 0:4ee0a6513a17 | 44 | |
embeddedartists | 0:4ee0a6513a17 | 45 | /** Reads one value for the specified analog port |
embeddedartists | 0:4ee0a6513a17 | 46 | * |
embeddedartists | 0:4ee0a6513a17 | 47 | * @param port the analog in to read (A0..A3) |
embeddedartists | 0:4ee0a6513a17 | 48 | * |
embeddedartists | 0:4ee0a6513a17 | 49 | * @returns |
embeddedartists | 0:4ee0a6513a17 | 50 | * the value on success (0..255) |
embeddedartists | 0:4ee0a6513a17 | 51 | * -1 on failure |
embeddedartists | 0:4ee0a6513a17 | 52 | */ |
embeddedartists | 0:4ee0a6513a17 | 53 | int read(AnalogIn port); |
embeddedartists | 0:4ee0a6513a17 | 54 | |
embeddedartists | 0:4ee0a6513a17 | 55 | private: |
embeddedartists | 0:4ee0a6513a17 | 56 | I2C m_i2c; |
embeddedartists | 0:4ee0a6513a17 | 57 | int m_addr; |
embeddedartists | 0:4ee0a6513a17 | 58 | }; |
embeddedartists | 0:4ee0a6513a17 | 59 | |
embeddedartists | 0:4ee0a6513a17 | 60 | #endif |
embeddedartists | 0:4ee0a6513a17 | 61 |