本文整理匯總了Java中com.pi4j.io.gpio.GpioPinDigitalOutput類的典型用法代碼示例。如果您正苦於以下問題:Java GpioPinDigitalOutput類的具體用法?Java GpioPinDigitalOutput怎麽用?Java GpioPinDigitalOutput使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GpioPinDigitalOutput類屬於com.pi4j.io.gpio包,在下文中一共展示了GpioPinDigitalOutput類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
public static void main(String[] args) {
System.out.println("<--Pi4J--> GPIO Frequency Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// provision gpio pin #01 as an output pin and turn on
final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, PinState.LOW);
// continuous loop
while(true) {
pin.setState(true);
pin.setState(false);
}
// 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(); <--- implement this method call if you wish to terminate the Pi4J GPIO controller
}
示例2: getNextOutput
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
public GpioPinDigitalOutput getNextOutput() {
// No pins are left
if (this.availablePins.isEmpty()) {
return null;
}
NamedPin temp = this.availablePins.get(0);
this.assignedPins.add(temp);
this.availablePins.remove(temp);
GpioPinDigitalOutput result;
if(temp.provider != null){
result = this.gpio.provisionDigitalOutputPin(temp.provider, temp.pin, PinState.LOW);
} else {
result = this.gpio.provisionDigitalOutputPin(temp.pin, PinState.LOW);
}
return result;
}
示例3: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
public static void main(String[] args) {
System.out.println("<--Pi4J--> GPIO Frequency Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// provision gpio pin #01 as an output pin and turn on
final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, PinState.LOW);
// continuous loop
while(true) {
pin.setState(true);
pin.setState(false);
}
// 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(); <--- implement this method call if you wish to terminate the Pi4J GPIO controller
}
示例4: sendPowerPinSwitch
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
private boolean sendPowerPinSwitch(MessageParsedInfo messageParsedInfo) {
int pinNum = (Integer)messageParsedInfo.getParsedValues()[0];
int power = (Integer)messageParsedInfo.getParsedValues()[1];
GpioPinDigitalOutput pin = (GpioPinDigitalOutput)getPin(pinNum);
pin.setMode(PinMode.DIGITAL_OUTPUT);
if(power == IProtocol.LOW) {
pin.low();
} else {
pin.high();
}
return true;
}
示例5: getDevice
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
@Override
public Device getDevice(int index) {
if (index != 0) {
throw new DeviceException("");
}
GpioPinDigitalOutput[] digitalOutput = new GpioPinDigitalOutput[8];
digitalOutput[0] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00,
"D0", PinState.LOW);
digitalOutput[1] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01,
"D1", PinState.LOW);
digitalOutput[2] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02,
"D2", PinState.LOW);
digitalOutput[3] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03,
"D3", PinState.LOW);
digitalOutput[4] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04,
"D4", PinState.LOW);
digitalOutput[5] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05,
"D5", PinState.LOW);
digitalOutput[6] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06,
"D6", PinState.LOW);
digitalOutput[7] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_07,
"D7", PinState.LOW);
return null;
}
示例6: testSecondAction
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
@Test
public void testSecondAction() {
GpioPinDigitalOutput pinIo = mock(GpioPinDigitalOutput.class);
when(mGpioController.provisionDigitalOutputPin(Pins.GPIO_PIN[23],
PinState.LOW)).thenReturn(pinIo);
mRelayController.switchRelay(2, true);
mRelayController.switchRelay(2, false);
mRelayController.switchRelay(2, true);
mRelayController.switchRelay(2, false);
// The first provisioning will set it high, so we only expect setState with LOW to be called
// once. NOTE: HIGH is active, LOW is de-active.
verify(pinIo, times(2)).setState(PinState.HIGH);
verify(pinIo, times(1)).setState(PinState.LOW);
}
示例7: testPinProvisionedOnce
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
@Test
public void testPinProvisionedOnce() {
GpioPinDigitalOutput pinIo = mock(GpioPinDigitalOutput.class);
when(mGpioController.provisionDigitalOutputPin(Pins.GPIO_PIN[3],
PinState.LOW)).thenReturn(pinIo);
mRelayController.switchRelay(0, true);
mRelayController.switchRelay(0, false);
mRelayController.switchRelay(0, true);
mRelayController.switchRelay(0, false);
// Pin should only be provisioned once.
verify(mGpioController, times(1)).provisionDigitalOutputPin(eq(Pins.GPIO_PIN[3]),
any(PinState.class));
// No other pin should be provisioned
verify(mGpioController, never()).provisionDigitalOutputPin(Pins.GPIO_PIN[11], PinState.LOW);
verify(mGpioController, never()).provisionDigitalOutputPin(Pins.GPIO_PIN[23], PinState.LOW);
verify(mGpioController, never()).provisionDigitalOutputPin(Pins.GPIO_PIN[27], PinState.LOW);
}
示例8: testClickAlreadyOnRelayNoOp
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
@Test
public void testClickAlreadyOnRelayNoOp() {
mRelayController = new RelayControllerImpl(new int[]{3}, mGpioController, 0 /*clickDelay*/);
GpioPinDigitalOutput pinIo = mock(GpioPinDigitalOutput.class);
when(mGpioController.provisionDigitalOutputPin(Pins.GPIO_PIN[3],
PinState.LOW)).thenReturn(pinIo);
mRelayController.switchRelay(0, true);
when(pinIo.isLow()).thenReturn(true);
mRelayController.clickRelay(0);
mRelayController.clickRelay(0);
mRelayController.clickRelay(0);
// Should never we called since clickRelay is a no-op and switchRelay will only provision the
// pin.
verify(pinIo, never()).setState(any(PinState.class));
}
示例9: write
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
@Override
public Integer write(Integer endereco, Integer comando) {
Integer resultante = null;
GpioPinDigitalOutput pino = (GpioPinDigitalOutput) this.pinos.get(endereco);
switch(comando){
case 1:
pino.high();
resultante = 1;
break;
case 0:
pino.low();
resultante = 0;
break;
case 2:
pino.toggle();
if(pino.isHigh()){
resultante = 1;
}else{
resultante = 0;
}
break;
}
return resultante;
}
示例10: piInitialseGPIO
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
/**
* Intialises the GPIO ports to be linked to fixed GPIO pins
*/
private void piInitialseGPIO() {
/* create gpio controller */
opin = new ArrayList<GpioPinDigitalOutput>();
opin.add(gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "MyLED", PinState.LOW));
opin.add(gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02, "MyLED", PinState.LOW));
opin.add(gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03, "MyLED", PinState.LOW));
opin.add(gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, "MyLED", PinState.LOW));
opin.add(gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05, "MyLED", PinState.LOW));
opin.add(gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06, "MyLED", PinState.LOW));
opin.add(gpio.provisionDigitalOutputPin(RaspiPin.GPIO_07, "MyLED", PinState.LOW));
opin.add(gpio.provisionDigitalOutputPin(RaspiPin.GPIO_08, "MyLED", PinState.LOW));
opin.add(gpio.provisionDigitalOutputPin(RaspiPin.GPIO_09, "MyLED", PinState.LOW));
opin.add(gpio.provisionDigitalOutputPin(RaspiPin.GPIO_10, "MyLED", PinState.LOW));
}
示例11: LedManager
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
/**
* Constructor of class.
*
* @param pin1
* Pin for first line of led.
* @param pin2
* Pin for second line of led.
* @param pin3
* Pin for third line of led.
*/
public LedManager(Pin pin1, Pin pin2, Pin pin3) {
GpioController gpio = GpioFactory.getInstance();
this.pin1 = gpio.provisionDigitalOutputPin(pin1, "MyLED", PinState.LOW);
this.pin2 = gpio.provisionDigitalOutputPin(pin2, "MyLED", PinState.LOW);
this.pin3 = gpio.provisionDigitalOutputPin(pin3, "MyLED", PinState.LOW);
List<GpioPinDigitalOutput> gpioLed = new ArrayList<GpioPinDigitalOutput>();
gpioLed.add(this.pin1);
gpioLed.add(this.pin2);
gpioLed.add(this.pin3);
ledBlinking = new LedBlinking(gpioLed);
}
示例12: run
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
@Override
public void run() {
while (!stopThread) {
for (GpioPinDigitalOutput led : listLed) {
if (ledStatus) {
led.high();
} else {
led.low();
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
ledStatus = !ledStatus;
}
stopThread = false;
}
示例13: internalReceiveCommand
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
/**
* @{inheritDoc}
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
// the code being executed when a command was sent on the openHAB
// event bus goes here. This method is only called if one of the
// BindingProviders provide a binding for the given 'itemName'.
logger.debug("internalReceiveCommand({},{}) is called!", itemName, command);
// the configuration is guaranteed not to be null, because the component
// definition has the configuration-policy set to require. If set to
// 'optional' then the configuration may be null
if (command instanceof OnOffType) {
final OnOffType switchCommand = (OnOffType) command;
for (MCP23017BindingProvider provider : this.providers) {
if (provider.providesBindingFor(itemName)) {
GpioPin pin = gpioPins.get(itemName);
if (switchCommand == OnOffType.OFF) {
gpio.setState(PinState.LOW, (GpioPinDigitalOutput) pin);
} else if (switchCommand == OnOffType.ON) {
gpio.setState(PinState.HIGH, (GpioPinDigitalOutput) pin);
}
}
}
}
}
示例14: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Cylon Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// provision gpio pin #01 as an output pin and turn on
final GpioPinDigitalOutput[] pins = {
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_07, PinState.LOW)};
System.out.println("--> GPIO state should be: ON");
// set shutdown options on all pins
gpio.setShutdownOptions(true, PinState.LOW, pins);
// infinite loop
while(true) {
for(int index = 0; index <= 6; index++) {
pins[index].pulse(50);
Thread.sleep(50);
}
for(int index = 6; index >= 0; index--) {
pins[index].pulse(50);
Thread.sleep(50);
}
}
// 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(); <--- implement this method call if you wish to terminate the Pi4J GPIO controller
}
示例15: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入依賴的package包/類
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Blink Trigger Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// provision gpio pin #02 as an input pin with its internal pull down resistor enabled
final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02,
PinPullResistance.PULL_DOWN);
System.out.println(" ... complete the GPIO #02 circuit and see the blink trigger take effect.");
// setup gpio pins #04 an output pins and make sure they are all LOW at startup
final GpioPinDigitalOutput myLed = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, PinState.LOW);
// create a gpio control trigger on the input pin ; when the input goes HIGH, turn on blinking
myButton.addTrigger(new GpioBlinkStateTrigger(PinState.HIGH, myLed, 250));
// create a gpio control trigger on the input pin ; when the input goes LOW, turn off blinking
myButton.addTrigger(new GpioBlinkStopStateTrigger(PinState.LOW, myLed));
// keep program running until user aborts (CTRL-C)
while(true) {
Thread.sleep(500);
}
// 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(); <--- implement this method call if you wish to terminate the Pi4J GPIO controller
}