Hardware Reference
In-Depth Information
Wire.write(_chip0Output);
Wire.endTransmission();
delay(5);
Wire.beginTransmission(_chip1Address);
_chip1Output = ((uint8_t) ((data) >> 8));
Wire.write(_chip1Output);
Wire.endTransmission();
return true;
}
By now you should be accustomed to using both chips. The logic behind
this is that both variables are updated, and both chips are updated with those
variables. The trick comes in separating a word into 2 bytes; this is done with
masks and shifts. The i rst conversion transforms a word into a byte, by omit-
ting the i rst 8 bits using a mask. The second conversion does the same; only it
shifts the i rst 8 bits to the right, essentially pushing the i rst 8 bits to the place
of the second 8 bits, and then masking.
The last function that you need is writing individual bits:
bool PCF8574AP::writeBit(bool bit, uint8_t pos)
{
// Is the bit requested out of range?
if (pos > 15)
return false;
if (pos < 8)
{
//Chip 0
if (bit == true)
{
bitSet(_chip0Output, pos);
}
else
{
bitClear(_chip0Output, pos);
}
Wire.beginTransmission(_chip0Address);
Wire.write(_chip0Output);
Wire.endTransmission();
}
else
{
//Chip 1
if (bit == true)
{
bitSet(_chip1Output, pos - 8);
}
Search WWH ::




Custom Search