NXP fan (in Japan) / Mbed 2 deprecated PCA9955A_Gradation_control

Dependencies:   mbed PCA995xA

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #include "PCA9955A.h"
00004 PCA9955A    led_cntlr( p28, p27, 0x02 );    //  SDA, SCL, Slave_address(option)
00005 
00006 #define     GRADATION_PERIOD    6.0
00007 
00008 int main()
00009 {
00010     led_cntlr.gradation_group_setting( 0,  1 ); //  Port  1 is assigned to group 0
00011     led_cntlr.gradation_group_setting( 0,  5 ); //  Port  5 is assigned to group 0
00012     led_cntlr.gradation_group_setting( 0,  9 ); //  Port  9 is assigned to group 0
00013     led_cntlr.gradation_group_setting( 0, 13 ); //  Port 13 is assigned to group 0
00014     led_cntlr.gradation_group_setting( 1,  2 ); //  Port  2 is assigned to group 1
00015     led_cntlr.gradation_group_setting( 1,  6 ); //  Port  6 is assigned to group 1
00016     led_cntlr.gradation_group_setting( 1, 10 ); //  Port 10 is assigned to group 1
00017     led_cntlr.gradation_group_setting( 1, 14 ); //  Port 14 is assigned to group 1
00018     led_cntlr.gradation_group_setting( 2,  3 ); //  Port  3 is assigned to group 2
00019     led_cntlr.gradation_group_setting( 2,  7 ); //  Port  7 is assigned to group 2
00020     led_cntlr.gradation_group_setting( 2, 11 ); //  Port 11 is assigned to group 2
00021     led_cntlr.gradation_group_setting( 2, 15 ); //  Port 15 is assigned to group 2
00022     //  Port 0, 4, 8 and 12 are not assigned to any groups
00023     //  Group 3 has no assigned port
00024 
00025     //  Making same gradation shape to group 0, 1 and 2
00026     //  The gradation shape will be total 6 seconds cycle including 2 seconds LED-OFF
00027     float cycle   =
00028     led_cntlr.gradation_ramp_setting( 0, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_2_00_SEC, RAMP_UP_DOWN );
00029     led_cntlr.gradation_ramp_setting( 1, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_2_00_SEC, RAMP_UP_DOWN );
00030     led_cntlr.gradation_ramp_setting( 2, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_2_00_SEC, RAMP_UP_DOWN );
00031 
00032     //  Start group 0
00033     led_cntlr.gradation_start( 0 );
00034 
00035     //  Start group 1 (after 1/3 cycle delay)
00036     wait( cycle / 3.0 );
00037     led_cntlr.gradation_start( 1 );
00038 
00039     //  Start group 2 (after 1/3 cycle delay)
00040     wait( cycle / 3.0 );
00041     led_cntlr.gradation_start( 2 );
00042 
00043     //
00044     //  Now the gradation control for 3 groups are working
00045     //
00046 
00047     //
00048     //  Next while loop perform manual control for Rest of ports (0, 4, 8 and 12).
00049     //  You will see the operation for manual controll ports will be stopped if the I2C line is removed.
00050     //  But it continues the gradation control if only power supply is available
00051     //
00052     while(1) {
00053         for ( int i = 1; i <= 100; i++ ) {
00054             led_cntlr.pwm(  0, (float)i / 100.0 );
00055             led_cntlr.pwm(  4, (float)i / 100.0 );
00056             led_cntlr.pwm(  8, (float)i / 100.0 );
00057             led_cntlr.pwm( 12, (float)i / 100.0 );
00058             wait( 0.01 );
00059         }
00060     }
00061 }