/* Example to blink 8 leds like Knight-Rider connectet to a PCF8574(A) i2c port expander. */ #include #include #include #include #include #define PCF8574 0x20 /* PCF 8574, A0,A1,A2 = low */ #define wait 5 /* 100ms per led */ int i2c; char buf[1]; int mysleep( unsigned int s) /* my own sleep */ { /* usleep waits only 20ms */ unsigned int i; /* and ignore the parameter */ for (i=0;i 0 ) { ioctl(i2c,I2C_SLAVE, PCF8574); /* set the i2c chip address */ for (count=0;count<8;count++) { buf[0] = ~(1 << count); /* shift first bit forward and */ /* invert all for low activ outputs */ write(i2c,buf,1); /* write 1 byte to the deivce */ mysleep(wait); } for (count=0;count<8;count++) { buf[0] = ~(0x80 >> count); /* shift back */ write(i2c,buf,1); mysleep(wait); } } i2c = close(i2c); } return 0; }