Bubble display example using NXP PCAL9555A GPIO expander
Fork of PCAL9555_Hello by
main.cpp
- Committer:
- MACRUM
- Date:
- 2017-02-18
- Revision:
- 3:f74f521b2e46
- Parent:
- 2:ae0b95d42407
- Child:
- 4:0f3b252fb13f
File content as of revision 3:f74f521b2e46:
#pragma Ospace #include "mbed.h" #if 1 #ifdef USE_LIB #include "PCAL9555.h" #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; static int _seg; static int _chrs[4]; const char dispTabl[] = { 0x7E, // 0 0x30, // 1 0x6D, // 2 0x79, // 3 0x33, // 4 0x5B, // 5 0x5F, // 6 0x70, // 7 0x7F, // 8 0x7B, // 9 }; void update() { int port_0; int _data; _data = (dispTabl[_chrs[_seg]]); switch(_seg) { case 0: port_0 = 0x70; _seg = 1; break; case 1: port_0 = 0xb0; _seg = 2; break; case 2: port_0 = 0xd0; _seg = 3; break; case 3: port_0 = 0xe0; _seg = 0; 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 gpio_exp.write(0x40, buf, 3); #endif } void write_number(int num) { num %= 10000; _chrs[0] = (num/1000); _chrs[1] = ((num/100)%10); _chrs[2] = (((num/10)%100)%10); _chrs[3] = (((num%1000)%100)%10); } 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 tick.attach(&update, 0.005); // 5msec //pc.printf("PCAL9555 test program\n"); int cnt = 0; while(1) { write_number(cnt++); wait(0.1); } } void error(const char* format, ...) { } #else DigitalOut led(LED1); int main() { printf("hello\n"); while(1) { led = !led; wait(0.3); } } #endif