Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "PCA9956A.h" 00003 00004 I2C i2c( p28, p27 );// SDA, SCL 00005 00006 #define CURRENT_SETTING 1.0 00007 00008 PCA9956A lc[] = { 00009 PCA9956A( i2c, 0x02 ), 00010 PCA9956A( i2c, 0x04 ) 00011 }; 00012 00013 LedPwmOutCC led[ 3 ][ 16 ] = { 00014 { 00015 LedPwmOutCC( lc[ 0 ], L0 ), 00016 LedPwmOutCC( lc[ 0 ], L3 ), 00017 LedPwmOutCC( lc[ 0 ], L6 ), 00018 LedPwmOutCC( lc[ 0 ], L9 ), 00019 LedPwmOutCC( lc[ 1 ], L0 ), 00020 LedPwmOutCC( lc[ 1 ], L3 ), 00021 LedPwmOutCC( lc[ 1 ], L6 ), 00022 LedPwmOutCC( lc[ 1 ], L9 ), 00023 LedPwmOutCC( lc[ 1 ], L12 ), 00024 LedPwmOutCC( lc[ 1 ], L15 ), 00025 LedPwmOutCC( lc[ 1 ], L18 ), 00026 LedPwmOutCC( lc[ 1 ], L21 ), 00027 LedPwmOutCC( lc[ 0 ], L12 ), 00028 LedPwmOutCC( lc[ 0 ], L15 ), 00029 LedPwmOutCC( lc[ 0 ], L18 ), 00030 LedPwmOutCC( lc[ 0 ], L21 ), 00031 }, 00032 { 00033 LedPwmOutCC( lc[ 0 ], L1 ), 00034 LedPwmOutCC( lc[ 0 ], L4 ), 00035 LedPwmOutCC( lc[ 0 ], L7 ), 00036 LedPwmOutCC( lc[ 0 ], L10 ), 00037 LedPwmOutCC( lc[ 1 ], L1 ), 00038 LedPwmOutCC( lc[ 1 ], L4 ), 00039 LedPwmOutCC( lc[ 1 ], L7 ), 00040 LedPwmOutCC( lc[ 1 ], L10 ), 00041 LedPwmOutCC( lc[ 1 ], L13 ), 00042 LedPwmOutCC( lc[ 1 ], L16 ), 00043 LedPwmOutCC( lc[ 1 ], L19 ), 00044 LedPwmOutCC( lc[ 1 ], L22 ), 00045 LedPwmOutCC( lc[ 0 ], L13 ), 00046 LedPwmOutCC( lc[ 0 ], L16 ), 00047 LedPwmOutCC( lc[ 0 ], L19 ), 00048 LedPwmOutCC( lc[ 0 ], L22 ), 00049 }, 00050 { 00051 LedPwmOutCC( lc[ 0 ], L2 ), 00052 LedPwmOutCC( lc[ 0 ], L5 ), 00053 LedPwmOutCC( lc[ 0 ], L8 ), 00054 LedPwmOutCC( lc[ 0 ], L11 ), 00055 LedPwmOutCC( lc[ 1 ], L2 ), 00056 LedPwmOutCC( lc[ 1 ], L5 ), 00057 LedPwmOutCC( lc[ 1 ], L8 ), 00058 LedPwmOutCC( lc[ 1 ], L11 ), 00059 LedPwmOutCC( lc[ 1 ], L14 ), 00060 LedPwmOutCC( lc[ 1 ], L17 ), 00061 LedPwmOutCC( lc[ 1 ], L20 ), 00062 LedPwmOutCC( lc[ 1 ], L23 ), 00063 LedPwmOutCC( lc[ 0 ], L14 ), 00064 LedPwmOutCC( lc[ 0 ], L17 ), 00065 LedPwmOutCC( lc[ 0 ], L20 ), 00066 LedPwmOutCC( lc[ 0 ], L23 ), 00067 } 00068 }; 00069 00070 00071 void simple_loop( void ) 00072 { 00073 for ( int color = 0; color < 3; color++ ) { 00074 for ( int i = 0; i < 16; i++ ) { 00075 led[ color ][ i ].current( CURRENT_SETTING ); 00076 } 00077 } 00078 00079 for ( int repeat = 0; repeat < 2; repeat++ ) { 00080 for ( int color = 0; color < 3; color++ ) { 00081 for ( int i = 0; i < 16; i++ ) { 00082 led[ color ][ i ] = 1.0; 00083 wait( 0.02 ); 00084 } 00085 } 00086 for ( int color = 0; color < 3; color++ ) { 00087 for ( int i = 0; i < 16; i++ ) { 00088 led[ color ][ i ] = 0.0; 00089 wait( 0.02 ); 00090 } 00091 } 00092 } 00093 } 00094 00095 #define N_OF_REPEATS 4 00096 #define CYCLE_STEPS 256 00097 #define PI 3.14159265 00098 00099 void demo_colors_inphase( void ) 00100 { 00101 float brightness[ 3 ]; 00102 00103 for ( int repeat = 0; repeat < 3; repeat++ ) { 00104 for ( int i = 0; i < CYCLE_STEPS; i++ ) { 00105 brightness[ 0 ] = pow( sin( (float)(i + 0) * PI / CYCLE_STEPS ), 4 ); 00106 brightness[ 1 ] = pow( sin( (float)(i + 85) * PI / CYCLE_STEPS ), 4 ); 00107 brightness[ 2 ] = pow( sin( (float)(i + 170) * PI / CYCLE_STEPS ), 4 ); 00108 00109 for ( int color = 0; color < 3; color++ ) { 00110 for ( int j = 0; j < 16; j++ ) { 00111 led[ color ][ j ] = brightness[ color ]; 00112 } 00113 } 00114 wait( 0.01 ); 00115 } 00116 } 00117 } 00118 00119 void demo_colors_phase_gap( void ) 00120 { 00121 for ( int repeat = 0; repeat < 10; repeat++ ) { 00122 for ( int i = 0; i < CYCLE_STEPS; i++ ) { 00123 for ( int j = 0; j < 16; j++ ) { 00124 led[ 0 ][ j ] = pow( sin( (float)(i + 0 + j * 16) * PI / CYCLE_STEPS ), 4 ); 00125 led[ 1 ][ j ] = pow( sin( (float)(i + 85 + j * 16) * PI / CYCLE_STEPS ), 4 ); 00126 led[ 2 ][ j ] = pow( sin( (float)(i + 170 + j * 16) * PI / CYCLE_STEPS ), 4 ); 00127 } 00128 //wait( 0.01 ); 00129 } 00130 } 00131 } 00132 00133 int main() 00134 { 00135 i2c.frequency( 400 * 1000 ); 00136 00137 while( 1 ) { 00138 simple_loop(); 00139 demo_colors_inphase(); 00140 simple_loop(); 00141 demo_colors_phase_gap(); 00142 } 00143 }
Generated on Tue Jul 19 2022 12:53:49 by
1.7.2