当前位置: 首页>>代码示例>>Java>>正文


Java GpioPinDigitalOutput.setShutdownOptions方法代码示例

本文整理汇总了Java中com.pi4j.io.gpio.GpioPinDigitalOutput.setShutdownOptions方法的典型用法代码示例。如果您正苦于以下问题:Java GpioPinDigitalOutput.setShutdownOptions方法的具体用法?Java GpioPinDigitalOutput.setShutdownOptions怎么用?Java GpioPinDigitalOutput.setShutdownOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.pi4j.io.gpio.GpioPinDigitalOutput的用法示例。


在下文中一共展示了GpioPinDigitalOutput.setShutdownOptions方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的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");
    }
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:31,代码来源:ShutdownGpioExample.java

示例2: main

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的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");
    }
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:38,代码来源:MotorControl.java

示例3: main

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的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();
}
 
开发者ID:iot-labs,项目名称:communication,代码行数:29,代码来源:ShutdownGpioExample.java

示例4: main

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的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();
 }
 
开发者ID:starksm64,项目名称:RaspberryPi,代码行数:30,代码来源:ShutdownGpioExample.java

示例5: defineButton

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
private void defineButton(Pin pin, String operation)
{
    GpioPinDigitalOutput button = gpio.provisionDigitalOutputPin(pin, operation, PinState.LOW);
    button.setShutdownOptions(true, PinState.LOW);

    buttons.put(operation, button);
}
 
开发者ID:Bendr0id,项目名称:shutter-control,代码行数:8,代码来源:ShutterControl.java

示例6: switchRelay

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
@Override
public synchronized void switchRelay(int num, boolean on) {
  if (num < 0 || num >= mMapping.length) {
    LOG.warn("Invalid relay number: " + num);
    return;
  }

  LOG.info("Switching relay" + num + " on? " + on);
  GpioPinDigitalOutput gpio = mActivePins.get(num);
  if (gpio != null) {
    // If we already initialize the pin, simply switch the state.
    gpio.setState(on ? PinState.LOW : PinState.HIGH);
    return;
  }

  // A relay is 'ON' when its pin is set to LOW. However, there is an issue if
  // we call provisionDigitalOutputPin with state HIGH to have the pin off as
  // it will very briefly switch it to LOW. This is not acceptable, since e.g.
  // we might accidentally open up a garage door when initializing the pins.
  // This is why we don't provision the pin here until we need it.

  if (!on) {
    // If a pin has not been provisioned yet and is supposed to be switched
    // 'off', don't do anything.
    return;
  }

  // Only if a pin has not been provisioned yet and is to be switched on,
  // provision it to the relay state 'ON' which is 'LOW'.
  final GpioPinDigitalOutput pin = mGpioController.provisionDigitalOutputPin(
      Pins.GPIO_PIN[mMapping[num]], PinState.LOW);

  // Important: When the program is exited the pin needs to go into 'HIGH'
  // state so that the relay stays off. We don't want garage doors to open
  // when the app exits.
  pin.setShutdownOptions(true, PinState.HIGH, PinPullResistance.OFF);
  mActivePins.put(num, pin);
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:39,代码来源:RelayControllerImpl.java

示例7: main

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {

        // START SNIPPET: usage-create-controller-snippet
        // create gpio controller instance
        final GpioController gpio = GpioFactory.getInstance();
        // END SNIPPET: usage-create-controller-snippet

        // START SNIPPET: usage-provision-input-pin-snippet
        // provision gpio pin #02 as an input pin with its internal pull down resistor enabled
        // (configure pin edge to both rising and falling to get notified for HIGH and LOW state
        // changes)
        GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02,             // PIN NUMBER
                                                                     "MyButton",                   // PIN FRIENDLY NAME (optional)
                                                                     PinPullResistance.PULL_DOWN); // PIN RESISTANCE (optional)

        // END SNIPPET: usage-provision-input-pin-snippet
        // START SNIPPET: usage-provision-output-pin-snippet
        // provision gpio pins #04 as an output pin and make sure is is set to LOW at startup
        GpioPinDigitalOutput myLed = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04,   // PIN NUMBER
                                                                   "My LED",           // PIN FRIENDLY NAME (optional)
                                                                   PinState.LOW);      // PIN STARTUP STATE (optional)
        // END SNIPPET: usage-provision-output-pin-snippet

        // START SNIPPET: usage-shutdown-pin-snippet
        // 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
        myLed.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
        // END SNIPPET: usage-shutdown-pin-snippet

        // START SNIPPET: usage-control-pin-snippet
        // explicitly set a state on the pin object
        myLed.setState(PinState.HIGH);

        // use convenience wrapper method to set state on the pin object
        myLed.low();
        myLed.high();

        // use toggle method to apply inverse state on the pin object
        myLed.toggle();

        // use pulse method to set the pin to the HIGH state for
        // an explicit length of time in milliseconds
        myLed.pulse(1000);
        // END SNIPPET: usage-control-pin-snippet

        // START SNIPPET: usage-read-pin-snippet
        // get explicit state enumeration for the GPIO pin associated with the button
        PinState myButtonState = myButton.getState();

        // use convenience wrapper method to interrogate the button state
        boolean buttonPressed = myButton.isHigh();
        // END SNIPPET: usage-read-pin-snippet

        // START SNIPPET: usage-register-listener-snippet
        // create and register gpio pin listener
        myButton.addListener(new GpioUsageExampleListener());
        // END SNIPPET: usage-register-listener-snippet

        // START SNIPPET: usage-trigger-snippet
        // create a gpio synchronization trigger on the input pin
        // when the input state changes, also set LED controlling gpio pin to same state
        myButton.addTrigger(new GpioSyncStateTrigger(myLed));
        // END SNIPPET: usage-trigger-snippet

        // 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
    }
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:75,代码来源:UsageGpioExample.java

