PCA9956B (24ch LED controller). Simple 2 demoboards operation.

Dependencies:   PCA995xA mbed

Simple demo code for two PCA9956B demo boards.

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Wed Jul 22 07:48:31 2015 +0000
Commit message:
Initial version of simple demo code using PCA9956A component library

Changed in this revision

PCA995xA.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PCA995xA.lib	Wed Jul 22 07:48:31 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/nxp_ip/code/PCA995xA/#cb07190e05e7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jul 22 07:48:31 2015 +0000
@@ -0,0 +1,143 @@
+#include "mbed.h"
+#include "PCA9956A.h"
+
+I2C i2c( p28, p27 );//  SDA, SCL
+
+#define     CURRENT_SETTING     1.0
+
+PCA9956A    lc[]    =  {
+    PCA9956A( i2c, 0x02 ),
+    PCA9956A( i2c, 0x04 )
+};
+
+LedPwmOutCC led[ 3 ][ 16 ]  = {
+    {
+        LedPwmOutCC( lc[ 0 ], L0  ),
+        LedPwmOutCC( lc[ 0 ], L3  ),
+        LedPwmOutCC( lc[ 0 ], L6  ),
+        LedPwmOutCC( lc[ 0 ], L9  ),
+        LedPwmOutCC( lc[ 1 ], L0  ),
+        LedPwmOutCC( lc[ 1 ], L3  ),
+        LedPwmOutCC( lc[ 1 ], L6  ),
+        LedPwmOutCC( lc[ 1 ], L9  ),
+        LedPwmOutCC( lc[ 1 ], L12 ),
+        LedPwmOutCC( lc[ 1 ], L15 ),
+        LedPwmOutCC( lc[ 1 ], L18 ),
+        LedPwmOutCC( lc[ 1 ], L21 ),
+        LedPwmOutCC( lc[ 0 ], L12 ),
+        LedPwmOutCC( lc[ 0 ], L15 ),
+        LedPwmOutCC( lc[ 0 ], L18 ),
+        LedPwmOutCC( lc[ 0 ], L21 ),
+    },
+    {
+        LedPwmOutCC( lc[ 0 ], L1  ),
+        LedPwmOutCC( lc[ 0 ], L4  ),
+        LedPwmOutCC( lc[ 0 ], L7  ),
+        LedPwmOutCC( lc[ 0 ], L10 ),
+        LedPwmOutCC( lc[ 1 ], L1  ),
+        LedPwmOutCC( lc[ 1 ], L4  ),
+        LedPwmOutCC( lc[ 1 ], L7  ),
+        LedPwmOutCC( lc[ 1 ], L10 ),
+        LedPwmOutCC( lc[ 1 ], L13 ),
+        LedPwmOutCC( lc[ 1 ], L16 ),
+        LedPwmOutCC( lc[ 1 ], L19 ),
+        LedPwmOutCC( lc[ 1 ], L22 ),
+        LedPwmOutCC( lc[ 0 ], L13 ),
+        LedPwmOutCC( lc[ 0 ], L16 ),
+        LedPwmOutCC( lc[ 0 ], L19 ),
+        LedPwmOutCC( lc[ 0 ], L22 ),
+    },
+    {
+        LedPwmOutCC( lc[ 0 ], L2  ),
+        LedPwmOutCC( lc[ 0 ], L5  ),
+        LedPwmOutCC( lc[ 0 ], L8  ),
+        LedPwmOutCC( lc[ 0 ], L11 ),
+        LedPwmOutCC( lc[ 1 ], L2  ),
+        LedPwmOutCC( lc[ 1 ], L5  ),
+        LedPwmOutCC( lc[ 1 ], L8  ),
+        LedPwmOutCC( lc[ 1 ], L11 ),
+        LedPwmOutCC( lc[ 1 ], L14 ),
+        LedPwmOutCC( lc[ 1 ], L17 ),
+        LedPwmOutCC( lc[ 1 ], L20 ),
+        LedPwmOutCC( lc[ 1 ], L23 ),
+        LedPwmOutCC( lc[ 0 ], L14 ),
+        LedPwmOutCC( lc[ 0 ], L17 ),
+        LedPwmOutCC( lc[ 0 ], L20 ),
+        LedPwmOutCC( lc[ 0 ], L23 ),
+    }
+};
+
+
+void simple_loop( void )
+{
+    for ( int color = 0; color < 3; color++ ) {
+        for ( int i = 0; i < 16; i++ ) {
+            led[ color ][ i ].current( CURRENT_SETTING );
+        }
+    }
+
+    for ( int repeat = 0; repeat < 2; repeat++ ) {
+        for ( int color = 0; color < 3; color++ ) {
+            for ( int i = 0; i < 16; i++ ) {
+                led[ color ][ i ]   = 1.0;
+                wait( 0.02 );
+            }
+        }
+        for ( int color = 0; color < 3; color++ ) {
+            for ( int i = 0; i < 16; i++ ) {
+                led[ color ][ i ]   = 0.0;
+                wait( 0.02 );
+            }
+        }
+    }
+}
+
+#define     N_OF_REPEATS    4
+#define     CYCLE_STEPS     256
+#define     PI              3.14159265
+
+void demo_colors_inphase( void )
+{
+    float   brightness[ 3 ];
+
+    for ( int repeat = 0; repeat < 3; repeat++ ) {
+        for ( int i = 0; i < CYCLE_STEPS; i++ ) {
+            brightness[ 0 ] = pow( sin( (float)(i +   0) * PI / CYCLE_STEPS ), 4 );
+            brightness[ 1 ] = pow( sin( (float)(i +  85) * PI / CYCLE_STEPS ), 4 );
+            brightness[ 2 ] = pow( sin( (float)(i + 170) * PI / CYCLE_STEPS ), 4 );
+
+            for ( int color = 0; color < 3; color++ ) {
+                for ( int j = 0; j < 16; j++ ) {
+                    led[ color ][ j ]   = brightness[ color ];
+                }
+            }
+            wait( 0.01 );
+        }
+    }
+}
+
+void demo_colors_phase_gap( void )
+{
+    for ( int repeat = 0; repeat < 10; repeat++ ) {
+        for ( int i = 0; i < CYCLE_STEPS; i++ ) {
+            for ( int j = 0; j < 16; j++ ) {
+                led[ 0 ][ j ] = pow( sin( (float)(i +   0 + j * 16) * PI / CYCLE_STEPS ), 4 );
+                led[ 1 ][ j ] = pow( sin( (float)(i +  85 + j * 16) * PI / CYCLE_STEPS ), 4 );
+                led[ 2 ][ j ] = pow( sin( (float)(i + 170 + j * 16) * PI / CYCLE_STEPS ), 4 );
+            }
+            //wait( 0.01 );
+        }
+    }
+}
+
+int main()
+{
+    i2c.frequency( 400 * 1000 );
+
+    while( 1 ) {
+        simple_loop();
+        demo_colors_inphase();
+        simple_loop();
+        demo_colors_phase_gap();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jul 22 07:48:31 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81
\ No newline at end of file