PCA9956B (24ch LED controller). Simple 2 demoboards operation.
Simple demo code for two PCA9956B demo boards.
main.cpp@0:c0060f6e9b43, 2015-07-22 (annotated)
- Committer:
- okano
- Date:
- Wed Jul 22 07:48:31 2015 +0000
- Revision:
- 0:c0060f6e9b43
Initial version of simple demo code using PCA9956A component library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:c0060f6e9b43 | 1 | #include "mbed.h" |
okano | 0:c0060f6e9b43 | 2 | #include "PCA9956A.h" |
okano | 0:c0060f6e9b43 | 3 | |
okano | 0:c0060f6e9b43 | 4 | I2C i2c( p28, p27 );// SDA, SCL |
okano | 0:c0060f6e9b43 | 5 | |
okano | 0:c0060f6e9b43 | 6 | #define CURRENT_SETTING 1.0 |
okano | 0:c0060f6e9b43 | 7 | |
okano | 0:c0060f6e9b43 | 8 | PCA9956A lc[] = { |
okano | 0:c0060f6e9b43 | 9 | PCA9956A( i2c, 0x02 ), |
okano | 0:c0060f6e9b43 | 10 | PCA9956A( i2c, 0x04 ) |
okano | 0:c0060f6e9b43 | 11 | }; |
okano | 0:c0060f6e9b43 | 12 | |
okano | 0:c0060f6e9b43 | 13 | LedPwmOutCC led[ 3 ][ 16 ] = { |
okano | 0:c0060f6e9b43 | 14 | { |
okano | 0:c0060f6e9b43 | 15 | LedPwmOutCC( lc[ 0 ], L0 ), |
okano | 0:c0060f6e9b43 | 16 | LedPwmOutCC( lc[ 0 ], L3 ), |
okano | 0:c0060f6e9b43 | 17 | LedPwmOutCC( lc[ 0 ], L6 ), |
okano | 0:c0060f6e9b43 | 18 | LedPwmOutCC( lc[ 0 ], L9 ), |
okano | 0:c0060f6e9b43 | 19 | LedPwmOutCC( lc[ 1 ], L0 ), |
okano | 0:c0060f6e9b43 | 20 | LedPwmOutCC( lc[ 1 ], L3 ), |
okano | 0:c0060f6e9b43 | 21 | LedPwmOutCC( lc[ 1 ], L6 ), |
okano | 0:c0060f6e9b43 | 22 | LedPwmOutCC( lc[ 1 ], L9 ), |
okano | 0:c0060f6e9b43 | 23 | LedPwmOutCC( lc[ 1 ], L12 ), |
okano | 0:c0060f6e9b43 | 24 | LedPwmOutCC( lc[ 1 ], L15 ), |
okano | 0:c0060f6e9b43 | 25 | LedPwmOutCC( lc[ 1 ], L18 ), |
okano | 0:c0060f6e9b43 | 26 | LedPwmOutCC( lc[ 1 ], L21 ), |
okano | 0:c0060f6e9b43 | 27 | LedPwmOutCC( lc[ 0 ], L12 ), |
okano | 0:c0060f6e9b43 | 28 | LedPwmOutCC( lc[ 0 ], L15 ), |
okano | 0:c0060f6e9b43 | 29 | LedPwmOutCC( lc[ 0 ], L18 ), |
okano | 0:c0060f6e9b43 | 30 | LedPwmOutCC( lc[ 0 ], L21 ), |
okano | 0:c0060f6e9b43 | 31 | }, |
okano | 0:c0060f6e9b43 | 32 | { |
okano | 0:c0060f6e9b43 | 33 | LedPwmOutCC( lc[ 0 ], L1 ), |
okano | 0:c0060f6e9b43 | 34 | LedPwmOutCC( lc[ 0 ], L4 ), |
okano | 0:c0060f6e9b43 | 35 | LedPwmOutCC( lc[ 0 ], L7 ), |
okano | 0:c0060f6e9b43 | 36 | LedPwmOutCC( lc[ 0 ], L10 ), |
okano | 0:c0060f6e9b43 | 37 | LedPwmOutCC( lc[ 1 ], L1 ), |
okano | 0:c0060f6e9b43 | 38 | LedPwmOutCC( lc[ 1 ], L4 ), |
okano | 0:c0060f6e9b43 | 39 | LedPwmOutCC( lc[ 1 ], L7 ), |
okano | 0:c0060f6e9b43 | 40 | LedPwmOutCC( lc[ 1 ], L10 ), |
okano | 0:c0060f6e9b43 | 41 | LedPwmOutCC( lc[ 1 ], L13 ), |
okano | 0:c0060f6e9b43 | 42 | LedPwmOutCC( lc[ 1 ], L16 ), |
okano | 0:c0060f6e9b43 | 43 | LedPwmOutCC( lc[ 1 ], L19 ), |
okano | 0:c0060f6e9b43 | 44 | LedPwmOutCC( lc[ 1 ], L22 ), |
okano | 0:c0060f6e9b43 | 45 | LedPwmOutCC( lc[ 0 ], L13 ), |
okano | 0:c0060f6e9b43 | 46 | LedPwmOutCC( lc[ 0 ], L16 ), |
okano | 0:c0060f6e9b43 | 47 | LedPwmOutCC( lc[ 0 ], L19 ), |
okano | 0:c0060f6e9b43 | 48 | LedPwmOutCC( lc[ 0 ], L22 ), |
okano | 0:c0060f6e9b43 | 49 | }, |
okano | 0:c0060f6e9b43 | 50 | { |
okano | 0:c0060f6e9b43 | 51 | LedPwmOutCC( lc[ 0 ], L2 ), |
okano | 0:c0060f6e9b43 | 52 | LedPwmOutCC( lc[ 0 ], L5 ), |
okano | 0:c0060f6e9b43 | 53 | LedPwmOutCC( lc[ 0 ], L8 ), |
okano | 0:c0060f6e9b43 | 54 | LedPwmOutCC( lc[ 0 ], L11 ), |
okano | 0:c0060f6e9b43 | 55 | LedPwmOutCC( lc[ 1 ], L2 ), |
okano | 0:c0060f6e9b43 | 56 | LedPwmOutCC( lc[ 1 ], L5 ), |
okano | 0:c0060f6e9b43 | 57 | LedPwmOutCC( lc[ 1 ], L8 ), |
okano | 0:c0060f6e9b43 | 58 | LedPwmOutCC( lc[ 1 ], L11 ), |
okano | 0:c0060f6e9b43 | 59 | LedPwmOutCC( lc[ 1 ], L14 ), |
okano | 0:c0060f6e9b43 | 60 | LedPwmOutCC( lc[ 1 ], L17 ), |
okano | 0:c0060f6e9b43 | 61 | LedPwmOutCC( lc[ 1 ], L20 ), |
okano | 0:c0060f6e9b43 | 62 | LedPwmOutCC( lc[ 1 ], L23 ), |
okano | 0:c0060f6e9b43 | 63 | LedPwmOutCC( lc[ 0 ], L14 ), |
okano | 0:c0060f6e9b43 | 64 | LedPwmOutCC( lc[ 0 ], L17 ), |
okano | 0:c0060f6e9b43 | 65 | LedPwmOutCC( lc[ 0 ], L20 ), |
okano | 0:c0060f6e9b43 | 66 | LedPwmOutCC( lc[ 0 ], L23 ), |
okano | 0:c0060f6e9b43 | 67 | } |
okano | 0:c0060f6e9b43 | 68 | }; |
okano | 0:c0060f6e9b43 | 69 | |
okano | 0:c0060f6e9b43 | 70 | |
okano | 0:c0060f6e9b43 | 71 | void simple_loop( void ) |
okano | 0:c0060f6e9b43 | 72 | { |
okano | 0:c0060f6e9b43 | 73 | for ( int color = 0; color < 3; color++ ) { |
okano | 0:c0060f6e9b43 | 74 | for ( int i = 0; i < 16; i++ ) { |
okano | 0:c0060f6e9b43 | 75 | led[ color ][ i ].current( CURRENT_SETTING ); |
okano | 0:c0060f6e9b43 | 76 | } |
okano | 0:c0060f6e9b43 | 77 | } |
okano | 0:c0060f6e9b43 | 78 | |
okano | 0:c0060f6e9b43 | 79 | for ( int repeat = 0; repeat < 2; repeat++ ) { |
okano | 0:c0060f6e9b43 | 80 | for ( int color = 0; color < 3; color++ ) { |
okano | 0:c0060f6e9b43 | 81 | for ( int i = 0; i < 16; i++ ) { |
okano | 0:c0060f6e9b43 | 82 | led[ color ][ i ] = 1.0; |
okano | 0:c0060f6e9b43 | 83 | wait( 0.02 ); |
okano | 0:c0060f6e9b43 | 84 | } |
okano | 0:c0060f6e9b43 | 85 | } |
okano | 0:c0060f6e9b43 | 86 | for ( int color = 0; color < 3; color++ ) { |
okano | 0:c0060f6e9b43 | 87 | for ( int i = 0; i < 16; i++ ) { |
okano | 0:c0060f6e9b43 | 88 | led[ color ][ i ] = 0.0; |
okano | 0:c0060f6e9b43 | 89 | wait( 0.02 ); |
okano | 0:c0060f6e9b43 | 90 | } |
okano | 0:c0060f6e9b43 | 91 | } |
okano | 0:c0060f6e9b43 | 92 | } |
okano | 0:c0060f6e9b43 | 93 | } |
okano | 0:c0060f6e9b43 | 94 | |
okano | 0:c0060f6e9b43 | 95 | #define N_OF_REPEATS 4 |
okano | 0:c0060f6e9b43 | 96 | #define CYCLE_STEPS 256 |
okano | 0:c0060f6e9b43 | 97 | #define PI 3.14159265 |
okano | 0:c0060f6e9b43 | 98 | |
okano | 0:c0060f6e9b43 | 99 | void demo_colors_inphase( void ) |
okano | 0:c0060f6e9b43 | 100 | { |
okano | 0:c0060f6e9b43 | 101 | float brightness[ 3 ]; |
okano | 0:c0060f6e9b43 | 102 | |
okano | 0:c0060f6e9b43 | 103 | for ( int repeat = 0; repeat < 3; repeat++ ) { |
okano | 0:c0060f6e9b43 | 104 | for ( int i = 0; i < CYCLE_STEPS; i++ ) { |
okano | 0:c0060f6e9b43 | 105 | brightness[ 0 ] = pow( sin( (float)(i + 0) * PI / CYCLE_STEPS ), 4 ); |
okano | 0:c0060f6e9b43 | 106 | brightness[ 1 ] = pow( sin( (float)(i + 85) * PI / CYCLE_STEPS ), 4 ); |
okano | 0:c0060f6e9b43 | 107 | brightness[ 2 ] = pow( sin( (float)(i + 170) * PI / CYCLE_STEPS ), 4 ); |
okano | 0:c0060f6e9b43 | 108 | |
okano | 0:c0060f6e9b43 | 109 | for ( int color = 0; color < 3; color++ ) { |
okano | 0:c0060f6e9b43 | 110 | for ( int j = 0; j < 16; j++ ) { |
okano | 0:c0060f6e9b43 | 111 | led[ color ][ j ] = brightness[ color ]; |
okano | 0:c0060f6e9b43 | 112 | } |
okano | 0:c0060f6e9b43 | 113 | } |
okano | 0:c0060f6e9b43 | 114 | wait( 0.01 ); |
okano | 0:c0060f6e9b43 | 115 | } |
okano | 0:c0060f6e9b43 | 116 | } |
okano | 0:c0060f6e9b43 | 117 | } |
okano | 0:c0060f6e9b43 | 118 | |
okano | 0:c0060f6e9b43 | 119 | void demo_colors_phase_gap( void ) |
okano | 0:c0060f6e9b43 | 120 | { |
okano | 0:c0060f6e9b43 | 121 | for ( int repeat = 0; repeat < 10; repeat++ ) { |
okano | 0:c0060f6e9b43 | 122 | for ( int i = 0; i < CYCLE_STEPS; i++ ) { |
okano | 0:c0060f6e9b43 | 123 | for ( int j = 0; j < 16; j++ ) { |
okano | 0:c0060f6e9b43 | 124 | led[ 0 ][ j ] = pow( sin( (float)(i + 0 + j * 16) * PI / CYCLE_STEPS ), 4 ); |
okano | 0:c0060f6e9b43 | 125 | led[ 1 ][ j ] = pow( sin( (float)(i + 85 + j * 16) * PI / CYCLE_STEPS ), 4 ); |
okano | 0:c0060f6e9b43 | 126 | led[ 2 ][ j ] = pow( sin( (float)(i + 170 + j * 16) * PI / CYCLE_STEPS ), 4 ); |
okano | 0:c0060f6e9b43 | 127 | } |
okano | 0:c0060f6e9b43 | 128 | //wait( 0.01 ); |
okano | 0:c0060f6e9b43 | 129 | } |
okano | 0:c0060f6e9b43 | 130 | } |
okano | 0:c0060f6e9b43 | 131 | } |
okano | 0:c0060f6e9b43 | 132 | |
okano | 0:c0060f6e9b43 | 133 | int main() |
okano | 0:c0060f6e9b43 | 134 | { |
okano | 0:c0060f6e9b43 | 135 | i2c.frequency( 400 * 1000 ); |
okano | 0:c0060f6e9b43 | 136 | |
okano | 0:c0060f6e9b43 | 137 | while( 1 ) { |
okano | 0:c0060f6e9b43 | 138 | simple_loop(); |
okano | 0:c0060f6e9b43 | 139 | demo_colors_inphase(); |
okano | 0:c0060f6e9b43 | 140 | simple_loop(); |
okano | 0:c0060f6e9b43 | 141 | demo_colors_phase_gap(); |
okano | 0:c0060f6e9b43 | 142 | } |
okano | 0:c0060f6e9b43 | 143 | } |