InetrfaceProducts NXP / Mbed 2 deprecated PCA9632_simple_operation_sample

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /** PCA9632 very simple operation sample
00002  *
00003  *  @author  Akifumi (Tedd) OKANO, NXP Semiconductors
00004  *  @version 1.0
00005  *  @date    22-Jan-2014
00006  *
00007  *  Released under the  Apache 2.0 open source licence -- http://opensource.org/licenses/Apache-2.0
00008  *
00009  *  This sample operates 4 LEDs on the evaluation board (OM13269 -- http://www.nxp.com/documents/user_manual/UM10528.pdf). 
00010  *  LED1(Red), LED2(Green) and LED3(Blue) are PWM controlled from mbed. 
00011  *  LED4 is controlled by group PWM function of PCA9632
00012  */
00013 
00014 #include "mbed.h"
00015 
00016 I2C     i2c( p28, p27 );
00017 
00018 
00019 char    data[]  = {
00020     0x80,
00021     0x80, 0x21,
00022     0x00, 0x00, 0x00, 0x40,
00023     0x80, 0x02,
00024     0xEA
00025 };
00026 
00027 char    blink_rate[]    = { 0x07, 0x00 };
00028 
00029 #define     I2C_ADDRESS     0xC4
00030 
00031 int main()
00032 {
00033     int     count;
00034 
00035     i2c.write( I2C_ADDRESS, data, sizeof( data ) );
00036 
00037     while ( 1 ) {
00038 
00039         for ( count = 0; count < 12; count++ ) {
00040             data[ 3 + ((count + 2) % 3) ]    = 0xFF;
00041             data[ 3 + ((count + 1) % 3) ]    = 0x00;
00042             data[ 3 + ((count + 0) % 3) ]    = 0x00;
00043             data[ 7 ]                               = 0;
00044             data[ 8 ]                               = 0;
00045             i2c.write( I2C_ADDRESS, data, 9 );
00046             wait( 0.25 );
00047 
00048             data[ 3 ]    = 0x00;
00049             data[ 4 ]    = 0x00;
00050             data[ 5 ]    = 0x00;
00051             data[ 7 ]                               = 0;
00052             data[ 8 ]                               = 0;
00053             i2c.write( I2C_ADDRESS, data, 9 );
00054 
00055             count++;
00056             wait( 0.25 );
00057         }
00058 
00059         for ( count = 0; count < 4096; count++ ) {
00060             data[ 3 + (((count >> 8) + 2) % 3) ]    = 0xFF - (count & 0xFF);
00061             data[ 3 + (((count >> 8) + 1) % 3) ]    = 0x00;
00062             data[ 3 + (((count >> 8) + 0) % 3) ]    = count & 0xFF;
00063             data[ 7 ]                               = 0;
00064             data[ 8 ]                               = 0;
00065             i2c.write( I2C_ADDRESS, data, 9 );
00066 
00067             count++;
00068             wait( 0.002 );
00069         }
00070 
00071         for ( count = 0; count < 2048; count++ ) {
00072             data[ 3 + (((count >> 8) + 2) % 3) ]    = 0xFF - (count & 0xFF);
00073             data[ 3 + (((count >> 8) + 1) % 3) ]    = 0x00;
00074             data[ 3 + (((count >> 8) + 0) % 3) ]    = count & 0xFF;
00075             data[ 7 ]                               = (count >>  9) & 0x1 ? 0x80 : 0x10;
00076             data[ 8 ]                               = (count >> 10) & 0x1 ?   23 :    2;
00077             i2c.write( I2C_ADDRESS, data, 9 );
00078 
00079             count++;
00080             wait( 0.01 );
00081         }
00082     }
00083 }