當前位置: 首頁>>代碼示例>>Java>>正文


Java GpioController.setShutdownOptions方法代碼示例

本文整理匯總了Java中com.pi4j.io.gpio.GpioController.setShutdownOptions方法的典型用法代碼示例。如果您正苦於以下問題:Java GpioController.setShutdownOptions方法的具體用法?Java GpioController.setShutdownOptions怎麽用?Java GpioController.setShutdownOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.pi4j.io.gpio.GpioController的用法示例。


在下文中一共展示了GpioController.setShutdownOptions方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:41,代碼來源:CylonGpioExample.java

示例2: 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        
}
 
開發者ID:iot-labs,項目名稱:communication,代碼行數:41,代碼來源:CylonGpioExample.java

示例3: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
/**
 * @param args
 * @throws InterruptedException
 * @throws PlatformAlreadyAssignedException
 */
public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException {

    // ####################################################################
    //
    // !!!!! ATTENTION !!!!!  ALL ADC/AIN PINS ON ODROID-XU4 ARE 1.8VDC.
    //          DO NOT APPLY A HIGHER VOLTAGE THAN 1.8VDC TO THESE PINS.
    //
    // ####################################################################

    // ####################################################################
    //
    // since we are not using the default Raspberry Pi platform, we should
    // explicitly assign the platform as the Odroid platform.
    //
    // ####################################################################
    PlatformManager.setPlatform(Platform.ODROID);

    // create Pi4J console wrapper/helper
    // (This is a utility class to abstract some of the boilerplate code)
    final Console console = new Console();

    // print program title/header
    console.title("<-- The Pi4J Project -->", "Analog Input Example");

    // create gpio controller
    final GpioController gpio = GpioFactory.getInstance();

    // ####################################################################
    //
    // IF YOU ARE USING AN ODROID XU4 PLATFORM, THEN ...
    //    When provisioning a pin, use the OdroidXU4Pin class.
    //
    // ####################################################################

    // provision analog input pins
    final GpioPinAnalogInput[] inputs = {
            gpio.provisionAnalogInputPin(OdroidXU4Pin.AIN0, "Analog Input 0"),
            gpio.provisionAnalogInputPin(OdroidXU4Pin.AIN3, "Analog Input 3")
    };

    // set shutdown state for this pin: unexport the pins
    gpio.setShutdownOptions(true, inputs);

    // prompt user that we are ready
    console.println(" ... Successfully provisioned [" + inputs[0] + "]");
    console.println(" ... Successfully provisioned [" + inputs[1] + "]");
    console.emptyLine();
    console.box("Below is the 12-bit conversion value (a number ",
                "between 0 and 4095) from the two analog input ",
                "pins which represents a voltage applied to each",
                "pin between 0VDC (Ground) and +1.8VDC.  If no ",
                "voltage is currently applied to the analog input",
                "pins then they may 'float' between a value of 0" ,
                "to 4095.");

    // display current pin values
    console.emptyLine();
    console.println(" [" + inputs[0].toString() + "] value is: %4.0f (%2.1f VDC)",
            inputs[0].getValue(),
            getVoltage(inputs[0].getValue()));
    console.println(" [" + inputs[1].toString() + "] value is: %4.0f (%2.1f VDC)",
            inputs[1].getValue(),
            getVoltage(inputs[1].getValue()));
    console.emptyLine();

    // say goodbye
    console.goodbye();

    // 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:uwigem,項目名稱:uwigem2017,代碼行數:78,代碼來源:AnalogInputExample.java

示例4: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {

        System.out.println("<--Pi4J--> PCF8574 GPIO Example ... started.");

        // create gpio controller
        final GpioController gpio = GpioFactory.getInstance();

        // create custom MCP23017 GPIO provider
        final PCF8574GpioProvider provider = new PCF8574GpioProvider(I2CBus.BUS_1, PCF8574GpioProvider.PCF8574A_0x3F);

        // provision gpio input pins from MCP23017
        GpioPinDigitalInput myInputs[] = {
                gpio.provisionDigitalInputPin(provider, PCF8574Pin.GPIO_00),
                gpio.provisionDigitalInputPin(provider, PCF8574Pin.GPIO_01),
                gpio.provisionDigitalInputPin(provider, PCF8574Pin.GPIO_02)
            };

        // 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, PCF8574Pin.GPIO_04, PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, PCF8574Pin.GPIO_05, PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, PCF8574Pin.GPIO_06, PinState.LOW)
          };

        // on program shutdown, set the pins back to their default state: HIGH
        gpio.setShutdownOptions(true, PinState.HIGH, myOutputs);

        // 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 PCF8574GpioExample");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:52,代碼來源:PCF8574GpioExample.java

示例5: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String args[]) throws InterruptedException, IOException {
    
    System.out.println("<--Pi4J--> PCF8574 GPIO Example ... started.");
    
    // create gpio controller
    final GpioController gpio = GpioFactory.getInstance();
    
    // create custom MCP23017 GPIO provider
    final PCF8574GpioProvider gpioProvider = new PCF8574GpioProvider(I2CBus.BUS_1, PCF8574GpioProvider.PCF8574A_0x3F);
    
    // provision gpio input pins from MCP23017
    GpioPinDigitalInput myInputs[] = {
            gpio.provisionDigitalInputPin(gpioProvider, PCF8574Pin.GPIO_00),
            gpio.provisionDigitalInputPin(gpioProvider, PCF8574Pin.GPIO_01),
            gpio.provisionDigitalInputPin(gpioProvider, PCF8574Pin.GPIO_02)
        };
    
    // 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, PCF8574Pin.GPIO_04, PinState.LOW),
        gpio.provisionDigitalOutputPin(gpioProvider, PCF8574Pin.GPIO_05, PinState.LOW),
        gpio.provisionDigitalOutputPin(gpioProvider, PCF8574Pin.GPIO_06, PinState.LOW)
      };

    // on program shutdown, set the pins back to their default state: HIGH 
    gpio.setShutdownOptions(true, PinState.HIGH, myOutputs);
    
    // 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();
}
 
開發者ID:iot-labs,項目名稱:communication,代碼行數:50,代碼來源:PCF8574GpioExample.java


注:本文中的com.pi4j.io.gpio.GpioController.setShutdownOptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。