Program to demonstrate NXP semiconductor's PCA9955B chip working with the BBC micro:bit
Dependencies: PCA995xA microbit
Fork of PCA9955A_Hello by
This is a simple program that allows you to control each port on a PCA9955B connected over i2c to a BBC micro:bit using a simple USB serial communication program.
I've written it to work with the 2 digit SMD soldering kit I designed. Drop me an email at tb942@hotmail.co.uk for further info on that...
main.cpp@2:cfa5103184b1, 2015-03-04 (annotated)
- Committer:
- nxp_ip
- Date:
- Wed Mar 04 10:33:14 2015 +0000
- Revision:
- 2:cfa5103184b1
- Parent:
- 1:8b5c26cc269c
- Child:
- 3:a67c21ad4173
Library updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nxp_ip | 0:ec8cc77909e5 | 1 | #include "mbed.h" |
nxp_ip | 0:ec8cc77909e5 | 2 | |
nxp_ip | 0:ec8cc77909e5 | 3 | #include "PCA9955A.h" |
nxp_ip | 0:ec8cc77909e5 | 4 | PCA9955A led_cntlr( p28, p27, 0x02 ); // SDA, SCL, Slave_address(option) |
nxp_ip | 0:ec8cc77909e5 | 5 | |
nxp_ip | 1:8b5c26cc269c | 6 | int main() |
nxp_ip | 0:ec8cc77909e5 | 7 | { |
nxp_ip | 0:ec8cc77909e5 | 8 | led_cntlr.current( ALLPORTS, 1.0 ); // Set all ports output current 100% |
nxp_ip | 0:ec8cc77909e5 | 9 | |
nxp_ip | 0:ec8cc77909e5 | 10 | while(1) { |
nxp_ip | 0:ec8cc77909e5 | 11 | for ( int port = 0; port < led_cntlr.number_of_ports(); port++ ) { |
nxp_ip | 0:ec8cc77909e5 | 12 | for ( int i = 1; i <= 100; i++ ) { |
nxp_ip | 0:ec8cc77909e5 | 13 | led_cntlr.pwm( port, (float)i / 100.0 ); |
nxp_ip | 0:ec8cc77909e5 | 14 | wait( 0.01 ); |
nxp_ip | 0:ec8cc77909e5 | 15 | } |
nxp_ip | 0:ec8cc77909e5 | 16 | } |
nxp_ip | 0:ec8cc77909e5 | 17 | led_cntlr.pwm( ALLPORTS, 0.0 ); // Set all ports output PWM 0% |
nxp_ip | 0:ec8cc77909e5 | 18 | } |
nxp_ip | 0:ec8cc77909e5 | 19 | } |
nxp_ip | 2:cfa5103184b1 | 20 | |
nxp_ip | 2:cfa5103184b1 | 21 | |
nxp_ip | 2:cfa5103184b1 | 22 | |
nxp_ip | 2:cfa5103184b1 | 23 | #if 0 // Sample of using LedPwmOut API |
nxp_ip | 2:cfa5103184b1 | 24 | #include "mbed.h" |
nxp_ip | 2:cfa5103184b1 | 25 | #include "PCA9955A.h" |
nxp_ip | 2:cfa5103184b1 | 26 | |
nxp_ip | 2:cfa5103184b1 | 27 | PCA9955A led_cntlr( p28, p27, 0x02 ); |
nxp_ip | 2:cfa5103184b1 | 28 | LedPwmOutCC leds[] = { |
nxp_ip | 2:cfa5103184b1 | 29 | LedPwmOutCC( led_cntlr, L0 ), |
nxp_ip | 2:cfa5103184b1 | 30 | LedPwmOutCC( led_cntlr, L4 ), |
nxp_ip | 2:cfa5103184b1 | 31 | LedPwmOutCC( led_cntlr, L8 ), |
nxp_ip | 2:cfa5103184b1 | 32 | LedPwmOutCC( led_cntlr, L12 ), |
nxp_ip | 2:cfa5103184b1 | 33 | |
nxp_ip | 2:cfa5103184b1 | 34 | LedPwmOutCC( led_cntlr, L1 ), |
nxp_ip | 2:cfa5103184b1 | 35 | LedPwmOutCC( led_cntlr, L5 ), |
nxp_ip | 2:cfa5103184b1 | 36 | LedPwmOutCC( led_cntlr, L9 ), |
nxp_ip | 2:cfa5103184b1 | 37 | LedPwmOutCC( led_cntlr, L13 ), |
nxp_ip | 2:cfa5103184b1 | 38 | |
nxp_ip | 2:cfa5103184b1 | 39 | LedPwmOutCC( led_cntlr, L2 ), |
nxp_ip | 2:cfa5103184b1 | 40 | LedPwmOutCC( led_cntlr, L6 ), |
nxp_ip | 2:cfa5103184b1 | 41 | LedPwmOutCC( led_cntlr, L10 ), |
nxp_ip | 2:cfa5103184b1 | 42 | LedPwmOutCC( led_cntlr, L14 ), |
nxp_ip | 2:cfa5103184b1 | 43 | |
nxp_ip | 2:cfa5103184b1 | 44 | LedPwmOutCC( led_cntlr, L3 ), |
nxp_ip | 2:cfa5103184b1 | 45 | LedPwmOutCC( led_cntlr, L7 ), |
nxp_ip | 2:cfa5103184b1 | 46 | LedPwmOutCC( led_cntlr, L11 ), |
nxp_ip | 2:cfa5103184b1 | 47 | LedPwmOutCC( led_cntlr, L15 ), |
nxp_ip | 2:cfa5103184b1 | 48 | |
nxp_ip | 2:cfa5103184b1 | 49 | }; |
nxp_ip | 2:cfa5103184b1 | 50 | |
nxp_ip | 2:cfa5103184b1 | 51 | int main() |
nxp_ip | 2:cfa5103184b1 | 52 | { |
nxp_ip | 2:cfa5103184b1 | 53 | for ( int ch = 0; ch < 16; ch++ ) |
nxp_ip | 2:cfa5103184b1 | 54 | leds[ ch ] = 1.0; |
nxp_ip | 2:cfa5103184b1 | 55 | for ( int ch = 0; ch < 16; ch++ ) |
nxp_ip | 2:cfa5103184b1 | 56 | leds[ ch ].current( 0.0 ); |
nxp_ip | 2:cfa5103184b1 | 57 | |
nxp_ip | 2:cfa5103184b1 | 58 | while(1) { |
nxp_ip | 2:cfa5103184b1 | 59 | for ( int ch = 0; ch < 16; ch++ ) { |
nxp_ip | 2:cfa5103184b1 | 60 | for ( float p = 0.0; p < 1.0; p += 0.01 ) { |
nxp_ip | 2:cfa5103184b1 | 61 | // leds[ ch ] = p; |
nxp_ip | 2:cfa5103184b1 | 62 | leds[ ch ].current( p ); |
nxp_ip | 2:cfa5103184b1 | 63 | wait( 0.01 ); |
nxp_ip | 2:cfa5103184b1 | 64 | } |
nxp_ip | 2:cfa5103184b1 | 65 | } |
nxp_ip | 2:cfa5103184b1 | 66 | for ( float c = 1.0; c > 0.0; c -= 0.01 ) { |
nxp_ip | 2:cfa5103184b1 | 67 | for ( int ch = 0; ch < 16; ch++ ) { |
nxp_ip | 2:cfa5103184b1 | 68 | leds[ ch ].current( c ); |
nxp_ip | 2:cfa5103184b1 | 69 | |
nxp_ip | 2:cfa5103184b1 | 70 | } |
nxp_ip | 2:cfa5103184b1 | 71 | wait( 0.01 ); |
nxp_ip | 2:cfa5103184b1 | 72 | } |
nxp_ip | 2:cfa5103184b1 | 73 | } |
nxp_ip | 2:cfa5103184b1 | 74 | } |
nxp_ip | 2:cfa5103184b1 | 75 | #endif |