Hardware Reference
In-Depth Information
few LEDs on their desk with the corresponding resistors. They might not have
16, so this example uses only one output, with 8 LEDs.
#include <Wire.h>
#include <PCF8574AP.h>
// Define the addresses of both chips on the expander board
#define EXPANDER_CHIP0 B0111000
#define EXPANDER_CHIP1 B0111001
// You must provide two I2C addresses, one for each chip on the shield
PCF8574AP expanderShield = PCF8574AP(EXPANDER_CHIP0, EXPANDER_CHIP1);
byte output;
void setup()
{
Serial.begin(9600);
expanderShield.begin(); // Start the expander shield, set all outputs
to 1
}
void loop()
{
// Write a 16-bit word to the expander shield, all ones
expanderShield.writeWord(0xFFFF);
delay(1000);
// Time to begin the light show
// Make the lights go towards the center by writing bytes
expanderShield.writeByte(B01111110, 0);
delay(1000);
expanderShield.writeByte(B00111100, 0);
delay(1000);
expanderShield.writeByte(B00011000, 0);
delay(1000);
expanderShield.writeByte(B00000000, 0);
delay(1000);
// Now make the lights go towards the edges by writing individual bits
// Bits can be set by writing a 1 or a 0 to a specific location: bits
0 to 15
expanderShield.writeBit(1, 0); // Write a logical 1 to bit 0 of the
expander shield
expanderShield.writeBit(1, 7); // Write a logical 1 to bit 7 of the
expander shield
delay(1000);
expanderShield.writeBit(1, 1);
Search WWH ::




Custom Search