PCA9635 16-bit I2C-bus LED driver
Dependents: digitalThermometer Counter SimpleClock printNumber ... more
Diff: PCA9635.h
- Revision:
- 0:d9cc568daeaf
- Child:
- 1:0a254eb888f1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PCA9635.h Tue Jun 28 10:03:49 2011 +0000 @@ -0,0 +1,104 @@ +//NXP PCA9635 library +//mbed Team - 1st June 2011 +//Ioannis Kedros +//updated by Daniel Worrall - 28th June 2011 + +#include "mbed.h" + +/** PCA9635 class defined on an I2C master bus +* +* Example: +* @code +* //Turn each output on and then off in order p0 >> p15 +* //then ramp brightenss up and down at different speeds. +* #include "mbed.h" +* #include "PCA9635.h" +* +* DigitalOut enable(p26); +* PCA9635 my_driver(p28, p27, 0x02); +* +* int main() +* { +* enable = 0; +* +* //turns each pin on and then off +* +* short op = 1; +* for(char j = 0; j < 16; j++){ +* my_driver.bus(op); +* wait(0.7); +* op = (op << 1); +* } +* +* //ramp brightness up three times faster than down, repeatedly +* +* while(1) +* { +* for(char valueUp=0; valueUp<0xFF; (valueUp = valueUp + 3)) +* { +* my_driver.brightness(ALL, valueUp); +* } +* +* for(char valueD=0; valueD<0xFF; valueD++) +* { +* my_driver.brightness(ALL, (0xFF - valueD)); +* wait(0.007); +* } +* } +* } +* @endcode +*/ + +class PCA9635 { + + public: + /** Create a PCA9635 object, connected to the specified I2C pins + * + * @param sda Defines serial data line + * @param scl Defines serial clock line + * @param addr chip address + */ + PCA9635(PinName sda, PinName scl, int addr); + + char cmd[2]; + + //Output control + + /** Set a particular output on PCA9635 high + * + * @param led LED pin coordinates + */ + void on(char led); + /** Reset a particular output on PCA9635 low + * + * @param led LED pin coordinates + */ + void off(char led); + /**Set all pins passed as argument high or low + * + * @param leds Set output according to parameter value - e.g. 0x0003 >> p0 & p1 high, rest low + */ + void bus(short leds); + /** Define LED brightness + * + * @param led LED pin coordinates + * @param value Brightness of LED, 0x00 < value < 0xFF + */ + void brightness(char led, char value); + + //Reset + + /** Reset chip + */ + void reset(void); + /** Initialise chip + */ + void init(void); + + + private: + I2C m_i2c; + int m_addr; + + #define ALL 0xFF +}; \ No newline at end of file