![](/media/cache/profiles/ed277964a8959e72a0d987e598dfbe72.50x50_q85.jpg)
update to suppress warning of "last line of file ends without a newline"
main.cpp@0:d65648cc3923, 2015-02-25 (annotated)
- Committer:
- nxp_ip
- Date:
- Wed Feb 25 06:51:30 2015 +0000
- Revision:
- 0:d65648cc3923
- Child:
- 2:e58648ee9d04
Initial version
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:d65648cc3923 | 6 | #define GRADATION_PERIOD 6.0 |
nxp_ip | 0:d65648cc3923 | 7 | |
nxp_ip | 0:d65648cc3923 | 8 | int main() |
nxp_ip | 0:d65648cc3923 | 9 | { |
nxp_ip | 0:d65648cc3923 | 10 | led_cntlr.gradation_group_setting( 0, 1 ); // Port 1 is assigned to group 0 |
nxp_ip | 0:d65648cc3923 | 11 | led_cntlr.gradation_group_setting( 0, 5 ); // Port 5 is assigned to group 0 |
nxp_ip | 0:d65648cc3923 | 12 | led_cntlr.gradation_group_setting( 0, 9 ); // Port 9 is assigned to group 0 |
nxp_ip | 0:d65648cc3923 | 13 | led_cntlr.gradation_group_setting( 0, 13 ); // Port 13 is assigned to group 0 |
nxp_ip | 0:d65648cc3923 | 14 | led_cntlr.gradation_group_setting( 1, 2 ); // Port 2 is assigned to group 1 |
nxp_ip | 0:d65648cc3923 | 15 | led_cntlr.gradation_group_setting( 1, 6 ); // Port 6 is assigned to group 1 |
nxp_ip | 0:d65648cc3923 | 16 | led_cntlr.gradation_group_setting( 1, 10 ); // Port 10 is assigned to group 1 |
nxp_ip | 0:d65648cc3923 | 17 | led_cntlr.gradation_group_setting( 1, 14 ); // Port 14 is assigned to group 1 |
nxp_ip | 0:d65648cc3923 | 18 | led_cntlr.gradation_group_setting( 2, 3 ); // Port 3 is assigned to group 2 |
nxp_ip | 0:d65648cc3923 | 19 | led_cntlr.gradation_group_setting( 2, 7 ); // Port 7 is assigned to group 2 |
nxp_ip | 0:d65648cc3923 | 20 | led_cntlr.gradation_group_setting( 2, 11 ); // Port 11 is assigned to group 2 |
nxp_ip | 0:d65648cc3923 | 21 | led_cntlr.gradation_group_setting( 2, 15 ); // Port 15 is assigned to group 2 |
nxp_ip | 0:d65648cc3923 | 22 | // Port 0, 4, 8 and 12 are not assigned to any groups |
nxp_ip | 0:d65648cc3923 | 23 | // Group 3 has no assigned port |
nxp_ip | 0:d65648cc3923 | 24 | |
nxp_ip | 0:d65648cc3923 | 25 | // Making same gradation shape to group 0, 1 and 2 |
nxp_ip | 0:d65648cc3923 | 26 | // The gradation shape will be total 6 seconds cycle including 2 seconds LED-OFF |
nxp_ip | 0:d65648cc3923 | 27 | float cycle = |
nxp_ip | 0:d65648cc3923 | 28 | led_cntlr.gradation_ramp_setting( 0, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_2_00_SEC, RAMP_UP_DOWN ); |
nxp_ip | 0:d65648cc3923 | 29 | led_cntlr.gradation_ramp_setting( 1, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_2_00_SEC, RAMP_UP_DOWN ); |
nxp_ip | 0:d65648cc3923 | 30 | led_cntlr.gradation_ramp_setting( 2, GRADATION_PERIOD, HOLD_0_00_SEC, HOLD_2_00_SEC, RAMP_UP_DOWN ); |
nxp_ip | 0:d65648cc3923 | 31 | |
nxp_ip | 0:d65648cc3923 | 32 | // Start group 0 |
nxp_ip | 0:d65648cc3923 | 33 | led_cntlr.gradation_start( 0 ); |
nxp_ip | 0:d65648cc3923 | 34 | |
nxp_ip | 0:d65648cc3923 | 35 | // Start group 1 (after 1/3 cycle delay) |
nxp_ip | 0:d65648cc3923 | 36 | wait( cycle / 3.0 ); |
nxp_ip | 0:d65648cc3923 | 37 | led_cntlr.gradation_start( 1 ); |
nxp_ip | 0:d65648cc3923 | 38 | |
nxp_ip | 0:d65648cc3923 | 39 | // Start group 2 (after 1/3 cycle delay) |
nxp_ip | 0:d65648cc3923 | 40 | wait( cycle / 3.0 ); |
nxp_ip | 0:d65648cc3923 | 41 | led_cntlr.gradation_start( 2 ); |
nxp_ip | 0:d65648cc3923 | 42 | |
nxp_ip | 0:d65648cc3923 | 43 | // |
nxp_ip | 0:d65648cc3923 | 44 | // Now the gradation control for 3 groups are working |
nxp_ip | 0:d65648cc3923 | 45 | // |
nxp_ip | 0:d65648cc3923 | 46 | |
nxp_ip | 0:d65648cc3923 | 47 | // |
nxp_ip | 0:d65648cc3923 | 48 | // Next while loop perform manual control for Rest of ports (0, 4, 8 and 12). |
nxp_ip | 0:d65648cc3923 | 49 | // You will see the operation for manual controll ports will be stopped if the I2C line is removed. |
nxp_ip | 0:d65648cc3923 | 50 | // But it continues the gradation control if only power supply is available |
nxp_ip | 0:d65648cc3923 | 51 | // |
nxp_ip | 0:d65648cc3923 | 52 | while(1) { |
nxp_ip | 0:d65648cc3923 | 53 | for ( int i = 1; i <= 100; i++ ) { |
nxp_ip | 0:d65648cc3923 | 54 | led_cntlr.pwm( 0, (float)i / 100.0 ); |
nxp_ip | 0:d65648cc3923 | 55 | led_cntlr.pwm( 4, (float)i / 100.0 ); |
nxp_ip | 0:d65648cc3923 | 56 | led_cntlr.pwm( 8, (float)i / 100.0 ); |
nxp_ip | 0:d65648cc3923 | 57 | led_cntlr.pwm( 12, (float)i / 100.0 ); |
nxp_ip | 0:d65648cc3923 | 58 | wait( 0.01 ); |
nxp_ip | 0:d65648cc3923 | 59 | } |
nxp_ip | 0:d65648cc3923 | 60 | } |
nxp_ip | 0:d65648cc3923 | 61 | } |