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.

Committer:
nxp_ip
Date:
Fri Jun 17 06:09:24 2022 +0000
Revision:
5:33de84f8a660
Parent:
2:0cc3bba73370
Made gradation period shorter

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 0:d65648cc3923 1 #include "mbed.h"
nxp_ip 0:d65648cc3923 2
nxp_ip 0:d65648cc3923 3 #include "PCA9955A.h"
nxp_ip 0:d65648cc3923 4 PCA9955A led_cntlr( p28, p27, 0x02 ); // SDA, SCL, Slave_address(option)
nxp_ip 0:d65648cc3923 5
nxp_ip 5:33de84f8a660 6 #define GRADATION_PERIOD 2.8
nxp_ip 2:0cc3bba73370 7
nxp_ip 2:0cc3bba73370 8 #define MANUAL_BLINK_PERIOD 0.1
nxp_ip 2:0cc3bba73370 9 #define MANUAL_BLINK_ON_DURATION 0.03
nxp_ip 0:d65648cc3923 10
nxp_ip 0:d65648cc3923 11 int main()
nxp_ip 0:d65648cc3923 12 {
nxp_ip 2:0cc3bba73370 13 // Set current ourput maximum (1.0 = 100%)
nxp_ip 2:0cc3bba73370 14 led_cntlr.current( ALLPORTS, 1.0 );
nxp_ip 2:0cc3bba73370 15
nxp_ip 2:0cc3bba73370 16 // Gradation control grouping
nxp_ip 0:d65648cc3923 17 led_cntlr.gradation_group_setting( 0, 1 ); // Port 1 is assigned to group 0
nxp_ip 0:d65648cc3923 18 led_cntlr.gradation_group_setting( 0, 5 ); // Port 5 is assigned to group 0
nxp_ip 0:d65648cc3923 19 led_cntlr.gradation_group_setting( 0, 9 ); // Port 9 is assigned to group 0
nxp_ip 0:d65648cc3923 20 led_cntlr.gradation_group_setting( 0, 13 ); // Port 13 is assigned to group 0
nxp_ip 0:d65648cc3923 21 led_cntlr.gradation_group_setting( 1, 2 ); // Port 2 is assigned to group 1
nxp_ip 0:d65648cc3923 22 led_cntlr.gradation_group_setting( 1, 6 ); // Port 6 is assigned to group 1
nxp_ip 0:d65648cc3923 23 led_cntlr.gradation_group_setting( 1, 10 ); // Port 10 is assigned to group 1
nxp_ip 0:d65648cc3923 24 led_cntlr.gradation_group_setting( 1, 14 ); // Port 14 is assigned to group 1
nxp_ip 0:d65648cc3923 25 led_cntlr.gradation_group_setting( 2, 3 ); // Port 3 is assigned to group 2
nxp_ip 0:d65648cc3923 26 led_cntlr.gradation_group_setting( 2, 7 ); // Port 7 is assigned to group 2
nxp_ip 0:d65648cc3923 27 led_cntlr.gradation_group_setting( 2, 11 ); // Port 11 is assigned to group 2
nxp_ip 0:d65648cc3923 28 led_cntlr.gradation_group_setting( 2, 15 ); // Port 15 is assigned to group 2
nxp_ip 0:d65648cc3923 29 // Port 0, 4, 8 and 12 are not assigned to any groups
nxp_ip 0:d65648cc3923 30 // Group 3 has no assigned port
nxp_ip 0:d65648cc3923 31
nxp_ip 0:d65648cc3923 32 // Making same gradation shape to group 0, 1 and 2
nxp_ip 0:d65648cc3923 33 // The gradation shape will be total 6 seconds cycle including 2 seconds LED-OFF
nxp_ip 0:d65648cc3923 34 float cycle =
nxp_ip 5:33de84f8a660 35 led_cntlr.gradation_ramp_setting( 0, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_0_75_SEC, RAMP_UP_DOWN );
nxp_ip 5:33de84f8a660 36 led_cntlr.gradation_ramp_setting( 1, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_0_75_SEC, RAMP_UP_DOWN );
nxp_ip 5:33de84f8a660 37 led_cntlr.gradation_ramp_setting( 2, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_0_75_SEC, RAMP_UP_DOWN );
nxp_ip 5:33de84f8a660 38
nxp_ip 5:33de84f8a660 39 // printf( "cycle = %f\r\n", cycle );
nxp_ip 0:d65648cc3923 40
nxp_ip 0:d65648cc3923 41 // Start group 0
nxp_ip 0:d65648cc3923 42 led_cntlr.gradation_start( 0 );
nxp_ip 0:d65648cc3923 43
nxp_ip 0:d65648cc3923 44 // Start group 1 (after 1/3 cycle delay)
nxp_ip 0:d65648cc3923 45 wait( cycle / 3.0 );
nxp_ip 0:d65648cc3923 46 led_cntlr.gradation_start( 1 );
nxp_ip 0:d65648cc3923 47
nxp_ip 0:d65648cc3923 48 // Start group 2 (after 1/3 cycle delay)
nxp_ip 0:d65648cc3923 49 wait( cycle / 3.0 );
nxp_ip 0:d65648cc3923 50 led_cntlr.gradation_start( 2 );
nxp_ip 0:d65648cc3923 51
nxp_ip 0:d65648cc3923 52 //
nxp_ip 0:d65648cc3923 53 // Now the gradation control for 3 groups are working
nxp_ip 0:d65648cc3923 54 //
nxp_ip 0:d65648cc3923 55
nxp_ip 0:d65648cc3923 56 //
nxp_ip 0:d65648cc3923 57 // Next while loop perform manual control for Rest of ports (0, 4, 8 and 12).
nxp_ip 0:d65648cc3923 58 // You will see the operation for manual controll ports will be stopped if the I2C line is removed.
nxp_ip 2:0cc3bba73370 59 // But it continues the gradation control while power supply is available
nxp_ip 0:d65648cc3923 60 //
nxp_ip 0:d65648cc3923 61 while(1) {
nxp_ip 2:0cc3bba73370 62 for ( int i = 0; i <= 12; i += 4 ) {
nxp_ip 2:0cc3bba73370 63 led_cntlr.pwm( i, 1.0 );
nxp_ip 2:0cc3bba73370 64 wait( MANUAL_BLINK_ON_DURATION );
nxp_ip 2:0cc3bba73370 65 led_cntlr.pwm( i, 0.0 );
nxp_ip 2:0cc3bba73370 66 wait( MANUAL_BLINK_PERIOD - MANUAL_BLINK_ON_DURATION );
nxp_ip 0:d65648cc3923 67 }
nxp_ip 0:d65648cc3923 68 }
nxp_ip 2:0cc3bba73370 69 }