Esempio n. 1
0
// ----------------------------------------------------- MCP23017 port expander
void cButtonPE16::begin( uint8_t N, uint8_t addr ) {
// need to know how many active buttons so we can mask off the unused
  n = max(N,4);
  mask = ( 1 << n ) - 1; // for the buttons
  nextCheck = millis() + PERIOD;
  sidx = 0;

  // configure the port expander
  PEaddr = addr;
  Wire.beginTransmission( PEaddr );
  Wire._WRITE( IOCONZ );  // valid command only if BANK = 0, which is true upon reset
  Wire._WRITE( BANK ); // set BANK = 1 if it had been 0 (nothing happens if BANK = 1 already)
  Wire.endTransmission();

  // now, send our IO control byte with assurance BANK = 1
  Wire.beginTransmission( PEaddr );
  Wire._WRITE( IOCON );
  Wire._WRITE( BANK | SEQOP | DISSLW ); //  banked operation, non-sequential addressing
  Wire.endTransmission();

  // now, set up port B pins for input
  Wire.beginTransmission( PEaddr );
  Wire._WRITE( IODIRB );
  Wire._WRITE( 0x0F ); // configure port B pins:  input 0-3, output 4-7
  Wire.endTransmission();

  // reverse the polarity (so that 0 = not pressed, 1 = pressed)
  Wire.beginTransmission( PEaddr );
  Wire._WRITE( IPOLB );
  Wire._WRITE( 0x0F ); // configure port B polarity: reversed 0-3, normal 4-7
  Wire.endTransmission();

  ledAllOff(); // all LED's off by default
}
boardIO::boardIO()
{
  ledAllOff();
}