Tedd OKANO
/
PCA9955A_simple
PCA9955A test program
Revision 5:b93b28e126fe, committed 2021-10-20
- Comitter:
- okano
- Date:
- Wed Oct 20 08:17:05 2021 +0000
- Parent:
- 4:507e37f8008d
- Commit message:
- comment added
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 507e37f8008d -r b93b28e126fe main.cpp --- a/main.cpp Fri Aug 01 07:11:31 2014 +0000 +++ b/main.cpp Wed Oct 20 08:17:05 2021 +0000 @@ -3,7 +3,7 @@ I2C i2c( p28, p27 ); // SDA, SCL -#define SLAVE_ADDR 0x02 +#define SLAVE_ADDR 0x02 // I2C target (slave) adress void register_write( char addr, char data ); @@ -11,23 +11,25 @@ { // initialization - register_write( MODE1, 0x00 ); - register_write( MODE2, 0x25 ); - register_write( LEDOUT0, 0xAA ); - register_write( LEDOUT1, 0xAA ); - register_write( LEDOUT2, 0xAA ); - register_write( LEDOUT3, 0xAA ); - register_write( IREFALL, 0x10 ); + register_write( MODE1, 0x00 ); // mode setting + register_write( MODE2, 0x25 ); // mode setting + register_write( LEDOUT0, 0xAA ); // PWM output setting for LED0 .. LED3 + register_write( LEDOUT1, 0xAA ); // PWM output setting for LED4 .. LED7 + register_write( LEDOUT2, 0xAA ); // PWM output setting for LED8 .. LED11 + register_write( LEDOUT3, 0xAA ); // PWM output setting for LED12 .. LED15 + register_write( IREFALL, 0x10 ); // set all IREF register (output current setting) // operation loop while ( 1 ) { + // LED0 luminanceset from 0 to max by PWM for ( int i = 0; i < 256; i++ ) { register_write( PWM0, i ); wait( 0.01 ); } + // LED0 luminanceset from max to 0 by PWM for ( int i = 255; i >= 0; i-- ) { register_write( PWM0, i ); wait( 0.01 ); @@ -35,12 +37,12 @@ } } -void register_write( char addr, char data ) +void register_write( char addr /* register address */, char data /* data value */ ) { char d[ 2 ]; d[ 0 ] = addr; d[ 1 ] = data; - i2c.write( SLAVE_ADDR, d, 2 ); + i2c.write( SLAVE_ADDR, d, 2 ); // two bytes transfer to I2C target device which has address of SLAVE_ADDR }