Bubble display example using NXP PCAL9555A GPIO expander
Fork of PCAL9555_Hello by
Revision 4:0f3b252fb13f, committed 2017-02-22
- Comitter:
- MACRUM
- Date:
- Wed Feb 22 00:56:52 2017 +0000
- Parent:
- 3:f74f521b2e46
- Commit message:
- Code clean-up
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r f74f521b2e46 -r 0f3b252fb13f main.cpp --- a/main.cpp Sat Feb 18 15:37:34 2017 +0000 +++ b/main.cpp Wed Feb 22 00:56:52 2017 +0000 @@ -1,24 +1,14 @@ -#pragma Ospace - #include "mbed.h" -#if 1 - -#ifdef USE_LIB -#include "PCAL9555.h" +#if defined(TARGET_LPC812) +I2C gpio_exp(P0_10, P0_11); +#elif defined(TARGET_LPC810) +I2C gpio_exp(dp2, dp3); +#else +I2C gpio_exp(SDA, SCL); #endif -#if defined(TARGET_LPC81X) -//PCAL9555 gpio_exp(P0_10, P0_11); -I2C gpio_exp(dp4, dp3); -#else -//PCAL9555 gpio_exp(SDA, SCL); -I2C gpio_exp(SDA, SCL); -#endif - -//Serial pc(USBTX, USBRX); -Ticker tick; - +Ticker tick; static int _seg; static int _chrs[4]; @@ -39,7 +29,7 @@ { int port_0; int _data; - + _data = (dispTabl[_chrs[_seg]]); switch(_seg) { @@ -61,15 +51,11 @@ break; } -#ifdef USE_LIB - gpio_exp.write( (_data << 8) | port_0 ); -#else char buf[3]; - buf[0] = 2; // OUTPUT - buf[1] = port_0; - buf[2] = _data; // output + buf[0] = 2; // OUTPUT + buf[1] = port_0; // Port 0 + buf[2] = _data; // Port 1 gpio_exp.write(0x40, buf, 3); -#endif } void write_number(int num) @@ -84,43 +70,22 @@ int main() { _seg = 0; - -#ifdef USE_LIB - gpio_exp.configure(0x0000); // Set all pins: output -#else + char buf[3]; buf[0] = 0x06; // CONFIG buf[1] = 0; // output buf[2] = 0; // output gpio_exp.write(0x40, buf, 3); -#endif + wait(0.5); - tick.attach(&update, 0.005); // 5msec - - //pc.printf("PCAL9555 test program\n"); + tick.attach(&update, 0.01); // 10 msec int cnt = 0; while(1) { write_number(cnt++); - wait(0.1); + wait(0.1); // 100ms } } void error(const char* format, ...) { } - -#else - -DigitalOut led(LED1); - -int main() -{ - printf("hello\n"); - - while(1) { - led = !led; - wait(0.3); - } -} - -#endif