Code: task main() { // I2C Byte pattern to set the digital IO pins for Input // Message Length: 3 Data: 02 4E 00 Return bytes: 0 byte msgSetDigitalIOPins[] = { 3, 2, 0x4E, 0 };
// I2C Byte pattern to read the digital 6 bit value // Message Length: 2 Data: 02 4C Return bytes: 1 byte msgReadDigitalValues[] = { 2, 2, 0x4C }; byte retBytes[8]; // return (reply) bytes
eraseDisplay(); SensorType[S1] = sensorI2CCustom; sendI2CMsg(S1, msgSetDigitalIOPins, 0); // Make sure all of the digital I/O pins are in INPUT mode.
while (nI2CStatus[S1] == STAT_COMM_PENDING) wait1Msec(2);
readI2CReply(S1, retBytes, 0);
while (true) { sendI2CMsg(S1, msgReadDigitalValues, 1);
while (nI2CStatus[S1] == STAT_COMM_PENDING) wait1Msec(2);
if (nI2CBytesReady[S1] == 1) { readI2CReply(S1, retBytes, 1);
nxtDisplayTextLine(1, "B: %d", (~retBytes[0]) & 0x01); nxtDisplayTextLine(2, "B: %d", (~retBytes[0]) & 0x02); nxtDisplayTextLine(3, "B: %d", (~retBytes[0]) & 0x04); nxtDisplayTextLine(4, "B: %d", (~retBytes[0]) & 0x08); nxtDisplayTextLine(5, "B: %d", (~retBytes[0]) & 0x10); nxtDisplayTextLine(6, "B: %d", (~retBytes[0]) & 0x20); } else nxtDisplayTextLine(2, "B: ERR"); } } |