InetrfaceProducts NXP
/
PCA9955A_Gradation_control
Sample code to demonstrate PCA9955A's gradation control
Embed:
(wiki syntax)
Show/hide line numbers
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 2.8 00007 00008 #define MANUAL_BLINK_PERIOD 0.1 00009 #define MANUAL_BLINK_ON_DURATION 0.03 00010 00011 int main() 00012 { 00013 // Set current ourput maximum (1.0 = 100%) 00014 led_cntlr.current( ALLPORTS, 1.0 ); 00015 00016 // Gradation control grouping 00017 led_cntlr.gradation_group_setting( 0, 1 ); // Port 1 is assigned to group 0 00018 led_cntlr.gradation_group_setting( 0, 5 ); // Port 5 is assigned to group 0 00019 led_cntlr.gradation_group_setting( 0, 9 ); // Port 9 is assigned to group 0 00020 led_cntlr.gradation_group_setting( 0, 13 ); // Port 13 is assigned to group 0 00021 led_cntlr.gradation_group_setting( 1, 2 ); // Port 2 is assigned to group 1 00022 led_cntlr.gradation_group_setting( 1, 6 ); // Port 6 is assigned to group 1 00023 led_cntlr.gradation_group_setting( 1, 10 ); // Port 10 is assigned to group 1 00024 led_cntlr.gradation_group_setting( 1, 14 ); // Port 14 is assigned to group 1 00025 led_cntlr.gradation_group_setting( 2, 3 ); // Port 3 is assigned to group 2 00026 led_cntlr.gradation_group_setting( 2, 7 ); // Port 7 is assigned to group 2 00027 led_cntlr.gradation_group_setting( 2, 11 ); // Port 11 is assigned to group 2 00028 led_cntlr.gradation_group_setting( 2, 15 ); // Port 15 is assigned to group 2 00029 // Port 0, 4, 8 and 12 are not assigned to any groups 00030 // Group 3 has no assigned port 00031 00032 // Making same gradation shape to group 0, 1 and 2 00033 // The gradation shape will be total 6 seconds cycle including 2 seconds LED-OFF 00034 float cycle = 00035 led_cntlr.gradation_ramp_setting( 0, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_0_75_SEC, RAMP_UP_DOWN ); 00036 led_cntlr.gradation_ramp_setting( 1, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_0_75_SEC, RAMP_UP_DOWN ); 00037 led_cntlr.gradation_ramp_setting( 2, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_0_75_SEC, RAMP_UP_DOWN ); 00038 00039 // printf( "cycle = %f\r\n", cycle ); 00040 00041 // Start group 0 00042 led_cntlr.gradation_start( 0 ); 00043 00044 // Start group 1 (after 1/3 cycle delay) 00045 wait( cycle / 3.0 ); 00046 led_cntlr.gradation_start( 1 ); 00047 00048 // Start group 2 (after 1/3 cycle delay) 00049 wait( cycle / 3.0 ); 00050 led_cntlr.gradation_start( 2 ); 00051 00052 // 00053 // Now the gradation control for 3 groups are working 00054 // 00055 00056 // 00057 // Next while loop perform manual control for Rest of ports (0, 4, 8 and 12). 00058 // You will see the operation for manual controll ports will be stopped if the I2C line is removed. 00059 // But it continues the gradation control while power supply is available 00060 // 00061 while(1) { 00062 for ( int i = 0; i <= 12; i += 4 ) { 00063 led_cntlr.pwm( i, 1.0 ); 00064 wait( MANUAL_BLINK_ON_DURATION ); 00065 led_cntlr.pwm( i, 0.0 ); 00066 wait( MANUAL_BLINK_PERIOD - MANUAL_BLINK_ON_DURATION ); 00067 } 00068 } 00069 }
Generated on Wed Jul 13 2022 08:08:02 by 1.7.2