Class MCP23008

java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.internal.MCP23008

public class MCP23008 extends Component
Class to provide IO interfacing with MCP23008
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected byte
    Current IO States of the MCP23008

    Fields inherited from class com.pi4j.crowpi.components.Component

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
    MCP23008(com.pi4j.context.Context pi4j)
    Creates a new MCP using the default setup.
    MCP23008(com.pi4j.context.Context pi4j, int bus, int device)
    Creates a new MCP with custom bus, device address
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    checkPinNumber(int bit)
    Checks a bit is in Range of 0-7.
    byte
    Returns the created gpio state byte for the mcp
    com.pi4j.io.i2c.I2C
    Returns the created i2c instance for the mcp
    void
    initializeIo(byte ioConfiguration)
    Configure the IO's of the MCP23008.
    void
    pulsePin(int bit, int pulseWidth)
    Pulse a IO Pin
    void
    setAndWritePin(int bit, boolean state)
    Set a Pin an directly write it out to the hardware
    void
    setPin(int bit, boolean state)
    Set the state of a pin to high or low.
    void
    Write the Buffer out to the Pins

    Methods inherited from class com.pi4j.crowpi.components.Component

    sleep, triggerSimpleEvent

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • gpioState

      protected byte gpioState
      Current IO States of the MCP23008
  • Constructor Details

    • MCP23008

      public MCP23008(com.pi4j.context.Context pi4j)
      Creates a new MCP using the default setup.
      Parameters:
      pi4j - Pi4J context
    • MCP23008

      public MCP23008(com.pi4j.context.Context pi4j, int bus, int device)
      Creates a new MCP with custom bus, device address
      Parameters:
      pi4j - Pi4J context
      bus - Custom I2C bus address
      device - Custom device address on I2C
  • Method Details

    • initializeIo

      public void initializeIo(byte ioConfiguration)
      Configure the IO's of the MCP23008. Every bit of the input byte represents one of the IO PIN. 0 = Output, 1 = Input
      Parameters:
      ioConfiguration - Configure the Pin's of the MCP as Input (1) or Output(0)
    • pulsePin

      public void pulsePin(int bit, int pulseWidth)
      Pulse a IO Pin
      Parameters:
      bit - Number of the Pin
      pulseWidth - Time to Pulse the Output in Millis
    • setPin

      public void setPin(int bit, boolean state)
      Set the state of a pin to high or low. Pin needs manually write out to the hardware after setting
      Parameters:
      bit - Number of the Pin
      state - Set the Pin to this state
    • setAndWritePin

      public void setAndWritePin(int bit, boolean state)
      Set a Pin an directly write it out to the hardware
      Parameters:
      bit - Number of the Pin
      state - State which the Pin is set and written to
    • writePins

      public void writePins()
      Write the Buffer out to the Pins
    • checkPinNumber

      protected void checkPinNumber(int bit)
      Checks a bit is in Range of 0-7. So it is an IO Pin
      Parameters:
      bit - Number to check
    • getI2C

      public com.pi4j.io.i2c.I2C getI2C()
      Returns the created i2c instance for the mcp
      Returns:
      I2C instance
    • getGpioState

      public byte getGpioState()
      Returns the created gpio state byte for the mcp
      Returns:
      I2C instance