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


Java GpioPinDigitalInput类代码示例

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


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

示例1: startListenDigitalPin

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的package包/类
private boolean startListenDigitalPin(MessageParsedInfo messageParsedInfo) {
	int pinNum    = (Integer)messageParsedInfo.getParsedValues()[0];
	
	GpioPinListenerDigital listener = digitalListeners.get(pinNum);
	if(listener == null) {
		listener = createDigitalListener(pinNum);
		GpioPinDigitalInput pin = (GpioPinDigitalInput)getPin(pinNum);
		pin.setMode(PinMode.DIGITAL_INPUT);
		pin.setPullResistance(PinPullResistance.PULL_DOWN);
		
		digitalListeners.put(pinNum, listener);
		pin.addListener(listener);
	}
	
	return true;
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:17,代码来源:RaspberryPIConnection.java

示例2: GPIOButton

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的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

示例3: main

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的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

示例4: initializeInputPin

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的package包/类
private GpioPinDigitalInput initializeInputPin(ChannelUID channel) {
    logger.debug("initializing input pin for channel {}", channel.getAsString());
    Pin pin = PinMapper.get(channel.getIdWithoutGroup());

    String pullMode = DEFAULT_PULL_MODE;
    if (thing.getChannel(channel.getIdWithoutGroup()) != null) {
        Configuration configuration = thing.getChannel(channel.getId()).getConfiguration();
        pullMode = ((String) configuration.get(PULL_MODE)) != null ? ((String) configuration.get(PULL_MODE))
                : DEFAULT_PULL_MODE;
    }
    logger.debug("initializing pin {}, pullMode {}, mcpProvider {}", pin, pullMode, mcpProvider);
    GpioPinDigitalInput input = GPIODataHolder.GPIO.provisionDigitalInputPin(mcpProvider, pin,
            channel.getIdWithoutGroup(), PinPullResistance.valueOf(pullMode));
    input.addListener(this);
    logger.debug("Bound digital input for PIN: {}, ItemName: {}, pullMode: {}", pin, channel.getAsString(),
            pullMode);
    return input;

}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:20,代码来源:Mcp23017Handler.java

示例5: init

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的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

示例6: initializePins

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的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

示例7: mapearPino

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的package包/类
private void mapearPino(int endereco, GrappaPin pinoDigitalGrappa) {
	GpioPinDigital pino = null;
	switch(pinoDigitalGrappa.getType()){
	case INPUT:
	case MONITOR:
		GpioPinDigitalInput entrada = this.gpio.provisionDigitalInputPin(getPinoMapeado(endereco), "GRAPPA_" + endereco,PinPullResistance.PULL_DOWN);
		pino = entrada;
		break;
	case OUTPUT:
		pino = this.gpio.provisionDigitalOutputPin(getPinoMapeado(endereco), "GRAPPA_" + endereco);
		pino.setShutdownOptions(true, PinState.LOW);
		break;
	default:
		throw new RuntimeException();
	}
	this.pinos.put(endereco, pino);
}
 
开发者ID:Gunisalvo,项目名称:Grappa,代码行数:18,代码来源:RaspberryPi4J.java

示例8: registerServices

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的package包/类
@Override
public List<PinService> registerServices(List<Class<PinService>> templates) {
	List<PinService> servicos = new ArrayList<>();
	try{
		for(Class<PinService> t : templates){
			PinListener anotacao = t.getAnnotation(PinListener.class);
			int[] enderecos = anotacao.addresses();
			PinService servico = t.newInstance();
			registrarHardware(servico);
			for(int i = 0; i < enderecos.length; i++){
				this.mapeamento.getPins().get(enderecos[i]).registerServices(servico);
				registrarServico(servico, (GpioPinDigitalInput) this.pinos.get(enderecos[i]));
			}
			servicos.add(servico);
			
		}
	}catch(Exception ex){
		throw new RuntimeException(ex);
	}
	return servicos;
}
 
开发者ID:Gunisalvo,项目名称:Grappa,代码行数:22,代码来源:RaspberryPi4J.java

示例9: main

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的package包/类
public static void main(String [] args) throws Exception
{        
    GpioController gpio = GpioFactory.getInstance();
    
    String outpath = System.getProperty("user.home") + "/lizard-enclosure/photos";
    Camera camera = new RaspberryPiCamera();
    camera.setOutputPath(outpath);
            
    LizardEnclosureSevice lizardEnclosureSevice = new RaspberryPiLizardEnclosureSevice(camera);
    
    GpioPinListenerDigital selfieListener = lizardEnclosureSevice.newSelfieListener();
    
    GpioPinDigitalInput selfieSensorPin = lizardEnclosureSevice.provisionSelfiePin(gpio);
    selfieSensorPin.addListener(selfieListener);
    
    System.out.println("Ctrl+C to quit");
    while(true)
    {
        Sleeper.sleepo(1000);
    }
}
 
开发者ID:onebeartoe,项目名称:lizard-enclosure,代码行数:22,代码来源:SelfieSensorTest.java

示例10: main

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的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

示例11: SyringePump

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的package包/类
/**
* 
* @param dirPin Pin used to choose direction.
* @param stepPin Pin used to take steps
* @param enablePin Pin used to DISABLE the motor
* @param endHigh Pin that goes high when at the end
* @param endLow Pin that goes high when at the end
* @param rate Number of steps for 1 mL fluid moved
*/
public SyringePump(GpioPinDigitalOutput dirPin, GpioPinDigitalOutput stepPin, GpioPinDigitalOutput enablePin, 
        GpioPinDigitalInput endHigh, GpioPinDigitalInput endLow, double rate){
    this.rate = rate;
    this.dirPin = dirPin;
    this.stepPin = stepPin;
    this.enablePin = enablePin;
    this.endHigh = endHigh;
    this.endLow = endLow;
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:19,代码来源:SyringePump.java

示例12: main

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的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

示例13: getNextInput

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的package包/类
public GpioPinDigitalInput getNextInput(PinPullResistance ppr) {
    // No pins are left
    if (this.availablePins.isEmpty()) {
        return null;
    }

    NamedPin temp = this.availablePins.get(0);
    this.assignedPins.add(temp);
    this.availablePins.remove(temp);

    GpioPinDigitalInput result = this.gpio.provisionDigitalInputPin(temp.provider, temp.pin, temp.name, ppr);
    return result;
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:14,代码来源:GpioManager.java

示例14: main

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的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

示例15: main

import com.pi4j.io.gpio.GpioPinDigitalInput; //导入依赖的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


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