本文整理汇总了Java中com.pi4j.gpio.extension.mcp.MCP23017GpioProvider类的典型用法代码示例。如果您正苦于以下问题:Java MCP23017GpioProvider类的具体用法?Java MCP23017GpioProvider怎么用?Java MCP23017GpioProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MCP23017GpioProvider类属于com.pi4j.gpio.extension.mcp包,在下文中一共展示了MCP23017GpioProvider类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PumpDiagGuiSingle
import com.pi4j.gpio.extension.mcp.MCP23017GpioProvider; //导入依赖的package包/类
/**
* Creates new form MainWindow
*
* @throws com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException
* @throws java.io.IOException
*/
public PumpDiagGuiSingle() throws I2CFactory.UnsupportedBusNumberException, IOException, IOException, InterruptedException {
gpio = GpioFactory.getInstance(); // Singleton instance
mcpProvider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x23);
// Provision direction control pins as outputs
System.out.println("Provisioning direction pin");
dir = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A7, "Direction", PinState.LOW);
// Provision step control pins as outputs
System.out.println("Provisioning step pin");
step = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A6, "Step", PinState.LOW);
// Provision enable pins as outputs.
// Note that the pin state "high" means the pump is disabled;
// the enable pump on the chip is inverted.
System.out.println("Provisioning enable pin");
enable = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A5, "~Enable", PinState.HIGH);
}
示例2: McpOutputController
import com.pi4j.gpio.extension.mcp.MCP23017GpioProvider; //导入依赖的package包/类
public McpOutputController(int addr) {
// Basic required setup
this.gpioCtrl = GpioFactory.getInstance();
try {
this.provider = new MCP23017GpioProvider(I2CBus.BUS_1, addr);
} catch (I2CFactory.UnsupportedBusNumberException | IOException ex) {
Logger.getLogger(McpOutputController.class.getName()).log(Level.SEVERE, null, ex);
}
// Initialize all pins to output
this.initPins();
}
示例3: addMcp
import com.pi4j.gpio.extension.mcp.MCP23017GpioProvider; //导入依赖的package包/类
/**
* Add a new MCP23017 GPIO expander chip to the manager. This allows the
* assignment of 16 additional GPIO pins.
*
* Note that each chip assigned must have a different address.
*
* @param address The I2C address of the chip, in the range 0x20 to 0x27
* @throws I2CFactory.UnsupportedBusNumberException If the bus # is invalid.
* @throws IOException If the chip can't be communicated with.
*/
public void addMcp(int bus, int address)
throws I2CFactory.UnsupportedBusNumberException, IOException {
GpioProvider provider = new MCP23017GpioProvider(bus, address);
for (Pin mcpPin : MCP23017Pin.ALL) {
String name = mcpPin.getName() + " " + Integer.toHexString(address);
NamedPin newPin = new NamedPin(name, mcpPin, provider);
this.availablePins.add(newPin);
}
}
示例4: getMCP23017Provider
import com.pi4j.gpio.extension.mcp.MCP23017GpioProvider; //导入依赖的package包/类
public GpioProvider getMCP23017Provider(int address) {
try {
return new MCP23017GpioProvider(newRasPI() ? I2CBus.BUS_1 : I2CBus.BUS_0, address);
} catch (IOException | UnsatisfiedLinkError e) {
LOG.error("Unable to locate MCP23017 at address " + String.format("0x%x", address) + ", using default provider instead.", e);
return gpio().getDefaultProvider();
}
}
示例5: main
import com.pi4j.gpio.extension.mcp.MCP23017GpioProvider; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> MCP23017 GPIO Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom MCP23017 GPIO provider
final MCP23017GpioProvider provider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x21);
// provision gpio input pins from MCP23017
GpioPinDigitalInput myInputs[] = {
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A0, "MyInput-A0", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A1, "MyInput-A1", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A2, "MyInput-A2", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A3, "MyInput-A3", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A4, "MyInput-A4", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A5, "MyInput-A5", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A6, "MyInput-A6", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A7, "MyInput-A7", PinPullResistance.PULL_UP),
};
// create and register gpio pin listener
gpio.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = "
+ event.getState());
}
}, myInputs);
// provision gpio output pins and make sure they are all LOW at startup
GpioPinDigitalOutput myOutputs[] = {
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B0, "MyOutput-B0", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B1, "MyOutput-B1", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B2, "MyOutput-B2", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B3, "MyOutput-B3", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B4, "MyOutput-B4", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B5, "MyOutput-B5", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B6, "MyOutput-B6", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B7, "MyOutput-B7", PinState.LOW)
};
// keep program running for 20 seconds
for (int count = 0; count < 10; count++) {
gpio.setState(true, myOutputs);
Thread.sleep(1000);
gpio.setState(false, myOutputs);
Thread.sleep(1000);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("Exiting MCP23017GpioExample");
}
示例6: MCP23017_Control
import com.pi4j.gpio.extension.mcp.MCP23017GpioProvider; //导入依赖的package包/类
public MCP23017_Control(int address) throws UnsupportedBusNumberException, IOException {
this.gpio = GpioFactory.getInstance();
this.provider = new MCP23017GpioProvider(I2CBus.BUS_1, address);
}
示例7: main
import com.pi4j.gpio.extension.mcp.MCP23017GpioProvider; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> MCP23017 GPIO Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom MCP23017 GPIO provider
final MCP23017GpioProvider provider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x20);
// provision gpio input pins from MCP23017
GpioPinDigitalInput myInputs[] = {
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A0, "MyInput-A0", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A1, "MyInput-A1", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A2, "MyInput-A2", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A3, "MyInput-A3", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A4, "MyInput-A4", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A5, "MyInput-A5", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A6, "MyInput-A6", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A7, "MyInput-A7", PinPullResistance.OFF),
};
// create and register gpio pin listener
gpio.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = "
+ event.getState());
}
}, myInputs);
// provision gpio output pins and make sure they are all LOW at startup
GpioPinDigitalOutput myOutputs[] = {
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B0, "MyOutput-B0", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B1, "MyOutput-B1", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B2, "MyOutput-B2", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B3, "MyOutput-B3", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B4, "MyOutput-B4", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B5, "MyOutput-B5", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B6, "MyOutput-B6", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B7, "MyOutput-B7", PinState.LOW)
};
// keep program running for 20 seconds
for (int count = 0; count < 1000; count++) {
gpio.setState(true, myOutputs);
Thread.sleep(1000);
gpio.setState(false, myOutputs);
Thread.sleep(1000);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("Exiting MCP23017GpioExample");
}
示例8: PumpDiagGui
import com.pi4j.gpio.extension.mcp.MCP23017GpioProvider; //导入依赖的package包/类
/**
* Creates new form MainWindow
* @throws com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException
* @throws java.io.IOException
*/
public PumpDiagGui() throws I2CFactory.UnsupportedBusNumberException, IOException, IOException {
gpio = GpioFactory.getInstance(); // Singleton instance
mcpProviderOne = new MCP23017GpioProvider(I2CBus.BUS_1, 0x27);
//mcpProviderTwo = new MCP23017GpioProvider(I2CBus.BUS_1, 0x23);
// Provision direction control pins as outputs
GpioPinDigitalOutput dir1 = gpio.provisionDigitalOutputPin(mcpProviderOne, MCP23017Pin.GPIO_A7, "Pump 1 Direction", PinState.LOW);
GpioPinDigitalOutput dir2 = gpio.provisionDigitalOutputPin(mcpProviderOne, MCP23017Pin.GPIO_B0, "Pump 2 Direction", PinState.LOW);
GpioPinDigitalOutput dir3 = gpio.provisionDigitalOutputPin(mcpProviderOne, MCP23017Pin.GPIO_A4, "Pump 3 Direction", PinState.LOW);
// Provision step control pins as outputs
GpioPinDigitalOutput step1 = gpio.provisionDigitalOutputPin(mcpProviderOne, MCP23017Pin.GPIO_A6, "Pump 1 Step", PinState.LOW);
GpioPinDigitalOutput step2 = gpio.provisionDigitalOutputPin(mcpProviderOne, MCP23017Pin.GPIO_B1, "Pump 2 Step", PinState.LOW);
GpioPinDigitalOutput step3 = gpio.provisionDigitalOutputPin(mcpProviderOne, MCP23017Pin.GPIO_A3, "Pump 3 Step", PinState.LOW);
// Provision enable pins as outputs.
// Note that the pin state "high" means the pump is disabled;
// the enable pump on the chip is inverted.
GpioPinDigitalOutput enable1 = gpio.provisionDigitalOutputPin(mcpProviderOne, MCP23017Pin.GPIO_A5, "Pump 1 ~Enable", PinState.HIGH);
GpioPinDigitalOutput enable2 = gpio.provisionDigitalOutputPin(mcpProviderOne, MCP23017Pin.GPIO_B7, "Pump 2 ~Enable", PinState.HIGH);
GpioPinDigitalOutput enable3 = gpio.provisionDigitalOutputPin(mcpProviderOne, MCP23017Pin.GPIO_A2, "Pump 3 ~Enable", PinState.HIGH);
// Provision end-stop pins as inputs.
// These pins tell the pump when the syringe
// is in its MINIMUM possible position (empty).
GpioPinDigitalInput min1 = gpio.provisionDigitalInputPin(RaspiPin.GPIO_07, "Pump 1 Min (BCM 4)", PinPullResistance.PULL_UP);
GpioPinDigitalInput min2 = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, "Pump 2 Min (BCM 17)", PinPullResistance.PULL_UP);
GpioPinDigitalInput min3 = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02, "Pump 3 Min (BCM 27)", PinPullResistance.PULL_UP);
// Provision end-stop pins as inputs.
// These pins tell the pump when the syringe
// is in its MAXIMUM possible position (full).
GpioPinDigitalInput max1 = gpio.provisionDigitalInputPin(RaspiPin.GPIO_27, "Pump 1 Max (BCM 16)", PinPullResistance.PULL_UP);
GpioPinDigitalInput max2 = gpio.provisionDigitalInputPin(RaspiPin.GPIO_28, "Pump 2 Max (BCM 20)", PinPullResistance.PULL_UP);
GpioPinDigitalInput max3 = gpio.provisionDigitalInputPin(RaspiPin.GPIO_29, "Pump 3 Max (BCM 21)", PinPullResistance.PULL_UP);
pump1 = new SyringePump(step1, dir1, enable1, min1, max1);
pump2 = new SyringePump(step2, dir2, enable2, min2, max2);
pump3 = new SyringePump(step3, dir3, enable3, min3, max3);
pump1.setStepDelay(1);
pump2.setStepDelay(1);
pump3.setStepDelay(1);
initComponents();
}
示例9: main
import com.pi4j.gpio.extension.mcp.MCP23017GpioProvider; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, IOException {
System.out.println("<--Pi4J--> MCP23017 GPIO Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom MCP23017 GPIO provider
final MCP23017GpioProvider gpioProvider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x21);
// provision gpio input pins from MCP23017
GpioPinDigitalInput myInputs[] = {
gpio.provisionDigitalInputPin(gpioProvider, MCP23017Pin.GPIO_A0, "MyInput-A0", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(gpioProvider, MCP23017Pin.GPIO_A1, "MyInput-A1", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(gpioProvider, MCP23017Pin.GPIO_A2, "MyInput-A2", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(gpioProvider, MCP23017Pin.GPIO_A3, "MyInput-A3", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(gpioProvider, MCP23017Pin.GPIO_A4, "MyInput-A4", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(gpioProvider, MCP23017Pin.GPIO_A5, "MyInput-A5", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(gpioProvider, MCP23017Pin.GPIO_A6, "MyInput-A6", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(gpioProvider, MCP23017Pin.GPIO_A7, "MyInput-A7", PinPullResistance.PULL_UP),
};
// create and register gpio pin listener
gpio.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = "
+ event.getState());
}
}, myInputs);
// provision gpio output pins and make sure they are all LOW at startup
GpioPinDigitalOutput myOutputs[] = {
gpio.provisionDigitalOutputPin(gpioProvider, MCP23017Pin.GPIO_B0, "MyOutput-B0", PinState.LOW),
gpio.provisionDigitalOutputPin(gpioProvider, MCP23017Pin.GPIO_B1, "MyOutput-B1", PinState.LOW),
gpio.provisionDigitalOutputPin(gpioProvider, MCP23017Pin.GPIO_B2, "MyOutput-B2", PinState.LOW),
gpio.provisionDigitalOutputPin(gpioProvider, MCP23017Pin.GPIO_B3, "MyOutput-B3", PinState.LOW),
gpio.provisionDigitalOutputPin(gpioProvider, MCP23017Pin.GPIO_B4, "MyOutput-B4", PinState.LOW),
gpio.provisionDigitalOutputPin(gpioProvider, MCP23017Pin.GPIO_B5, "MyOutput-B5", PinState.LOW),
gpio.provisionDigitalOutputPin(gpioProvider, MCP23017Pin.GPIO_B6, "MyOutput-B6", PinState.LOW),
gpio.provisionDigitalOutputPin(gpioProvider, MCP23017Pin.GPIO_B7, "MyOutput-B7", PinState.LOW)
};
// keep program running for 20 seconds
for (int count = 0; count < 10; count++) {
gpio.setState(true, myOutputs);
Thread.sleep(1000);
gpio.setState(false, myOutputs);
Thread.sleep(1000);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
}
示例10: Mcp23017PinStateHolder
import com.pi4j.gpio.extension.mcp.MCP23017GpioProvider; //导入依赖的package包/类
public Mcp23017PinStateHolder(MCP23017GpioProvider mcpProvider, Thing thing) {
this.mcpProvider = mcpProvider;
this.thing = thing;
}