PCA9635 16-bit I2C-bus LED driver
Dependents: digitalThermometer Counter SimpleClock printNumber ... more
PCA9635.h
00001 //NXP PCA9635 library 00002 //mbed Team - 1st June 2011 00003 //Ioannis Kedros 00004 //updated by Daniel Worrall - 28th June 2011 00005 00006 #ifndef MBED_PCA9635_H 00007 #define MBED_PCA9635_H 00008 00009 #include "mbed.h" 00010 00011 /** PCA9635 class defined on an I2C master bus 00012 * 00013 * Example: 00014 * @code 00015 * //Turn each output on and then off in order p0 >> p15 00016 * //then ramp brightenss up and down at different speeds. 00017 * #include "mbed.h" 00018 * #include "PCA9635.h" 00019 * 00020 * DigitalOut enable(p26); 00021 * PCA9635 my_driver(p28, p27); 00022 * 00023 * int main() 00024 * { 00025 * enable = 0; 00026 * my_driver.init(0x02); 00027 * //N.B. you MUST declare init(int address), before calling any PCA9635 functions 00028 * //turns each pin on and then off 00029 * 00030 * short op = 1; 00031 * for(char j = 0; j < 16; j++){ 00032 * my_driver.bus(op); 00033 * wait(0.7); 00034 * op = (op << 1); 00035 * } 00036 * 00037 * //ramp brightness up three times faster than down, repeatedly 00038 * 00039 * while(1) 00040 * { 00041 * for(char valueUp=0; valueUp<0xFF; (valueUp = valueUp + 3)) 00042 * { 00043 * my_driver.brightness(ALL, valueUp); 00044 * } 00045 * 00046 * for(char valueD=0; valueD<0xFF; valueD++) 00047 * { 00048 * my_driver.brightness(ALL, (0xFF - valueD)); 00049 * wait(0.007); 00050 * } 00051 * } 00052 * } 00053 * @endcode 00054 */ 00055 00056 class PCA9635 { 00057 00058 public: 00059 /** Create a PCA9635 object, connected to the specified I2C pins 00060 * 00061 * @param sda Defines serial data line 00062 * @param scl Defines serial clock line 00063 */ 00064 PCA9635(PinName sda, PinName scl); 00065 00066 char cmd[2]; 00067 00068 //Output control 00069 00070 /** Set a particular output on PCA9635 high 00071 * 00072 * @param led LED pin coordinates 00073 */ 00074 void on(char led); 00075 /** Reset a particular output on PCA9635 low 00076 * 00077 * @param led LED pin coordinates 00078 */ 00079 void off(char led); 00080 /**Set all pins passed as argument high or low for current address 00081 * 00082 * @param leds Set output according to parameter value - e.g. 0x0003 >> p0 & p1 high, rest low 00083 */ 00084 void bus(short leds); 00085 /**Set all pins passed as argument high or low for specified address 00086 * 00087 * @param led Pin co-ordinates 00088 * @param value Brightness value 00089 */ 00090 void brightness(char led, char value); 00091 /** Set write address 00092 * 00093 * ¶m address write address 00094 */ 00095 void setAddress(int address); 00096 /** Reset chip 00097 * 00098 */ 00099 void reset(void); 00100 /** Initialise chip - MUST call this before calling any other functions 00101 * 00102 * @param address hardware address 00103 */ 00104 void init(int address); 00105 00106 private: 00107 I2C m_i2c; 00108 int m_addr; 00109 00110 #define ALL 0xFF 00111 }; 00112 00113 #endif
Generated on Tue Jul 19 2022 03:54:59 by 1.7.2