本文整理汇总了Java中com.pi4j.wiringpi.Gpio.pinMode方法的典型用法代码示例。如果您正苦于以下问题:Java Gpio.pinMode方法的具体用法?Java Gpio.pinMode怎么用?Java Gpio.pinMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.Gpio
的用法示例。
在下文中一共展示了Gpio.pinMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) {
int pin_number = 13;
Gpio.wiringPiSetupGpio();
Gpio.pinMode(pin_number, Gpio.PWM_OUTPUT);
Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
//Gpio.pwmSetClock(384);
//Gpio.pwmSetRange(1000);
Gpio.pwmSetClock(187);
Gpio.pwmSetRange(1024);
try {
for (int i=0; i<1000; i+=10) {
Gpio.pwmWrite(pin_number, i);
Thread.sleep(100);
}
for (int i=1000; i>0; i-=10) {
Gpio.pwmWrite(pin_number, i);
Thread.sleep(100);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例3: 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 ALT MODE test program");
// setup wiringPi
if (Gpio.wiringPiSetup() == -1) {
System.out.println(" ==>> GPIO SETUP FAILED");
return;
}
// NOTE, this example does not really do anything visible, its just an usage example of settings ALT pin modes
// iterate through all the available pin modes
Gpio.pinMode (7, Gpio.INPUT);
Gpio.pinMode (7, Gpio.OUTPUT);
Gpio.pinMode (7, Gpio.ALT0);
Gpio.pinMode (7, Gpio.ALT1);
Gpio.pinMode (7, Gpio.ALT2);
Gpio.pinMode (7, Gpio.ALT3);
Gpio.pinMode (7, Gpio.ALT4);
Gpio.pinMode (7, Gpio.ALT5);
System.out.println("Exiting WiringPiPinAltExample");
}
示例4: getDistanceOnePin
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private double getDistanceOnePin() {
Gpio.pinMode(trig, Gpio.OUTPUT);
Gpio.digitalWrite(trig, Gpio.LOW);
Tools.sleepMilliseconds(2);
Gpio.digitalWrite(trig, Gpio.HIGH);
Tools.sleepMilliseconds(10);
Gpio.digitalWrite(trig, Gpio.LOW);
Gpio.pinMode(trig, Gpio.INPUT);
while(!(Gpio.digitalRead(trig) == 1));
long start = System.nanoTime();
while(!(Gpio.digitalRead(trig) == 0));
long end = System.nanoTime();
return (end - start) / 1000. / 58.;
}
示例5: 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.");
}
示例6: tearDownPins
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private synchronized void tearDownPins(){
// turn off pen
try{
String servoPenOffCommand = buildServoCommand(properties.getPenPinNumber(), 0);
FileUtils.writeStringToFile(servoPipeFile, servoPenOffCommand);
} catch (Exception e){
throw new RuntimeException(e.getMessage());
}
Gpio.pinMode(properties.getPenPinNumber(), Gpio.OUTPUT);
Gpio.digitalWrite(properties.getLeftMotorEnablePinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getLeftMotorDirectionPinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getLeftMotorStepPinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getRightMotorEnablePinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getRightMotorDirectionPinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getRightMotorStepPinNumber(), false); // turn off old pin
}
示例7: 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;
}
});
}
示例8: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) throws PlatformAlreadyAssignedException {
// Default platform is Raspberry -> Explicit assign the target platform
// TODO : Use PI4J_PLATFORM env variable ??
PlatformManager.setPlatform(Platform.ODROID);
// PI4J Init
if (Gpio.wiringPiSetup() == -1) {
log.error(" ==>> GPIO SETUP FAILED");
return;
}
// GPIO 1 init as Output
GpioUtil.export(1, GpioUtil.DIRECTION_OUT);
Gpio.pinMode (1, Gpio.OUTPUT) ;
// Force low state for GPIO 1
Gpio.digitalWrite(1, Gpio.LOW);
// Vertx event timer
Vertx.vertx().setPeriodic(1000, l -> {
// Blink led every seconds
if (Gpio.digitalRead(1) != Gpio.LOW) {
log.info("Switch off ...");
Gpio.digitalWrite(1, Gpio.LOW);
}
else {
log.info("Switch on ...");
Gpio.digitalWrite(1, Gpio.HIGH);
}
});
}
示例9: WiringPiDigitalOutputDevice
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
WiringPiDigitalOutputDevice(String key, DeviceFactoryInterface deviceFactory, int gpio, boolean initialValue) throws RuntimeIOException {
super(key, deviceFactory);
this.gpio = gpio;
try {
if (GpioUtil.isExported(gpio)) {
GpioUtil.setDirection(gpio, initialValue ? GpioUtil.DIRECTION_HIGH : GpioUtil.DIRECTION_LOW);
} else {
GpioUtil.export(gpio, initialValue ? GpioUtil.DIRECTION_HIGH : GpioUtil.DIRECTION_LOW);
}
Gpio.pinMode(gpio, Gpio.OUTPUT);
} catch (RuntimeException re) {
throw new RuntimeIOException(re);
}
}
示例10: WiringPiPwmOutputDevice
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
WiringPiPwmOutputDevice(String key, DeviceFactoryInterface deviceFactory, PwmType pwmType,
int range, int gpio, float initialValue) throws RuntimeIOException {
super(key, deviceFactory);
this.pwmType = pwmType;
this.gpio = gpio;
this.value = initialValue;
this.range = range;
switch (pwmType) {
case HARDWARE:
if (GpioUtil.isExported(gpio)) {
GpioUtil.setDirection(gpio, GpioUtil.DIRECTION_OUT);
} else {
GpioUtil.export(gpio, GpioUtil.DIRECTION_OUT);
}
Gpio.pinMode(gpio, Gpio.PWM_OUTPUT);
// Have to call this after setting the pin mode! Yuck
Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
Gpio.pwmWrite(gpio, Math.round(initialValue * range));
break;
case SOFTWARE:
int status = SoftPwm.softPwmCreate(gpio, Math.round(initialValue * range), range);
if (status != 0) {
throw new RuntimeIOException("Error setting up software controlled PWM GPIO on BCM pin " +
gpio + ", status=" + status);
}
break;
}
}
示例11: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: " + WiringPiRawPerfTest.class.getName() + " <pin-number> [<iterations>]");
System.exit(1);
}
final int pin = Integer.parseInt(args[0]);
final int iterations = args.length > 1 ? Integer.parseInt(args[1]) : DEFAULT_ITERATIONS;
Gpio.wiringPiSetupGpio();
if (GpioUtil.isExported(pin)) {
GpioUtil.setDirection(pin, GpioUtil.DIRECTION_OUT);
} else {
GpioUtil.export(pin, GpioUtil.DIRECTION_OUT);
}
Gpio.pinMode(pin, Gpio.OUTPUT);
for (int j=0; j<5; j++) {
long start_nano = System.nanoTime();
for (int i=0; i<iterations; i++) {
Gpio.digitalWrite(pin, true);
Gpio.digitalWrite(pin, false);
}
long duration_ns = (System.nanoTime() - start_nano);
System.out.format("Duration for %d iterations: %.4fs%n",
Integer.valueOf(iterations), Float.valueOf(((float)duration_ns) / 1000 / 1000 / 1000));
}
GpioUtil.unexport(pin);
}
示例12: Pi4jPwmOutputDevice
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
Pi4jPwmOutputDevice(String key, DeviceFactoryInterface deviceFactory, GpioController gpioController,
PwmType pwmType, int gpio, float initialValue, int range) throws RuntimeIOException {
super(key, deviceFactory);
this.pwmType = pwmType;
this.gpio = gpio;
this.value = initialValue;
this.range = range;
//pin = RaspiBcmPin.getPinByAddress(gpio);
//pin.getSupportedPinModes().contains(PinMode.PWM_OUTPUT);
switch (pwmType) {
case HARDWARE:
//pwmOutputPin = gpioController.provisionPwmOutputPin(pin, "PWM output for BCM GPIO " + gpio,
// Math.round(value * range));
Gpio.pinMode(gpio, Gpio.PWM_OUTPUT);
// Have to call this after setting the pin mode! Yuck
Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
Gpio.pwmWrite(gpio, Math.round(initialValue * range));
break;
case SOFTWARE:
//pwmOutputPin = gpioController.provisionSoftPwmOutputPin(
// pin, "PWM output for BCM GPIO " + gpio, Math.round(initialValue * range));
int status = SoftPwm.softPwmCreate(gpio, Math.round(initialValue * range), range);
if (status != 0) {
throw new RuntimeIOException("Error setting up software controlled PWM GPIO on BCM pin " +
gpio + ", status=" + status);
}
}
}
示例13: UltrasonicHCSR04
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
* Constructor for an ultrasonic sensor HCSR04 using a specific Gpio trigger pin
* and a specific Gpio echo pin.
* @param trigPin the pin to use to trigger signals.
* @param echoPin the pin to use to detect echo signals.
*/
public UltrasonicHCSR04(GPIOPin trigPin, GPIOPin echoPin) {
singlePin = false;
trig = trigPin.getPin().getWiringPiNb();
echo = echoPin.getPin().getWiringPiNb();
if(trig == echo)
throw new RaspoidException("The selected Gpio pins for the ultrasonic sensor can't be the same.");
Gpio.pinMode(trig, Gpio.OUTPUT);
Gpio.pinMode(echo, Gpio.INPUT);
}
示例14: RotaryEncoder
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
* Constructor for a new rotary encoder using specific GPIO pin for sw, dt and clk pins.
* @param swPin GPIO pin corresponding to the push button of the encoder.
* @param dtPin GPIO pin corresponding to the data signal from the encoder.
* @param clkPin GPIO pin corresponding to the clock from the encoder.
*/
public RotaryEncoder(GPIOPin swPin, GPIOPin dtPin, GPIOPin clkPin) {
super(swPin, false);
this.dtPinNumber = dtPin.getPin().getWiringPiNb();
this.clkPinNumber = clkPin.getPin().getWiringPiNb();
Gpio.pinMode(dtPinNumber, Gpio.INPUT);
Gpio.pinMode(clkPinNumber, Gpio.INPUT);
}
示例15: ServoMotorCallibration
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
* Constructor for a new callibrator.
* @param minValue the minimum pulse length value, in ms.
* @param maxValue the maximum pulse length value, in ms.
*/
public ServoMotorCallibration(int minValue, int maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
Gpio.wiringPiSetup();
pinNumber = PWMPin.PWM1.getPin().getWiringPiNb();
Gpio.pinMode(pinNumber, Gpio.PWM_OUTPUT);
Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
int pwmRangeGenerator = 20000;// 20ms
int targetFrequency = 50; // Hz
int pwmClockDivisor = ServoMotor.DEFAULT_RPI_PWM_CLOCK_FREQUENCY / (targetFrequency * pwmRangeGenerator);
Gpio.pwmSetClock(pwmClockDivisor);
Gpio.pwmSetRange(pwmRangeGenerator);
}