InetrfaceProducts NXP / Mbed 2 deprecated PCA9622_LED8x8_Hello

Dependencies:   PCA9622_LED8x8 mbed

Committer:
nxp_ip
Date:
Fri Nov 28 10:53:10 2014 +0000
Revision:
1:2d0488faaa05
Parent:
0:ac9e3a1bbc8f
Child:
2:aaa5b046e49d
including published version library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 0:ac9e3a1bbc8f 1 /**
nxp_ip 0:ac9e3a1bbc8f 2 * A hello world code for the PCA9622 LED 8x8 library
nxp_ip 0:ac9e3a1bbc8f 3 *
nxp_ip 0:ac9e3a1bbc8f 4 * @author Tedd OKANO
nxp_ip 0:ac9e3a1bbc8f 5 * @version 1.0
nxp_ip 0:ac9e3a1bbc8f 6 * @date 28-Nov-2014
nxp_ip 0:ac9e3a1bbc8f 7 *
nxp_ip 0:ac9e3a1bbc8f 8 * This is a very simple sample code for the PCA9622_LED8x8 library.
nxp_ip 0:ac9e3a1bbc8f 9 * Target hardware : "I2C 8x8 LED matrix board" from Switch Science
nxp_ip 0:ac9e3a1bbc8f 10 * https://www.switch-science.com/catalog/2071/
nxp_ip 0:ac9e3a1bbc8f 11 *
nxp_ip 0:ac9e3a1bbc8f 12 * The I2C LED controller PCA9622 is used on this module
nxp_ip 0:ac9e3a1bbc8f 13 * that ebables to control the LEDs with PWM brightness control.
nxp_ip 0:ac9e3a1bbc8f 14 *
nxp_ip 0:ac9e3a1bbc8f 15 * For more information about the PCA9622:
nxp_ip 0:ac9e3a1bbc8f 16 * http://www.nxp.com/documents/data_sheet/PCA9622.pdf
nxp_ip 0:ac9e3a1bbc8f 17 */
nxp_ip 0:ac9e3a1bbc8f 18
nxp_ip 0:ac9e3a1bbc8f 19 #include "mbed.h"
nxp_ip 0:ac9e3a1bbc8f 20 #include "PCA9622_LED8x8.h"
nxp_ip 0:ac9e3a1bbc8f 21
nxp_ip 0:ac9e3a1bbc8f 22 // Choose a target platform from next list
nxp_ip 0:ac9e3a1bbc8f 23 PCA9622_LED8x8 matrix( p28, p27 ); // for 40pin type mbed
nxp_ip 0:ac9e3a1bbc8f 24 //PCA9622_LED8x8 matrix( D14, D15 ); // for Arduino type mbed
nxp_ip 0:ac9e3a1bbc8f 25 //PCA9622_LED8x8 matrix( dp5, dp27 ); // for mbed LPC1114
nxp_ip 0:ac9e3a1bbc8f 26
nxp_ip 0:ac9e3a1bbc8f 27 float func( float x, float y, float t ); // function to make 8x8 image
nxp_ip 0:ac9e3a1bbc8f 28
nxp_ip 0:ac9e3a1bbc8f 29 int main()
nxp_ip 0:ac9e3a1bbc8f 30 {
nxp_ip 0:ac9e3a1bbc8f 31 float image[ 8 ][ 8 ]; //
nxp_ip 0:ac9e3a1bbc8f 32 int count = 0;
nxp_ip 0:ac9e3a1bbc8f 33
nxp_ip 0:ac9e3a1bbc8f 34 matrix.start();
nxp_ip 0:ac9e3a1bbc8f 35
nxp_ip 0:ac9e3a1bbc8f 36 while(1) {
nxp_ip 0:ac9e3a1bbc8f 37
nxp_ip 0:ac9e3a1bbc8f 38 // making 8x8 image to "image" array
nxp_ip 0:ac9e3a1bbc8f 39 for ( int i = 0; i < 8; i++ )
nxp_ip 0:ac9e3a1bbc8f 40 for ( int j = 0; j < 8; j++ )
nxp_ip 0:ac9e3a1bbc8f 41 image[ i ][ j ] = func( i, j, count * 0.2 );
nxp_ip 0:ac9e3a1bbc8f 42
nxp_ip 0:ac9e3a1bbc8f 43 // set the image into library internal bufer
nxp_ip 0:ac9e3a1bbc8f 44 matrix.set_data( image );
nxp_ip 0:ac9e3a1bbc8f 45
nxp_ip 0:ac9e3a1bbc8f 46 count++;
nxp_ip 0:ac9e3a1bbc8f 47 wait( 0.05 );
nxp_ip 0:ac9e3a1bbc8f 48 }
nxp_ip 0:ac9e3a1bbc8f 49 }
nxp_ip 0:ac9e3a1bbc8f 50
nxp_ip 0:ac9e3a1bbc8f 51 float func( float x, float y, float t )
nxp_ip 0:ac9e3a1bbc8f 52 {
nxp_ip 0:ac9e3a1bbc8f 53 //#define DISPLAY_OFFSET 3.5
nxp_ip 0:ac9e3a1bbc8f 54 #define DISPLAY_OFFSET 0
nxp_ip 0:ac9e3a1bbc8f 55 #define SIZE 0.3
nxp_ip 0:ac9e3a1bbc8f 56
nxp_ip 0:ac9e3a1bbc8f 57 float s;
nxp_ip 0:ac9e3a1bbc8f 58
nxp_ip 0:ac9e3a1bbc8f 59 x = (x - DISPLAY_OFFSET) * SIZE;
nxp_ip 0:ac9e3a1bbc8f 60 y = (y - DISPLAY_OFFSET) * SIZE;
nxp_ip 0:ac9e3a1bbc8f 61
nxp_ip 0:ac9e3a1bbc8f 62 s = cos( powf( x * x + y * y, 0.5 ) - t );
nxp_ip 0:ac9e3a1bbc8f 63 return ( powf( s, 4.0 ) );
nxp_ip 0:ac9e3a1bbc8f 64 }