java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.internal.MCP23008
Class to provide IO interfacing with MCP23008
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkPinNumber
(int bit) Checks a bit is in Range of 0-7.byte
Returns the created gpio state byte for the mcpcom.pi4j.io.i2c.I2C
getI2C()
Returns the created i2c instance for the mcpvoid
initializeIo
(byte ioConfiguration) Configure the IO's of the MCP23008.void
pulsePin
(int bit, int pulseWidth) Pulse a IO Pinvoid
setAndWritePin
(int bit, boolean state) Set a Pin an directly write it out to the hardwarevoid
setPin
(int bit, boolean state) Set the state of a pin to high or low.void
Write the Buffer out to the PinsMethods inherited from class com.pi4j.crowpi.components.Component
sleep, triggerSimpleEvent
-
Field Details
-
gpioState
protected byte gpioStateCurrent 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 contextbus
- Custom I2C bus addressdevice
- 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 PinpulseWidth
- 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 Pinstate
- 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 Pinstate
- 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
-