本文整理匯總了Java中com.pi4j.io.gpio.GpioController.provisionDigitalOutputPin方法的典型用法代碼示例。如果您正苦於以下問題:Java GpioController.provisionDigitalOutputPin方法的具體用法?Java GpioController.provisionDigitalOutputPin怎麽用?Java GpioController.provisionDigitalOutputPin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.pi4j.io.gpio.GpioController
的用法示例。
在下文中一共展示了GpioController.provisionDigitalOutputPin方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.pi4j.io.gpio.GpioController; //導入方法依賴的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: Led
import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
/**
* Constructs a led with its number
* @param ledNb the led number (1 or 2)
*/
protected Led(int ledNb) {
GpioController gpio = GpioFactory.getInstance();
// provision the corresponding gpio pin as an output pin
// and make sure it is set to LOW at startup
if(ledNb == 1) {
ledOutputPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "led1", PinState.LOW);
} else {
ledOutputPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02, "led2", PinState.LOW);
}
// configure the pin shutdown behavior; these settings will be
// automatically applied to the pin when the application is terminated
// ensure that the LED is turned OFF when the application is shutdown
ledOutputPin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
}
示例3: start
import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
@Override
public void start() {
GpioController gpioController = getGpioController();
if(gpioController != null) {
try {
outputPin = gpioController.provisionDigitalOutputPin(getGpio(), adjustState(PinState.LOW));
logger.info("{}: Switch uses {} reverseStates={}", getApplianceId(), getGpio(), reverseStates);
}
catch(Exception e) {
logger.error("{}: Error starting {} for {}", getApplianceId(), getClass().getSimpleName(), getGpio(), e);
}
}
else {
logGpioAccessDisabled();
}
}
示例4: initializeIO
import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public void initializeIO() {
GpioController controller = GpioFactory.getInstance();
m_controlPin = controller.provisionDigitalOutputPin(
PinTable2.get(controlPin), PinStateTable2.get(controlPinState));
m_statePin = controller.provisionDigitalInputPin(
PinTable2.get(statePin),
PinPullResistanceTable2.get(statePinResistance));
m_statePin.addListener(m_stateListener);
if (m_statePin.isHigh())
m_doorState = doorStateEnum.CLOSED;
else
m_doorState = doorStateEnum.OPEN;
}
示例5: LedManager
import com.pi4j.io.gpio.GpioController; //導入方法依賴的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);
}
示例6: main
import com.pi4j.io.gpio.GpioController; //導入方法依賴的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
}
示例7: main
import com.pi4j.io.gpio.GpioController; //導入方法依賴的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
}
示例8: main
import com.pi4j.io.gpio.GpioController; //導入方法依賴的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
}
示例9: main
import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Shutdown 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.HIGH);
// configure the pin shutdown behavior; these settings will be
// automatically applied to the pin when the application is terminated
pin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
System.out.println("--> GPIO state should be: ON");
System.out.println(" This program will automatically terminate in 10 seconds,");
System.out.println(" or you can use the CTRL-C keystroke to terminate at any time.");
System.out.println(" When the program terminates, the GPIO state should be shutdown and set to: OFF");
// wait 10 seconds
Thread.sleep(10000);
System.out.println(" .. shutting down now ...");
// 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 ShutdownGpioExample");
}
示例10: main
import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Control 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, "MyLED", PinState.HIGH);
// set shutdown state for this pin
pin.setShutdownOptions(true, PinState.LOW);
System.out.println("--> GPIO state should be: ON");
Thread.sleep(10);
// turn off gpio pin #01
pin.low();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(10);
for(int i=0;i<200;i++)
{
pin.toggle();
Thread.sleep(10);
pin.toggle();
Thread.sleep(10);
}
// 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 MotorControl");
}
示例11: MFRC522
import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public MFRC522(GpioController gpio,Pin pinNRSTPD,SpiChannel channel) throws IOException {
this.pinNRSTPD = pinNRSTPD;
this.spiChannel = channel;
spi = SpiFactory.getInstance(spiChannel,
SpiDevice.DEFAULT_SPI_SPEED, // default spi speed 1 MHz
SpiDevice.DEFAULT_SPI_MODE); // default spi mode 0
rstOut = gpio.provisionDigitalOutputPin(pinNRSTPD, "RC522RST");
rstOut.setShutdownOptions(true, PinState.HIGH, PinPullResistance.OFF);
rstOut.high();
init();
}
示例12: main
import com.pi4j.io.gpio.GpioController; //導入方法依賴的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)
for (;;) {
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
}
示例13: main
import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Shutdown 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.HIGH);
// configure the pin shutdown behavior; these settings will be
// automatically applied to the pin when the application is terminated
pin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
System.out.println("--> GPIO state should be: ON");
System.out.println(" This program will automatically terminate in 10 seconds,");
System.out.println(" or you can use the CTRL-C keystroke to terminate at any time.");
System.out.println(" When the program terminates, the GPIO state should be shutdown and set to: OFF");
// wait 10 seconds
Thread.sleep(10000);
System.out.println(" .. shutting down now ...");
// 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();
}
示例14: main
import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Control 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, "MyLED", PinState.HIGH);
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// turn off gpio pin #01
pin.low();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
// toggle the current state of gpio pin #01 (should turn on)
pin.toggle();
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// toggle the current state of gpio pin #01 (should turn off)
pin.toggle();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
// turn on gpio pin #01 for 1 second and then off
System.out.println("--> GPIO state should be: ON for only 1 second");
pin.pulse(1000, true); // set second argument to 'true' use a blocking call
// 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();
}
示例15: main
import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
@Test
public void main() throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Shutdown 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.HIGH);
// configure the pin shutdown behavior; these settings will be
// automatically applied to the pin when the application is terminated
pin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
System.out.println("--> GPIO state should be: ON");
System.out.println(" This program will automatically terminate in 10 seconds,");
System.out.println(" or you can use the CTRL-C keystroke to terminate at any time.");
System.out.println(" When the program terminates, the GPIO state should be shutdown and set to: OFF");
// wait 10 seconds
Thread.sleep(10000);
System.out.println(" .. shutting down now ...");
// 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();
}