![](/media/cache/profiles/a53d1388191884b75c48bebb18709bfb.50x50_q85.jpg)
Hello world code for PCA9632 library. This demonstrates device class call and "LedPwmOut class API".
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 "PCA9632.h" PCA9632 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 ); } } }
Revision 3:0143415767e4, committed 2015-03-19
- Comitter:
- nxp_ip
- Date:
- Thu Mar 19 10:36:13 2015 +0000
- Parent:
- 2:b8c6902f2ff7
- Commit message:
- Correction of comment. To include latest library
Changed in this revision
PCA9632.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r b8c6902f2ff7 -r 0143415767e4 PCA9632.lib --- a/PCA9632.lib Wed Mar 04 08:38:06 2015 +0000 +++ b/PCA9632.lib Thu Mar 19 10:36:13 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/nxp_ip/code/PCA9632/#32308cbf7e68 +http://developer.mbed.org/users/nxp_ip/code/PCA9632/#3574bf73abf5
diff -r b8c6902f2ff7 -r 0143415767e4 main.cpp --- a/main.cpp Wed Mar 04 08:38:06 2015 +0000 +++ b/main.cpp Thu Mar 19 10:36:13 2015 +0000 @@ -2,7 +2,8 @@ #include "PCA9632.h" PCA9632 led_cntlr( p28, p27, 0xC4 ); // SDA, SCL, Slave_address(option) -LedPwmOut led( led_cntlr, L0 ); // for LED0 pin +LedPwmOut led0( led_cntlr, L0 ); // for LED0 pin +LedPwmOut led1( led_cntlr, L1 ); // for LED0 pin int main() { @@ -18,27 +19,35 @@ // while ( 1 ) { - + // // 1st sample is using LedPwmOut API. // PWM control via LedPwmOut // for ( int i = 0; i < 3; i++ ) { for( float p = 0.0f; p < 1.0f; p += 0.01f ) { - led = p; // Controls LED0 pin + led0 = p; // Controls LED0 pin + led1 = 1.0 - p; // Controls LED1 pin wait( 0.01 ); } } + led0 = 0.0; + led1 = 0.0; + // // 2nd sample is using PCA9632 class function. // PWM control by device class function call // for ( int i = 0; i < 3; i++ ) { for( float p = 0.0f; p < 1.0f; p += 0.01f ) { - led_cntlr.pwm( 3, p ); // Controls LED1 pin + led_cntlr.pwm( 2, p ); // Controls LED2 pin + led_cntlr.pwm( 3, 1.0 - p ); // Controls LED3 pin wait( 0.01 ); } } + + led_cntlr.pwm( 2, 0.0 ); + led_cntlr.pwm( 3, 0.0 ); } }