![](/media/cache/profiles/a53d1388191884b75c48bebb18709bfb.50x50_q85.jpg)
Hello world code for PCA9626 class library. The PCA9626 is a 24-channel Fm+ I2C-bus 100mA/40 V LED driver. This program shows its basic operation of PWM output.
Please refer to the component page for details
High-level API is available
A high-level API that can be used as the "PwmOut" of bed-SDK is available.
This API enables to make instances of each LED output pins and control PWM duty cycle by assignment.
For detail information, refer API document of LedPwmOut Class
class which is included in PCA962xA class library.
#include "mbed.h" #include "PCA9626.h" PCA9626 led_cntlr( p28, p27, 0xC4 ); // SDA, SCL, Slave_address(option) LedPwmOut led( led_cntlr, L0 ); int main() { while( 1 ) { for( float p = 0.0f; p < 1.0f; p += 0.1f ) { led = p; wait( 0.1 ); } } }
main.cpp@1:4e1fafcd63fa, 2015-03-04 (annotated)
- Committer:
- nxp_ip
- Date:
- Wed Mar 04 06:00:39 2015 +0000
- Revision:
- 1:4e1fafcd63fa
- Parent:
- 0:883e8fa760af
- Child:
- 2:1feea0f8e521
Version with LedPwmOut-API implemented library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nxp_ip | 0:883e8fa760af | 1 | #include "mbed.h" |
nxp_ip | 0:883e8fa760af | 2 | |
nxp_ip | 0:883e8fa760af | 3 | #include "PCA9626.h" |
nxp_ip | 0:883e8fa760af | 4 | PCA9626 led_cntlr( p28, p27, 0x3E ); // SDA, SCL, Slave_address(option) |
nxp_ip | 0:883e8fa760af | 5 | |
nxp_ip | 0:883e8fa760af | 6 | int main() |
nxp_ip | 0:883e8fa760af | 7 | { |
nxp_ip | 0:883e8fa760af | 8 | while(1) { |
nxp_ip | 0:883e8fa760af | 9 | for ( int port = 0; port < led_cntlr.number_of_ports(); port++ ) { |
nxp_ip | 0:883e8fa760af | 10 | for ( int i = 1; i <= 100; i++ ) { |
nxp_ip | 0:883e8fa760af | 11 | led_cntlr.pwm( port, (float)i / 100.0 ); |
nxp_ip | 0:883e8fa760af | 12 | wait( 0.01 ); |
nxp_ip | 0:883e8fa760af | 13 | } |
nxp_ip | 0:883e8fa760af | 14 | } |
nxp_ip | 0:883e8fa760af | 15 | led_cntlr.pwm( ALLPORTS, 0.0 ); |
nxp_ip | 0:883e8fa760af | 16 | } |
nxp_ip | 0:883e8fa760af | 17 | } |
nxp_ip | 1:4e1fafcd63fa | 18 | |
nxp_ip | 1:4e1fafcd63fa | 19 | |
nxp_ip | 1:4e1fafcd63fa | 20 | |
nxp_ip | 1:4e1fafcd63fa | 21 | |
nxp_ip | 1:4e1fafcd63fa | 22 | #if 0 // Sample of using LedPwmOut API |
nxp_ip | 1:4e1fafcd63fa | 23 | #include "mbed.h" |
nxp_ip | 1:4e1fafcd63fa | 24 | #include "PCA9626.h" |
nxp_ip | 1:4e1fafcd63fa | 25 | #include "PCA9622.h" |
nxp_ip | 1:4e1fafcd63fa | 26 | #include "PCA9624.h" |
nxp_ip | 1:4e1fafcd63fa | 27 | |
nxp_ip | 1:4e1fafcd63fa | 28 | PCA9626 led_cntlr( p28, p27, 0x3E ); // SDA, SCL, Slave_address(option) |
nxp_ip | 1:4e1fafcd63fa | 29 | |
nxp_ip | 1:4e1fafcd63fa | 30 | LedPwmOut leds[] = { |
nxp_ip | 1:4e1fafcd63fa | 31 | LedPwmOut( led_cntlr, L0 ), |
nxp_ip | 1:4e1fafcd63fa | 32 | LedPwmOut( led_cntlr, L1 ), |
nxp_ip | 1:4e1fafcd63fa | 33 | LedPwmOut( led_cntlr, L2 ), |
nxp_ip | 1:4e1fafcd63fa | 34 | LedPwmOut( led_cntlr, L3 ), |
nxp_ip | 1:4e1fafcd63fa | 35 | LedPwmOut( led_cntlr, L4 ), |
nxp_ip | 1:4e1fafcd63fa | 36 | LedPwmOut( led_cntlr, L5 ), |
nxp_ip | 1:4e1fafcd63fa | 37 | LedPwmOut( led_cntlr, L6 ), |
nxp_ip | 1:4e1fafcd63fa | 38 | LedPwmOut( led_cntlr, L7 ), |
nxp_ip | 1:4e1fafcd63fa | 39 | LedPwmOut( led_cntlr, L8 ), |
nxp_ip | 1:4e1fafcd63fa | 40 | LedPwmOut( led_cntlr, L9 ), |
nxp_ip | 1:4e1fafcd63fa | 41 | LedPwmOut( led_cntlr, L10 ), |
nxp_ip | 1:4e1fafcd63fa | 42 | LedPwmOut( led_cntlr, L11 ), |
nxp_ip | 1:4e1fafcd63fa | 43 | LedPwmOut( led_cntlr, L12 ), |
nxp_ip | 1:4e1fafcd63fa | 44 | LedPwmOut( led_cntlr, L13 ), |
nxp_ip | 1:4e1fafcd63fa | 45 | LedPwmOut( led_cntlr, L14 ), |
nxp_ip | 1:4e1fafcd63fa | 46 | LedPwmOut( led_cntlr, L15 ), |
nxp_ip | 1:4e1fafcd63fa | 47 | LedPwmOut( led_cntlr, L16 ), |
nxp_ip | 1:4e1fafcd63fa | 48 | LedPwmOut( led_cntlr, L17 ), |
nxp_ip | 1:4e1fafcd63fa | 49 | LedPwmOut( led_cntlr, L18 ), |
nxp_ip | 1:4e1fafcd63fa | 50 | LedPwmOut( led_cntlr, L19 ), |
nxp_ip | 1:4e1fafcd63fa | 51 | LedPwmOut( led_cntlr, L20 ), |
nxp_ip | 1:4e1fafcd63fa | 52 | LedPwmOut( led_cntlr, L21 ), |
nxp_ip | 1:4e1fafcd63fa | 53 | LedPwmOut( led_cntlr, L22 ), |
nxp_ip | 1:4e1fafcd63fa | 54 | LedPwmOut( led_cntlr, L23 ), |
nxp_ip | 1:4e1fafcd63fa | 55 | }; |
nxp_ip | 1:4e1fafcd63fa | 56 | |
nxp_ip | 1:4e1fafcd63fa | 57 | int main() |
nxp_ip | 1:4e1fafcd63fa | 58 | { |
nxp_ip | 1:4e1fafcd63fa | 59 | while(1) { |
nxp_ip | 1:4e1fafcd63fa | 60 | for ( int ch = 0; ch < 24; ch++ ) { |
nxp_ip | 1:4e1fafcd63fa | 61 | for ( float p = 0.0; p < 1.0; p += 0.01 ) { |
nxp_ip | 1:4e1fafcd63fa | 62 | leds[ ch ] = p; |
nxp_ip | 1:4e1fafcd63fa | 63 | wait( 0.01 ); |
nxp_ip | 1:4e1fafcd63fa | 64 | } |
nxp_ip | 1:4e1fafcd63fa | 65 | } |
nxp_ip | 1:4e1fafcd63fa | 66 | } |
nxp_ip | 1:4e1fafcd63fa | 67 | } |
nxp_ip | 1:4e1fafcd63fa | 68 | #endif |