InetrfaceProducts NXP / Mbed 2 deprecated PCA9632_Hello

Dependencies:   PCA9632 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "PCA9632.h"
00003 
00004 PCA9632     led_cntlr( p28, p27, 0xC4 );    //  SDA, SCL, Slave_address(option)
00005 LedPwmOut   led0( led_cntlr, L0 );           //  for LED0 pin
00006 LedPwmOut   led1( led_cntlr, L1 );           //  for LED0 pin
00007 
00008 int main()
00009 {
00010     //
00011     //  Here are two types of PWM control samples
00012     //  (User can choose one of those interface to set the PWM.)
00013     //
00014     //  1st sample is using LedPwmOut API.
00015     //    It provides similar interface like PwmOut of mbed-SDK
00016     //
00017     //  2nd sample is using PCA9632 class function.
00018     //    the 'pwm()' function takes LED channel number and duty-ratio value
00019     //
00020 
00021     while ( 1 ) {
00022 
00023         //
00024         //  1st sample is using LedPwmOut API.
00025         //  PWM control via LedPwmOut
00026         //
00027         for ( int i = 0; i < 3; i++ ) {
00028             for( float p = 0.0f; p < 1.0f; p += 0.01f ) {
00029                 led0    = p;        //  Controls LED0 pin
00030                 led1    = 1.0 - p;  //  Controls LED1 pin
00031                 wait( 0.01 );
00032             }
00033         }
00034 
00035         led0    = 0.0;
00036         led1    = 0.0;
00037 
00038         //
00039         //  2nd sample is using PCA9632 class function.
00040         //  PWM control by device class function call
00041         //
00042         for ( int i = 0; i < 3; i++ ) {
00043             for( float p = 0.0f; p < 1.0f; p += 0.01f ) {
00044                 led_cntlr.pwm( 2, p );          //  Controls LED2 pin
00045                 led_cntlr.pwm( 3, 1.0 - p );    //  Controls LED3 pin
00046                 wait( 0.01 );
00047             }
00048         }
00049         
00050         led_cntlr.pwm( 2, 0.0 );
00051         led_cntlr.pwm( 3, 0.0 );
00052     }
00053 }