示例8: main

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    
    // START SNIPPET: usage-create-controller-snippet
    // create gpio controller instance
    final GpioController gpio = GpioFactory.getInstance();
    // END SNIPPET: usage-create-controller-snippet

    // START SNIPPET: usage-provision-input-pin-snippet
    // provision gpio pin #02 as an input pin with its internal pull down resistor enabled
    // (configure pin edge to both rising and falling to get notified for HIGH and LOW state
    // changes)
    GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02,             // PIN NUMBER
                                                                 "MyButton",                   // PIN FRIENDLY NAME (optional)
                                                                 PinPullResistance.PULL_DOWN); // PIN RESISTANCE (optional)

    // END SNIPPET: usage-provision-input-pin-snippet
    // START SNIPPET: usage-provision-output-pin-snippet
    // provision gpio pins #04 as an output pin and make sure is is set to LOW at startup
    GpioPinDigitalOutput myLed = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04,   // PIN NUMBER
                                                               "My LED",           // PIN FRIENDLY NAME (optional)
                                                               PinState.LOW);      // PIN STARTUP STATE (optional)
    // END SNIPPET: usage-provision-output-pin-snippet

    // START SNIPPET: usage-shutdown-pin-snippet
    // 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
    myLed.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
    // END SNIPPET: usage-shutdown-pin-snippet
    
    // START SNIPPET: usage-control-pin-snippet
    // explicitly set a state on the pin object
    myLed.setState(PinState.HIGH);

    // use convenience wrapper method to set state on the pin object
    myLed.low();
    myLed.high();

    // use toggle method to apply inverse state on the pin object
    myLed.toggle();

    // use pulse method to set the pin to the HIGH state for
    // an explicit length of time in milliseconds
    myLed.pulse(1000);
    // END SNIPPET: usage-control-pin-snippet

    // START SNIPPET: usage-read-pin-snippet
    // get explicit state enumeration for the GPIO pin associated with the button
    PinState myButtonState = myButton.getState();

    // use convenience wrapper method to interrogate the button state
    boolean buttonPressed = myButton.isHigh();
    // END SNIPPET: usage-read-pin-snippet

    // START SNIPPET: usage-register-listener-snippet
    // create and register gpio pin listener
    myButton.addListener(new GpioUsageExampleListener());
    // END SNIPPET: usage-register-listener-snippet

    // START SNIPPET: usage-trigger-snippet
    // create a gpio synchronization trigger on the input pin
    // when the input state changes, also set LED controlling gpio pin to same state
    myButton.addTrigger(new GpioSyncStateTrigger(myLed));
    // END SNIPPET: usage-trigger-snippet

    // 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                
}
 
