Sample code to demonstrate PCA9955A's gradation control

Dependencies:   mbed PCA995xA

Components / PCA9955B, PCA9956B : 16 & 24-channel constant current LED driver
PCA9955B and PCA9956B are I²C-bus controlled 16-channel constant current LED driver optimized for dimming and blinking.

main.cpp

Committer:
nxp_ip
Date:
22 months ago
Revision:
5:33de84f8a660
Parent:
2:0cc3bba73370

File content as of revision 5:33de84f8a660:

#include "mbed.h"

#include "PCA9955A.h"
PCA9955A    led_cntlr( p28, p27, 0x02 );    //  SDA, SCL, Slave_address(option)

#define GRADATION_PERIOD            2.8

#define MANUAL_BLINK_PERIOD         0.1
#define MANUAL_BLINK_ON_DURATION    0.03

int main()
{
    //  Set current ourput maximum (1.0 = 100%)
    led_cntlr.current( ALLPORTS, 1.0 );
    
    //  Gradation control grouping
    led_cntlr.gradation_group_setting( 0,  1 ); //  Port  1 is assigned to group 0
    led_cntlr.gradation_group_setting( 0,  5 ); //  Port  5 is assigned to group 0
    led_cntlr.gradation_group_setting( 0,  9 ); //  Port  9 is assigned to group 0
    led_cntlr.gradation_group_setting( 0, 13 ); //  Port 13 is assigned to group 0
    led_cntlr.gradation_group_setting( 1,  2 ); //  Port  2 is assigned to group 1
    led_cntlr.gradation_group_setting( 1,  6 ); //  Port  6 is assigned to group 1
    led_cntlr.gradation_group_setting( 1, 10 ); //  Port 10 is assigned to group 1
    led_cntlr.gradation_group_setting( 1, 14 ); //  Port 14 is assigned to group 1
    led_cntlr.gradation_group_setting( 2,  3 ); //  Port  3 is assigned to group 2
    led_cntlr.gradation_group_setting( 2,  7 ); //  Port  7 is assigned to group 2
    led_cntlr.gradation_group_setting( 2, 11 ); //  Port 11 is assigned to group 2
    led_cntlr.gradation_group_setting( 2, 15 ); //  Port 15 is assigned to group 2
    //  Port 0, 4, 8 and 12 are not assigned to any groups
    //  Group 3 has no assigned port

    //  Making same gradation shape to group 0, 1 and 2
    //  The gradation shape will be total 6 seconds cycle including 2 seconds LED-OFF
    float cycle   =
    led_cntlr.gradation_ramp_setting( 0, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_0_75_SEC, RAMP_UP_DOWN );
    led_cntlr.gradation_ramp_setting( 1, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_0_75_SEC, RAMP_UP_DOWN );
    led_cntlr.gradation_ramp_setting( 2, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_0_75_SEC, RAMP_UP_DOWN );

    //  printf( "cycle = %f\r\n", cycle );

    //  Start group 0
    led_cntlr.gradation_start( 0 );

    //  Start group 1 (after 1/3 cycle delay)
    wait( cycle / 3.0 );
    led_cntlr.gradation_start( 1 );

    //  Start group 2 (after 1/3 cycle delay)
    wait( cycle / 3.0 );
    led_cntlr.gradation_start( 2 );

    //
    //  Now the gradation control for 3 groups are working
    //

    //
    //  Next while loop perform manual control for Rest of ports (0, 4, 8 and 12).
    //  You will see the operation for manual controll ports will be stopped if the I2C line is removed.
    //  But it continues the gradation control while power supply is available
    //
    while(1) {
        for ( int i = 0; i <= 12; i += 4 ) {
            led_cntlr.pwm(  i, 1.0 );
            wait( MANUAL_BLINK_ON_DURATION );
            led_cntlr.pwm(  i, 0.0 );
            wait( MANUAL_BLINK_PERIOD - MANUAL_BLINK_ON_DURATION );
        }
    }
}