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.
Dependencies: PCA9622_LED8x8 mbed
main.cpp
00001 /** 00002 * A demo code for the PCA9622 LED 8x8 library 00003 * 00004 * @author Tedd OKANO 00005 * @version 1.0 00006 * @date 03-Dec-2014 00007 * 00008 * This is a sample demo code for the PCA9622_LED8x8 library. 00009 * Target hardware : "I2C 8x8 LED matrix board" from Switch Science 00010 * https://www.switch-science.com/catalog/2071/ 00011 * 00012 * The I2C LED controller PCA9622 is used on this module 00013 * that ebables to control the LEDs with PWM brightness control. 00014 * 00015 * For more information about the PCA9622: 00016 * http://www.nxp.com/documents/data_sheet/PCA9622.pdf 00017 */ 00018 00019 #include "mbed.h" 00020 #include "PCA9622_LED8x8.h" 00021 00022 // Choose a target platform from next list 00023 PCA9622_LED8x8 matrix( p28, p27 ); // for 40pin type mbed 00024 //PCA9622_LED8x8 matrix( D14, D15 ); // for Arduino type mbed 00025 //PCA9622_LED8x8 matrix( dp5, dp27 ); // for mbed LPC1114 00026 00027 Ticker _ticker; 00028 int demo_mode = 0; 00029 00030 void demo_mode_change(); 00031 float func0( int x, int y, int t ); // function to make 8x8 image 00032 float func1( int x, int y, int t ); // function to make 8x8 image 00033 float func2( int x, int y, int t ); // function to make 8x8 image 00034 float func3( int x, int y, int t ); // function to make 8x8 image 00035 00036 typedef float (*func_ptr)( int x, int y, int t ); 00037 00038 func_ptr fp[] = { 00039 func0, 00040 func1, 00041 func2, 00042 func3 00043 }; 00044 00045 int main() 00046 { 00047 float image[ 8 ][ 8 ]; // 00048 int count = 0; 00049 00050 _ticker.attach( &demo_mode_change, 10 ); 00051 matrix.start(); 00052 00053 while(1) { 00054 00055 // making 8x8 image to "image" array 00056 for ( int i = 0; i < 8; i++ ) 00057 for ( int j = 0; j < 8; j++ ) 00058 image[ i ][ j ] = (*fp[ demo_mode % (sizeof( fp ) / sizeof( func_ptr )) ])( i, j, count ); 00059 00060 // set the image into library internal bufer 00061 matrix.set_data( image ); 00062 00063 count++; 00064 wait( 0.05 ); 00065 } 00066 } 00067 00068 void demo_mode_change() 00069 { 00070 demo_mode++; 00071 } 00072 00073 float func0( int x, int y, int t ) 00074 { 00075 // NXP logo 00076 00077 static char bm_nxp[] = { 00078 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00079 00080 0xFF, 0xFF, 0xFF, 0xF0, 0x78, 0x3C, 0x1E, 0x0F, 00081 0xFF, 0x7E, 0xBD, 0xDB, 0xE7, 0x7E, 0x3C, 0x18, 00082 0x3C, 0x7E, 0xE7, 0xDB, 0xBD, 0x7E, 0xFF, 0xCC, 00083 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x78, 0x78, 00084 00085 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00086 }; 00087 00088 int index; 00089 int direction = 0; 00090 00091 direction = (t / (sizeof( bm_nxp ) - 8)) & 0x1; 00092 index = (t % (sizeof( bm_nxp ) - 8)); 00093 index = direction ? (sizeof( bm_nxp ) - 8) - index : index; 00094 index = index + y; 00095 00096 return (bm_nxp[ index ] >> (7 - x)) & 0x1; 00097 } 00098 00099 float func1( int x, int y, int t ) 00100 { 00101 // ripple 00102 00103 const float display_offset = 3.5; 00104 //const float display_offset = 0.0; 00105 const float size = 0.3; 00106 const float eccentricity_cycle = 0.0; 00107 const float eccentricity_amplitude = 0.0; 00108 00109 float xx; 00110 float yy; 00111 float tt; 00112 00113 float s; 00114 00115 xx = ((float)x - display_offset + eccentricity_amplitude * sin( (float)t * eccentricity_cycle )) * size; 00116 yy = ((float)y - display_offset + eccentricity_amplitude * cos( (float)t * eccentricity_cycle )) * size; 00117 tt = sin( (float)t * 0.2 ) + sin( (float)t * 0.1 ); 00118 00119 s = cos( powf( xx * xx + yy * yy, 0.5 ) - tt ); 00120 return ( powf( s, 4.0 ) ); 00121 } 00122 00123 float func2( int x, int y, int t ) 00124 { 00125 // moving dot 00126 00127 const float display_offset = 3.5; 00128 //const float display_offset = 0.0; 00129 const float size = 0.3; 00130 const float eccentricity_cycle = 0.25; 00131 const float eccentricity_amplitude = 2.5; 00132 00133 float xx; 00134 float yy; 00135 float tt; 00136 float s; 00137 float d; 00138 00139 00140 xx = ((float)x - display_offset + eccentricity_amplitude * sin( (float)t * eccentricity_cycle )) * size; 00141 yy = ((float)y - display_offset + eccentricity_amplitude * cos( (float)t * eccentricity_cycle )) * size; 00142 tt = (float)t * 0.2; 00143 d = powf( xx * xx + yy * yy, 0.5 ) - tt * 0.0; 00144 d = d == 0.0 ? 1e-12 : d; 00145 d *= 4.0; 00146 00147 s = sin( d ) / d; 00148 return ( powf( s, 4.0 ) ); 00149 } 00150 00151 float func3( int x, int y, int t ) 00152 { 00153 // ripple with offset 00154 00155 const float display_offset = 3.5; 00156 //const float display_offset = 0.0; 00157 const float size = 0.3; 00158 const float eccentricity_cycle = 0.25; 00159 const float eccentricity_amplitude = 2.5; 00160 00161 float xx; 00162 float yy; 00163 float tt; 00164 00165 float s; 00166 00167 xx = ((float)x - display_offset + eccentricity_amplitude * sin( (float)t * eccentricity_cycle )) * size; 00168 yy = ((float)y - display_offset + eccentricity_amplitude * cos( (float)t * eccentricity_cycle )) * size; 00169 tt = (float)t * 0.2; 00170 00171 s = cos( powf( xx * xx + yy * yy, 0.5 ) - tt ); 00172 return ( powf( s, 4.0 ) ); 00173 } 00174
Generated on Wed Jul 13 2022 20:24:41 by
1.7.2