开发者ID:iot-labs,项目名称:communication,代码行数:75,代码来源:UsageGpioExample.java

示例9: createController

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
@Override
protected IRoverController createController() throws IOException {

	try {
		bus = I2CFactory.getInstance(I2CBus.BUS_1);
	} catch (UnsupportedBusNumberException e) {
		throw new IOException(e);
	}

	I2CDevice device = bus.getDevice(PCA9685_I2C_ADDRESS);
	pwmGenerator = new PCA9685PWMGenerator(device);

	pwmGenerator.open();
	pwmGenerator.setFrequency(50);

	GpioController gpio = GpioFactory.getInstance();
	GpioPinDigitalOutput directionPinLeft = gpio.provisionDigitalOutputPin(DIRECTION_PIN_LEFT_MOTOR,
			"Direction Left", PinState.LOW);
	directionPinLeft.setShutdownOptions(true, PinState.LOW);

	GpioPinDigitalOutput directionPinRight = gpio.provisionDigitalOutputPin(DIRECTION_PIN_RIGHT_MOTOR,
			"Direction Right", PinState.LOW);
	directionPinRight.setShutdownOptions(true, PinState.LOW);

	ConfigurationSource source = new FilesConfigurationSource(
			() -> Collections.singletonList(Paths.get(System.getProperty("rover.cfg", "rover.properties"))));

	ConfigurationProvider provider = new ConfigurationProviderBuilder().withConfigurationSource(source)
			.withReloadStrategy(new PeriodicalReloadStrategy(5, TimeUnit.SECONDS)).build();

	IMotorController leftMotor = new MotorControllerImpl(pwmGenerator.getOutput(PWM_OUTPUT_LEFT_MOTOR),
			directionPinLeft, provider.bind("motorLeft", IMotorControllerConfiguration.class));
	IMotorController rightMotor = new MotorControllerImpl(pwmGenerator.getOutput(PWM_OUTPUT_RIGHT_MOTOR),
			directionPinRight, provider.bind("motorRight", IMotorControllerConfiguration.class));
	IServoController panServo = new ServoControllerImpl(pwmGenerator.getOutput(PWM_OUTPUT_PAN_SERVO),
			provider.bind("servoPan", IServoControllerConfiguration.class));
	IServoController tiltServo = new ServoControllerImpl(pwmGenerator.getOutput(PWM_OUTPUT_TILT_SERVO),
			provider.bind("servoTilt", IServoControllerConfiguration.class));

	controller = new RoverControllerImpl(leftMotor, rightMotor, panServo, tiltServo);

	return controller;

}
 
开发者ID:gaelblondelle,项目名称:PSysRoverInitialContrib,代码行数:45,代码来源:PiServer.java

示例10: main

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的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(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();

        System.out.println("Exiting ControlGpioExample");
    }
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:46,代码来源:ControlGpioExample.java

示例11: main

import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的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(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();
}
 
开发者ID:iot-labs,项目名称:communication,代码行数:44,代码来源:ControlGpioExample.java


注:本文中的com.pi4j.io.gpio.GpioPinDigitalOutput.setShutdownOptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。