This is a very simple sample code for the PCA9622_LED8x8 library. arget hardware : "I2C 8x8 LED matrix board" from Switch Science https://www.switch-science.com/catalog/2071/

Dependencies:   PCA9622_LED8x8 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**
00002  *  A hello world code for the PCA9622 LED 8x8 library
00003  *
00004  *  @author  Tedd OKANO
00005  *  @version 1.1
00006  *  @date    25-Dec-2014
00007  *
00008  *  This is a very simple sample 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 float func( float x, float y, float t );    //  function to make 8x8 image
00028 
00029 int main()
00030 {
00031     float   image[ 8 ][ 8 ];  //  
00032     int     count   = 0;
00033     
00034     while(1) {
00035         
00036         //  making 8x8 image to "image" array
00037         for ( int i = 0; i < 8; i++ )
00038             for ( int j = 0; j < 8; j++ )
00039                 image[ i ][ j ]   = func( i, j, count * 0.2 );
00040 
00041         //  set the image into library internal bufer
00042         matrix.set_data( image );
00043 
00044         count++;
00045         wait( 0.05 );
00046     }
00047 }
00048 
00049 float func( float x, float y, float t )
00050 {
00051 //#define     DISPLAY_OFFSET  3.5
00052 #define     DISPLAY_OFFSET  0
00053 #define     SIZE            0.3
00054 
00055     float   s;
00056     
00057     x   = (x - DISPLAY_OFFSET) * SIZE;
00058     y   = (y - DISPLAY_OFFSET) * SIZE;
00059 
00060     s   = cos( powf( x * x + y * y, 0.5 ) - t );
00061     return ( powf( s, 4.0 ) );
00062 }