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


Java GpioController.provisionDigitalInputPin方法代碼示例

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


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

示例1: GPIOButton

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
/**
 * Constructing a software representation of an GPIO connected hardware
 * button.
 * 
 * @param pin
 *            the GPIO pin that the button is connected to.
 */
public GPIOButton(Pin pin) {
	// create gpio controller
	final GpioController gpio = GpioFactory.getInstance();

	// provision gpio pin as an input pin with its internal pull down
	// resistor enabled
	final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(pin, PinPullResistance.PULL_DOWN);

	// register an anonymous listener with the pi4j library to connect to
	// our internal listeners.
	myButton.addListener(new GpioPinListenerDigital() {

		@Override
		public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
			event.getState();
			if (event.getState() == PinState.HIGH) {
				setState(ButtonState.ON);
			} else {
				setState(ButtonState.OFF);
			}
		}
	});
}
 
開發者ID:SebiGo,項目名稱:BrewControlServer,代碼行數:31,代碼來源:GPIOButton.java

示例2: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException, FileNotFoundException {
	
	lp0 = new FileOutputStream(new File("/dev/usb/lp0"));

	GpioController gpio;
	GpioPinDigitalInput printButton;

	gpio = GpioFactory.getInstance();
	printButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_04, PinPullResistance.PULL_DOWN);
	printButton.addListener(new ButtonListener());

	System.out.println("Start pi cam");
	picam = new Camera();
	new Thread(picam).start();

	try {
		printer = new TMT20();
	} catch (SecurityException | UsbException e) {
		e.printStackTrace();
	}
	
	System.out.println("Press the big button !");

}
 
開發者ID:pierre-muth,項目名稱:selfpi,代碼行數:25,代碼來源:PrintImage.java

示例3: init

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
@Override
public void init() throws ServletException
{
    super.init();
    
    takingSnapshot = false;
    
    ServletContext servletContext = getServletContext();
    GpioController gpio = (GpioController) servletContext.getAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY);
    if(gpio == null)
    {
        System.err.println("The foot pedal servlet could not obtain a GPIO contorller from the servlet context");
    }
    else
    {            
        GpioPinDigitalInput photoBoothButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_17, 
                                                                             "foot pedal button", 
                                                                             PinPullResistance.PULL_UP);
        photoBoothButton.addListener(this);
        servletContext.setAttribute(PHOTO_BOOTH_FOOT_PEDAL_KEY, photoBoothButton);
    }
}
 
開發者ID:onebeartoe,項目名稱:photorama,代碼行數:23,代碼來源:FootPedalServlet.java

示例4: initializePins

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
private static GpioPinDigitalInput[] initializePins(int mapping[], GpioController gpioController,
                                                    final RelayStateChangedListener listener) {
  final GpioPinDigitalInput[] pins = new GpioPinDigitalInput[mapping.length];
  for (int i = 0; i < mapping.length; ++i) {
    pins[i] = gpioController.provisionDigitalInputPin(Pins.GPIO_PIN[mapping[i]],
        PinPullResistance.PULL_UP);
    final int relayNum = i;
    pins[i].addListener((GpioPinListenerDigital) event -> {
      listener.onRelayStateChanged(relayNum, event.getState() == PinState.LOW);
    });

    // Tell the listener about the current state before change events are
    // received.
    listener.onRelayStateChanged(relayNum, pins[i].getState() == PinState.LOW);
  }
  return pins;
}
 
開發者ID:shaeberling,項目名稱:winston,代碼行數:18,代碼來源:ReedControllerImpl.java

示例5: 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;

}
 
開發者ID:mitchellriley,項目名稱:OpenGarageServer,代碼行數:17,代碼來源:GarageDoor.java

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

示例7: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String[] args) 
           throws IOException, InterruptedException {
       
       // Create a GPIO controller instance
final GpioController gpio = GpioFactory.getInstance();	
       
       // Pi4J 22 = 6
       final GpioPinDigitalInput inputPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_22, PinPullResistance.PULL_DOWN);
       PinState inputState = inputPin.getState();
       /*
       while(System.in.available() == 0) {
           System.out.println(inputPin.isHigh());
           inputState = inputPin.getState();
           System.out.println(inputState.toString());
           Thread.sleep(1000);
       }*/
       
       System.out.println("Pulled down pin 22/6");

       int samples = 100000;
       
       // Take a bunch of samples and report
       while(System.in.available() == 0) {
           double sample = 0;
           for(int k = 0; k < samples ; k++) {
               if(inputPin.isHigh()) {
                   sample++;
               }
           }
           
           System.out.println(sample/samples);
       }
       
       System.out.println("Done");
   }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:36,代碼來源:TCS3200.java

