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:
Thu Jun 16 23:01:19 2022 +0000
Revision:
2:0cc3bba73370
Parent:
0:d65648cc3923
Child:
5:33de84f8a660
Demo behavior change (brighter manual blink); + Suppressing warning in KeilStudio and fix of API document

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 2:0cc3bba73370 6 #define GRADATION_PERIOD 6.0
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 0:d65648cc3923 35 led_cntlr.gradation_ramp_setting( 0, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_2_00_SEC, RAMP_UP_DOWN );
nxp_ip 0:d65648cc3923 36 led_cntlr.gradation_ramp_setting( 1, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_2_00_SEC, RAMP_UP_DOWN );
nxp_ip 0:d65648cc3923 37 led_cntlr.gradation_ramp_setting( 2, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_2_00_SEC, RAMP_UP_DOWN );
nxp_ip 0:d65648cc3923 38
nxp_ip 0:d65648cc3923 39 // Start group 0
nxp_ip 0:d65648cc3923 40 led_cntlr.gradation_start( 0 );
nxp_ip 0:d65648cc3923 41
nxp_ip 0:d65648cc3923 42 // Start group 1 (after 1/3 cycle delay)
nxp_ip 0:d65648cc3923 43 wait( cycle / 3.0 );
nxp_ip 0:d65648cc3923 44 led_cntlr.gradation_start( 1 );
nxp_ip 0:d65648cc3923 45
nxp_ip 0:d65648cc3923 46 // Start group 2 (after 1/3 cycle delay)
nxp_ip 0:d65648cc3923 47 wait( cycle / 3.0 );
nxp_ip 0:d65648cc3923 48 led_cntlr.gradation_start( 2 );
nxp_ip 0:d65648cc3923 49
nxp_ip 0:d65648cc3923 50 //
nxp_ip 0:d65648cc3923 51 // Now the gradation control for 3 groups are working
nxp_ip 0:d65648cc3923 52 //
nxp_ip 0:d65648cc3923 53
nxp_ip 0:d65648cc3923 54 //
nxp_ip 0:d65648cc3923 55 // Next while loop perform manual control for Rest of ports (0, 4, 8 and 12).
nxp_ip 0:d65648cc3923 56 // You will see the operation for manual controll ports will be stopped if the I2C line is removed.
nxp_ip 2:0cc3bba73370 57 // But it continues the gradation control while power supply is available
nxp_ip 0:d65648cc3923 58 //
nxp_ip 0:d65648cc3923 59 while(1) {
nxp_ip 2:0cc3bba73370 60 for ( int i = 0; i <= 12; i += 4 ) {
nxp_ip 2:0cc3bba73370 61 led_cntlr.pwm( i, 1.0 );
nxp_ip 2:0cc3bba73370 62 wait( MANUAL_BLINK_ON_DURATION );
nxp_ip 2:0cc3bba73370 63 led_cntlr.pwm( i, 0.0 );
nxp_ip 2:0cc3bba73370 64 wait( MANUAL_BLINK_PERIOD - MANUAL_BLINK_ON_DURATION );
nxp_ip 0:d65648cc3923 65 }
nxp_ip 0:d65648cc3923 66 }
nxp_ip 2:0cc3bba73370 67 }