本文整理汇总了Java中com.pi4j.wiringpi.Gpio.pullUpDnControl方法的典型用法代码示例。如果您正苦于以下问题:Java Gpio.pullUpDnControl方法的具体用法?Java Gpio.pullUpDnControl怎么用?Java Gpio.pullUpDnControl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.Gpio
的用法示例。
在下文中一共展示了Gpio.pullUpDnControl方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public void test(int gpio) {
int status = Gpio.wiringPiSetupGpio();
if (status != 0) {
throw new RuntimeException("Error initialising wiringPi: " + status);
}
Gpio.pinMode(gpio, Gpio.INPUT);
Gpio.pullUpDnControl(gpio, Gpio.PUD_UP);
int delay = 20;
System.out.println("Waiting " + delay + "s for events..., thread name=" + Thread.currentThread().getName());
if (Gpio.wiringPiISR(gpio, Gpio.INT_EDGE_BOTH, this) != 1) {
System.out.println("Error in wiringPiISR");
} else {
System.out.println("Sleeping for " + delay + "s");
SleepUtil.sleepSeconds(delay);
}
GpioUtil.unexport(gpio);
}
示例2: run
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Override
public void run() {
System.out.println(Thread.currentThread().getName()
+ " started on PIN " + pin);
Gpio.wiringPiSetupGpio();
Gpio.pinMode(pin, Gpio.OUTPUT);
Gpio.pullUpDnControl(pin, Gpio.PUD_DOWN);
Gpio.digitalWrite(pin, true);
while (!finish) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
stop();
}
}
Gpio.digitalWrite(pin, false);
System.out.println(Thread.currentThread().getName() + " finished.");
}
示例3: gpioIsrSetup
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private static void gpioIsrSetup() {
wiringPiSetup();
Gpio.pinMode(btnPin, Gpio.INPUT);
Gpio.pullUpDnControl(btnPin, Gpio.PUD_UP);
Gpio.pinMode(ledPin, Gpio.OUTPUT);
Gpio.pullUpDnControl(ledPin, Gpio.PUD_DOWN);
Gpio.digitalWrite(ledPin, false);
Gpio.wiringPiISR(btnPin, Gpio.INT_EDGE_FALLING, new GpioInterruptCallback() {
private final long debounceTime = 200;
@Override
public void callback(int pin) {
Gpio.delay(10);
long currentTime = System.currentTimeMillis();
if(currentTime > lastTime+debounceTime){
Gpio.digitalWrite(ledPin, Gpio.digitalRead(ledPin)==0?1:0);
logger.debug("GPIO PIN 0 detected. Led state: "+Gpio.digitalRead(ledPin));
}else{
logger.debug("Discard event "+currentTime);
}
lastTime=currentTime;
}
});
}
示例4: AudioPlayer
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public AudioPlayer() {
// initialize wiringPi library
// Gpio.wiringPiSetupGpio();
// GPIO output pin
Gpio.pinMode(17, Gpio.OUTPUT);
Gpio.pullUpDnControl(17, Gpio.PUD_DOWN);
}
示例5: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的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);
}
}
示例6: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的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);
}
}
示例7: WiringPiDigitalInputDevice
import com.pi4j.wiringpi.Gpio; //导入方法依赖的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);
}
示例8: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的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);
}
}
示例9: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的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);
}
}
示例10: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
// initialize wiringPi library
Gpio.wiringPiSetupGpio();
// GPIO output pin
Gpio.pinMode(17, Gpio.OUTPUT);
Gpio.pullUpDnControl(17, Gpio.PUD_DOWN);
Gpio.digitalWrite(17, false);
for (int i = 0; i < 30; i++) {
System.out.println("Iteration " + i);
Gpio.digitalWrite(17, true);
Thread.sleep(60000);
Gpio.digitalWrite(17, false);
Thread.sleep(500);
}
Gpio.digitalWrite(17, false);
// Gpio.digitalWrite(6, 1);
//
// Gpio.pwmWrite(12, 240);
// Gpio.pwmWrite(13, 240);
// // SoftPwm.softPwmWrite(12, i);
// Thread.sleep(5000);
//
// System.out.println("Running motors forward accelerating");
//
// for (int i = 0; i <= 480; i++) {
// Gpio.digitalWrite(5, 1);
// Gpio.digitalWrite(6, 1);
//
// Gpio.pwmWrite(12, i);
// Gpio.pwmWrite(13, i);
// // SoftPwm.softPwmWrite(12, i);
// Thread.sleep(40);
// }
//
// System.out.println("Running motors forward decelerating");
// for (int i = 480; i > 0; i--) {
// Gpio.digitalWrite(5, 1);
// Gpio.digitalWrite(6, 1);
//
// Gpio.pwmWrite(12, i);
// Gpio.pwmWrite(13, i);
// // SoftPwm.softPwmWrite(12, i);
// Thread.sleep(20);
// }
//
// Gpio.digitalWrite(5, 0);
// Gpio.digitalWrite(6, 1);
//
// Gpio.pwmWrite(12, 240);
// Gpio.pwmWrite(13, 240);
// // SoftPwm.softPwmWrite(12, i);
// Thread.sleep(5000);
//
// System.out.println("Running motors forward decelerating");
// for (int i = 480; i > 0; i--) {
// Gpio.digitalWrite(5, 1);
// Gpio.digitalWrite(6, 1);
//
// Gpio.pwmWrite(12, i);
// Gpio.pwmWrite(13, i);
// // SoftPwm.softPwmWrite(12, i);
// Thread.sleep(50);
// }
//
// Gpio.digitalWrite(5, 0);
// Gpio.digitalWrite(6, 0);
// Gpio.pwmWrite(12, 0);
// Gpio.pwmWrite(13, 0);
System.out.println("End of the demo.");
}