示例8: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String args[]) throws InterruptedException {
    System.out.println("<--Pi4J--> GPIO Listen 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);

    // create and register gpio pin listener
    myButton.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(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,代碼行數:31,代碼來源:ListenGpioExample.java

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

示例10: flowMeter

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void flowMeter(List<PumpRunner> pumps) {

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

		// provision gpio pin as an input pin with its internal pull down
		// resistor enabled
		for (PumpRunner pumpRunner : pumps) {
			final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(
					pumpRunner.getPin(), PinPullResistance.PULL_DOWN);
			myButton.addListener(new PumpListener(pumpRunner));
		}

	}
 
開發者ID:iproduct,項目名稱:course-social-robotics,代碼行數:15,代碼來源:CoctailMachine.java

示例11: start

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
@Override
public void start() {
    pulseElectricityMeter.setImpulsesPerKwh(impulsesPerKwh);
    pulseElectricityMeter.setMeasurementInterval(getMeasurementInterval());

    GpioController gpioController = getGpioController();
    if(gpioController != null) {
        try {
            inputPin = gpioController.provisionDigitalInputPin(getGpio(), getPinPullResistance());
            inputPin.addListener(new GpioPinListenerDigital() {
                @Override
                public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                    logger.debug("{}: GPIO {} changed to {}", getApplianceId(), event.getPin(), event.getState());
                    if(event.getState() == PinState.HIGH) {
                        pulseElectricityMeter.addTimestampAndMaintain(System.currentTimeMillis());
                    }
                }
            });
            logger.debug("{}: Starting {} for {}", getApplianceId(), getClass().getSimpleName(), getGpio());
        }
        catch(Exception e) {
            logger.error("{}: Error start metering using {}", getApplianceId(), getGpio(), e);
        }
    }
    else { 
        logGpioAccessDisabled();
    }
}
 
開發者ID:camueller,項目名稱:SmartApplianceEnabler,代碼行數:29,代碼來源:S0ElectricityMeter.java

示例12: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
    System.out.println("<--Pi4J--> GPIO Listen 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);

    // create and register gpio pin listener
    myButton.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(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:starksm64,項目名稱:RaspberryPi,代碼行數:31,代碼來源:ListenGpioExample.java

示例13: init

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
@Override
    public void init() throws ServletException
    {
        super.init();
        
        logger = Logger.getLogger(getClass().getName());
        
        takingSnapshots = false;
        
        ServletContext servletContext = getServletContext();
        GpioController gpio = (GpioController) servletContext.getAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY);
        if(gpio == null)
        {
            System.out.println("*Provisioning GPIO.");
            gpio = GpioFactory.getInstance();
            servletContext.setAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY, gpio);
            
            GpioPinDigitalInput photoBoothButton = gpio.provisionDigitalInputPin(buttonPin, 
                                                                             "photo booth button", 
                                                                             PinPullResistance.PULL_UP);   // works with the Adafruit massive arcade button
//                                                                           PinPullResistance.PULL_DOWN); // works with a tactile/simple push button
            
            System.out.println("*GPIO provisioned :)");
            photoBoothButton.addListener(this);
            servletContext.setAttribute(PHOTO_BOOTH_BUTTON_KEY, photoBoothButton);
        }
    }
 
開發者ID:onebeartoe,項目名稱:photorama,代碼行數:28,代碼來源:PhotoBoothServlet.java

示例14: PhotoBoothButtonTester

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public PhotoBoothButtonTester()
    {
        System.out.println("Provisioning GPIO.");
    
        GpioController gpio = GpioFactory.getInstance();
             
        
        GpioPinDigitalInput photoBoothButton = gpio.provisionDigitalInputPin(buttonPin, 
                                                                             "photo booth button", 
                                                                             PinPullResistance.PULL_UP);   // tried with the Adafruit button
// worked for the tacktile/simple push button                                PinPullResistance.PULL_DOWN);
        System.out.println("GPIO provisioned!");
        photoBoothButton.addListener(this);
    }
 
開發者ID:onebeartoe,項目名稱:photorama,代碼行數:15,代碼來源:PhotoBoothButtonTester.java

示例15: provisionSelfiePin

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
@Override
public GpioPinDigitalInput provisionSelfiePin(GpioController gpio) 
{
    // this is GPIO pin #25 on the Raspberry Pi header.
    GpioPinDigitalInput selfiePin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_06,
                                                    SELFIE_SENSOR_PIN,
                                                    PinPullResistance.PULL_DOWN);
    
    return selfiePin;
}
 
開發者ID:onebeartoe,項目名稱:lizard-enclosure,代碼行數:11,代碼來源:RaspberryPiLizardEnclosureSevice.java


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