InetrfaceProducts NXP / Mbed 2 deprecated PCA9632_Hello

Dependencies:   PCA9632 mbed

Committer:
nxp_ip
Date:
Thu Mar 19 10:36:13 2015 +0000
Revision:
3:0143415767e4
Parent:
2:b8c6902f2ff7
Correction of comment. To include latest library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 0:71a4bafbcad2 1 #include "mbed.h"
nxp_ip 0:71a4bafbcad2 2 #include "PCA9632.h"
nxp_ip 0:71a4bafbcad2 3
nxp_ip 0:71a4bafbcad2 4 PCA9632 led_cntlr( p28, p27, 0xC4 ); // SDA, SCL, Slave_address(option)
nxp_ip 3:0143415767e4 5 LedPwmOut led0( led_cntlr, L0 ); // for LED0 pin
nxp_ip 3:0143415767e4 6 LedPwmOut led1( led_cntlr, L1 ); // for LED0 pin
nxp_ip 0:71a4bafbcad2 7
nxp_ip 0:71a4bafbcad2 8 int main()
nxp_ip 0:71a4bafbcad2 9 {
nxp_ip 0:71a4bafbcad2 10 //
nxp_ip 0:71a4bafbcad2 11 // Here are two types of PWM control samples
nxp_ip 0:71a4bafbcad2 12 // (User can choose one of those interface to set the PWM.)
nxp_ip 0:71a4bafbcad2 13 //
nxp_ip 0:71a4bafbcad2 14 // 1st sample is using LedPwmOut API.
nxp_ip 0:71a4bafbcad2 15 // It provides similar interface like PwmOut of mbed-SDK
nxp_ip 0:71a4bafbcad2 16 //
nxp_ip 0:71a4bafbcad2 17 // 2nd sample is using PCA9632 class function.
nxp_ip 0:71a4bafbcad2 18 // the 'pwm()' function takes LED channel number and duty-ratio value
nxp_ip 0:71a4bafbcad2 19 //
nxp_ip 0:71a4bafbcad2 20
nxp_ip 0:71a4bafbcad2 21 while ( 1 ) {
nxp_ip 3:0143415767e4 22
nxp_ip 0:71a4bafbcad2 23 //
nxp_ip 0:71a4bafbcad2 24 // 1st sample is using LedPwmOut API.
nxp_ip 0:71a4bafbcad2 25 // PWM control via LedPwmOut
nxp_ip 0:71a4bafbcad2 26 //
nxp_ip 0:71a4bafbcad2 27 for ( int i = 0; i < 3; i++ ) {
nxp_ip 2:b8c6902f2ff7 28 for( float p = 0.0f; p < 1.0f; p += 0.01f ) {
nxp_ip 3:0143415767e4 29 led0 = p; // Controls LED0 pin
nxp_ip 3:0143415767e4 30 led1 = 1.0 - p; // Controls LED1 pin
nxp_ip 2:b8c6902f2ff7 31 wait( 0.01 );
nxp_ip 0:71a4bafbcad2 32 }
nxp_ip 0:71a4bafbcad2 33 }
nxp_ip 0:71a4bafbcad2 34
nxp_ip 3:0143415767e4 35 led0 = 0.0;
nxp_ip 3:0143415767e4 36 led1 = 0.0;
nxp_ip 3:0143415767e4 37
nxp_ip 0:71a4bafbcad2 38 //
nxp_ip 0:71a4bafbcad2 39 // 2nd sample is using PCA9632 class function.
nxp_ip 0:71a4bafbcad2 40 // PWM control by device class function call
nxp_ip 0:71a4bafbcad2 41 //
nxp_ip 0:71a4bafbcad2 42 for ( int i = 0; i < 3; i++ ) {
nxp_ip 2:b8c6902f2ff7 43 for( float p = 0.0f; p < 1.0f; p += 0.01f ) {
nxp_ip 3:0143415767e4 44 led_cntlr.pwm( 2, p ); // Controls LED2 pin
nxp_ip 3:0143415767e4 45 led_cntlr.pwm( 3, 1.0 - p ); // Controls LED3 pin
nxp_ip 2:b8c6902f2ff7 46 wait( 0.01 );
nxp_ip 0:71a4bafbcad2 47 }
nxp_ip 0:71a4bafbcad2 48 }
nxp_ip 3:0143415767e4 49
nxp_ip 3:0143415767e4 50 led_cntlr.pwm( 2, 0.0 );
nxp_ip 3:0143415767e4 51 led_cntlr.pwm( 3, 0.0 );
nxp_ip 0:71a4bafbcad2 52 }
nxp_ip 0:71a4bafbcad2 53 }