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


Java GpioUtil.setEdgeDetection方法代码示例

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


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

示例1: test

import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public void test(int gpio) {
	GpioFactory.setDefaultProvider(new RaspiGpioProvider(RaspiPinNumberingScheme.BROADCOM_PIN_NUMBERING));
	GpioController gpio_controller = GpioFactory.getInstance();
	Pin pin = RaspiBcmPin.getPinByAddress(gpio);
	GpioPinDigitalInput digitalInputPin = gpio_controller.provisionDigitalInputPin(pin,
			"Digital Input for BCM GPIO " + gpio, PinPullResistance.PULL_UP);
	GpioUtil.setEdgeDetection(pin.getAddress(), PinEdge.BOTH.getValue());
	digitalInputPin.addListener(this);
	System.out.println("Waiting 20s for events..., thread name=" + Thread.currentThread().getName());
	SleepUtil.sleepSeconds(20);
	gpio_controller.unprovisionPin(digitalInputPin);
	gpio_controller.shutdown();
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:14,代码来源:ButtonTestPi4j.java

示例2: main

import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {
    int pin;
    int dataPtr;
    int l, s, d;

    System.out.println("<--Pi4J--> GPIO test program");

    // setup wiringPi
    if (Gpio.wiringPiSetup() == -1) {
        System.out.println(" ==>> GPIO SETUP FAILED");
        return;
    }

    // set GPIO 4 as the input trigger
    GpioUtil.export(7, GpioUtil.DIRECTION_IN);
    GpioUtil.setEdgeDetection(7, GpioUtil.EDGE_BOTH);
    Gpio.pinMode (7, Gpio.INPUT) ;
    Gpio.pullUpDnControl(7, Gpio.PUD_DOWN);

    // set all other GPIO as outputs
    for (pin = 0; pin < 7; ++pin) {
        // export all the GPIO pins that we will be using
        GpioUtil.export(pin, GpioUtil.DIRECTION_OUT);
        Gpio.pinMode(pin, Gpio.OUTPUT);
    }

    dataPtr = 0;
    while (true) {
        l = data[dataPtr++]; // LED
        s = data[dataPtr++]; // State
        d = data[dataPtr++]; // Duration (10ths)

        if ((l + s + d) == 27) {
            dataPtr = 0;
            continue;
        }

        Gpio.digitalWrite(l, s);

        if (Gpio.digitalRead(7) == 1) // Pressed as our switch shorts to ground
            Gpio.delay(d * 10); // Faster!
        else
            Gpio.delay(d * 100);
    }
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:46,代码来源:WiringPiGpioExample.java

示例3: main

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

        System.out.println("<--Pi4J--> GPIO INTERRUPT test program");

        // create and add GPIO listener
        GpioInterrupt.addListener(new GpioInterruptListener() {
            @Override
            public void pinStateChange(GpioInterruptEvent event) {
                System.out.println("Raspberry Pi PIN [" + event.getPin() +"] is in STATE [" + event.getState() + "]");

                if(event.getPin() == 7) {
                    Gpio.digitalWrite(6, event.getStateValue());
                }
                if(event.getPin() == 0) {
                    Gpio.digitalWrite(5, event.getStateValue());
                }
            }
        });

        // setup wiring pi
        if (Gpio.wiringPiSetup() == -1) {
            System.out.println(" ==>> GPIO SETUP FAILED");
            return;
        }

        // export all the GPIO pins that we will be using
        GpioUtil.export(0, GpioUtil.DIRECTION_IN);
        GpioUtil.export(7, GpioUtil.DIRECTION_IN);
        GpioUtil.export(5, GpioUtil.DIRECTION_OUT);
        GpioUtil.export(6, GpioUtil.DIRECTION_OUT);

        // set the edge state on the pins we will be listening for
        GpioUtil.setEdgeDetection(0, GpioUtil.EDGE_BOTH);
        GpioUtil.setEdgeDetection(7, GpioUtil.EDGE_BOTH);

        // configure GPIO pins 5, 6 as an OUTPUT;
        Gpio.pinMode(5, Gpio.OUTPUT);
        Gpio.pinMode(6, Gpio.OUTPUT);

        // configure GPIO 0 as an INPUT pin; enable it for callbacks
        Gpio.pinMode(0, Gpio.INPUT);
        Gpio.pullUpDnControl(0, Gpio.PUD_DOWN);
        GpioInterrupt.enablePinStateChangeCallback(0);

        // configure GPIO 7 as an INPUT pin; enable it for callbacks
        Gpio.pinMode(7, Gpio.INPUT);
        Gpio.pullUpDnControl(7, Gpio.PUD_DOWN);
        GpioInterrupt.enablePinStateChangeCallback(7);

        // continuously loop to prevent program from exiting
        while (true) {
            Thread.sleep(5000);
        }
    }
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:55,代码来源:WiringPiGpioInterruptExample.java

示例4: WiringPiDigitalInputDevice

import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public WiringPiDigitalInputDevice(String key, DeviceFactoryInterface deviceFactory, int gpio,
		GpioPullUpDown pud, GpioEventTrigger trigger) throws RuntimeIOException {
	super(key, deviceFactory);
	
	this.gpio = gpio;
	switch (trigger) {
	case RISING:
		edge = Gpio.INT_EDGE_RISING;
		break;
	case FALLING:
		edge = Gpio.INT_EDGE_FALLING;
		break;
	case BOTH:
	default:
		edge = Gpio.INT_EDGE_BOTH;
		break;
	}
	
	try {
		// Note calling this method will automatically export the pin and set the pin direction to INPUT
		if (!GpioUtil.setEdgeDetection(gpio, edge)) {
			throw new RuntimeIOException("Error setting edge detection (" + edge + ") for pin " + gpio);
		}
	} catch (RuntimeException re) {
		throw new RuntimeIOException(re);
	}

	int wpi_pud;
	switch (pud) {
	case PULL_DOWN:
		wpi_pud = Gpio.PUD_DOWN;
		break;
	case PULL_UP:
		wpi_pud = Gpio.PUD_UP;
		break;
	case NONE:
	default:
		wpi_pud = Gpio.PUD_OFF;
		break;
	}
	Gpio.pullUpDnControl(gpio, wpi_pud);
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:43,代码来源:WiringPiDigitalInputDevice.java

示例5: Pi4jDigitalInputDevice

import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
Pi4jDigitalInputDevice(String key, DeviceFactoryInterface deviceFactory, GpioController gpioController,
		int gpio, GpioPullUpDown pud, GpioEventTrigger trigger) {
	super(key, deviceFactory);
	
	Pin pin = RaspiBcmPin.getPinByAddress(gpio);
	if (pin == null) {
		throw new IllegalArgumentException("Illegal GPIO number: " + gpio);
	}
	
	this.gpio = gpio;
	
	PinPullResistance ppr;
	switch (pud) {
	case PULL_DOWN:
		ppr = PinPullResistance.PULL_DOWN;
		break;
	case PULL_UP:
		ppr = PinPullResistance.PULL_UP;
		break;
	case NONE:
	default:
		ppr = PinPullResistance.OFF;
	}

	/*
	PinEdge edge;
	switch (trigger) {
	case FALLING:
		edge = PinEdge.FALLING;
		break;
	case RISING:
		edge = PinEdge.RISING;
		break;
	case NONE:
		edge = PinEdge.NONE;
		break;
	case BOTH:
	default:
		edge = PinEdge.BOTH;
		break;
	}
	*/
	
	// Note configuring GPIO event trigger values (rising / falling / both) via the provision APIs isn't possible in Pi4j
	digitalInputPin = gpioController.provisionDigitalInputPin(
			pin, "Digital Input for BCM GPIO " + gpio, ppr);
	
	// RaspiGpioProvider.export() calls this for all input pins:
	if (! GpioUtil.setEdgeDetection(pin.getAddress(), PinEdge.BOTH.getValue())) {
		throw new RuntimeIOException("Error setting edge detection");
	}
	//GpioUtil.setEdgeDetection(pin.getAddress(), edge.getValue());
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:54,代码来源:Pi4jDigitalInputDevice.java

示例6: main

import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {
    int pin;
    int dataPtr;
    int l, s, d;
    
    System.out.println("<--Pi4J--> GPIO test program");

    // setup wiringPi
    if (Gpio.wiringPiSetup() == -1) {
        System.out.println(" ==>> GPIO SETUP FAILED");
        return;
    }

    // set GPIO 4 as the input trigger 
    GpioUtil.export(7, GpioUtil.DIRECTION_IN);
    GpioUtil.setEdgeDetection(7, GpioUtil.EDGE_BOTH);
    Gpio.pinMode (7, Gpio.INPUT) ;  
    Gpio.pullUpDnControl(7, Gpio.PUD_DOWN);        

    // set all other GPIO as outputs
    for (pin = 0; pin < 7; ++pin) {
        // export all the GPIO pins that we will be using
        GpioUtil.export(pin, GpioUtil.DIRECTION_OUT);            
        Gpio.pinMode(pin, Gpio.OUTPUT);
    }
    
    dataPtr = 0;
    for (;;) {
        l = data[dataPtr++]; // LED
        s = data[dataPtr++]; // State
        d = data[dataPtr++]; // Duration (10ths)

        if ((l + s + d) == 27) {
            dataPtr = 0;
            continue;
        }

        Gpio.digitalWrite(l, s);
        
        if (Gpio.digitalRead(7) == 1) // Pressed as our switch shorts to ground
            Gpio.delay(d * 10); // Faster!
        else
            Gpio.delay(d * 100);
    }
}
 
开发者ID:iot-labs,项目名称:communication,代码行数:46,代码来源:WiringPiGpioExample.java

示例7: main

import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {
    
    System.out.println("<--Pi4J--> GPIO INTERRUPT test program");
    
    // create and add GPIO listener 
    GpioInterrupt.addListener(new GpioInterruptListener() {
        @Override
        public void pinStateChange(GpioInterruptEvent event) {
            System.out.println("Raspberry Pi PIN [" + event.getPin() +"] is in STATE [" + event.getState() + "]");
            
            if(event.getPin() == 7) {
                Gpio.digitalWrite(6, event.getStateValue());
            }
            if(event.getPin() == 0) {
                Gpio.digitalWrite(5, event.getStateValue());
            }
        }
    });
    
    // setup wiring pi
    if (Gpio.wiringPiSetup() == -1) {
        System.out.println(" ==>> GPIO SETUP FAILED");
        return;
    }

    // export all the GPIO pins that we will be using
    GpioUtil.export(0, GpioUtil.DIRECTION_IN);
    GpioUtil.export(7, GpioUtil.DIRECTION_IN);
    GpioUtil.export(5, GpioUtil.DIRECTION_OUT);
    GpioUtil.export(6, GpioUtil.DIRECTION_OUT);
    
    // set the edge state on the pins we will be listening for
    GpioUtil.setEdgeDetection(0, GpioUtil.EDGE_BOTH);
    GpioUtil.setEdgeDetection(7, GpioUtil.EDGE_BOTH);
    
    // configure GPIO pins 5, 6 as an OUTPUT;
    Gpio.pinMode(5, Gpio.OUTPUT);
    Gpio.pinMode(6, Gpio.OUTPUT);

    // configure GPIO 0 as an INPUT pin; enable it for callbacks
    Gpio.pinMode(0, Gpio.INPUT);
    Gpio.pullUpDnControl(0, Gpio.PUD_DOWN);        
    GpioInterrupt.enablePinStateChangeCallback(0);
    
    // configure GPIO 7 as an INPUT pin; enable it for callbacks
    Gpio.pinMode(7, Gpio.INPUT);
    Gpio.pullUpDnControl(7, Gpio.PUD_DOWN);        
    GpioInterrupt.enablePinStateChangeCallback(7);

    // continuously loop to prevent program from exiting
    for (;;) {
        Thread.sleep(5000);
    }
}
 
开发者ID:iot-labs,项目名称:communication,代码行数:55,代码来源:WiringPiGpioInterruptExample.java


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