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


Java GpioController.provisionDigitalMultipurposePin方法代碼示例

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


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

示例1: PhotoCellControllerImpl

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
@VisibleForTesting
PhotoCellControllerImpl(int[] mapping, GpioController gpioController,
                        WinstonScheduledExecutor executor, int sleepTimeoutMillis) {
  Preconditions.checkArgument(mapping.length == 1,
      "Only one photo cell supported at this time.");
  Preconditions.checkArgument(mapping[0] <= Pins.GPIO_PIN.length, "Illegal GPIO pin.");

  mSleepTimeoutMillis = sleepTimeoutMillis;
  int gpioPin = mapping[0];
  LOG.info("Initializing on GPIO pin: " + gpioPin);
  mPin = gpioController.provisionDigitalMultipurposePin(
      Pins.GPIO_PIN[gpioPin], PinMode.DIGITAL_INPUT);

  mPin.addListener(new GpioPinListenerDigital() {
    @Override
    public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
      if (event.getState() == PinState.HIGH) {
        long deltaNs = System.nanoTime() - mLastStartTimeNanos;

        if (DEBUG_LOGGING) {
          mMax = Math.max(mMax, deltaNs);
          mMin = Math.min(mMin, deltaNs);
          LOG.info("Value: " + (deltaNs / 1000000) + " ms.  (" + deltaNs + " ns.)");
          LOG.info("Min: " + mMin + "  /  Max: " + mMax);
        }

        // Clamp the value.
        deltaNs = Math.max(Math.min(MAX_LIGHT_NANOS, deltaNs), MIN_LIGHT_NANOS);
        mReadValuePercent = (int) (100 - (deltaNs - MIN_LIGHT_NANOS) / (LIGHT_RANGE_NANOS / 100));
      }
    }
  });
  executor.scheduleAtFixedRate(
      new ReadValuesRunnable(), 0, MEASUREMENT_INTERVAL_SECONDS, TimeUnit.SECONDS);
}
 
開發者ID:shaeberling,項目名稱:winston,代碼行數:36,代碼來源:PhotoCellControllerImpl.java

示例2: main

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

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

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

        // provision gpio pin #02 as an multi-purpose pin configured as an input
        // pin by default with its internal pull down resistor enabled
        final GpioPinDigitalMultipurpose pin = gpio.provisionDigitalMultipurposePin(RaspiPin.GPIO_02, PinMode.DIGITAL_INPUT, PinPullResistance.PULL_DOWN);

        // create and register gpio pin listener
        pin.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());
            }
        });

        System.out.println(" ... complete the GPIO #02 circuit and see the listener feedback here in the console.");

        // keep program running until user aborts (CTRL-C)
        while(true){
            Thread.sleep(5000);

            // here we want to control the multi-purpose GPIO pin
            // so we must reconfigure the pin mode first
            pin.setMode(PinMode.DIGITAL_OUTPUT);

            // perform the pin output operation
            System.out.println(" --> GPIO PIN - RECONFIGURED AS OUPUT PIN");
            pin.pulse(1000, true);

            // reconfigure the pin back to an input pin
            pin.setMode(PinMode.DIGITAL_INPUT);
            System.out.println(" --> GPIO PIN - RECONFIGURED AS INPUT PIN");
        }

        // 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,代碼行數:44,代碼來源:MultipurposePinGpioExample.java

示例3: main

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

    System.out.println("<--Pi4J--> GPIO Multipurpose Pin Example ... started.");
    
    // create gpio controller
    final GpioController gpio = GpioFactory.getInstance();

    // provision gpio pin #02 as an multi-purpose pin configured as an input  
    // pin by default with its internal pull down resistor enabled
    final GpioPinDigitalMultipurpose pin = gpio.provisionDigitalMultipurposePin(RaspiPin.GPIO_02, PinMode.DIGITAL_INPUT, PinPullResistance.PULL_DOWN);

    // create and register gpio pin listener
    pin.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());
        }            
    });
    
    System.out.println(" ... complete the GPIO #02 circuit and see the listener feedback here in the console.");
    
    // keep program running until user aborts (CTRL-C)
    for (;;) {
        Thread.sleep(5000);

        // here we want to control the multi-purpose GPIO pin
        // so we must reconfigure the pin mode first
        pin.setMode(PinMode.DIGITAL_OUTPUT);
        
        // perform the pin output operation
        System.out.println(" --> GPIO PIN - RECONFIGURED AS OUPUT PIN");
        pin.pulse(1000, true);
        
        // reconfigure the pin back to an input pin
        pin.setMode(PinMode.DIGITAL_INPUT);
        System.out.println(" --> GPIO PIN - RECONFIGURED AS INPUT PIN");
    }
    
    // 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,代碼行數:44,代碼來源:MultipurposePinGpioExample.java


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