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


Java Gpio.digitalRead方法代码示例

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


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

示例1: read

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public boolean[] read() {
	final boolean[] data = new boolean[8];
	Gpio.digitalWrite(CLK_INH, Gpio.HIGH);
	Gpio.digitalWrite(SH_LD, Gpio.LOW);
	Gpio.delayMicroseconds(1);
	Gpio.digitalWrite(SH_LD, Gpio.HIGH);
	Gpio.digitalWrite(CLK_INH, Gpio.LOW);

	for (int i = 7; i >= 0; i--) {
		Gpio.digitalWrite(CLK, Gpio.HIGH);
		Gpio.digitalWrite(CLK, Gpio.LOW);
		data[i] = Gpio.digitalRead(QH) == Gpio.HIGH ? true : false;
	}

	return data;
}
 
开发者ID:XDrake99,项目名称:WarpPI,代码行数:17,代码来源:ParallelToSerial.java

示例2: getDistanceTwoPins

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private double getDistanceTwoPins() {
    Gpio.digitalWrite(trig, Gpio.LOW);
    Tools.sleepMilliseconds(2);
    
    Gpio.digitalWrite(trig, Gpio.HIGH);
    Tools.sleepMilliseconds(10);
    Gpio.digitalWrite(trig, Gpio.LOW);

    while(!(Gpio.digitalRead(echo) == 1));
    long start = System.nanoTime();

    while(!(Gpio.digitalRead(echo) == 0));
    long end = System.nanoTime();
    
    return (end - start) / 1000. / 58.;
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:17,代码来源:UltrasonicHCSR04.java

示例3: 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.;
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:19,代码来源:UltrasonicHCSR04.java

示例4: getEncoderTurn

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
 * Updates the value of the counter used for this rotary encoder.
 * <p>The counter is used to represent the position of the shaft. If you turn to the right,
 * the counter is incremeted by one for each tick. If you turn to the left, the counter is 
 * then decremented by one for each tick.</p>
 * @see #getCounterValue()
 */
public void getEncoderTurn() {
    int lastDt = Gpio.digitalRead(dtPinNumber);
    
    while(Gpio.digitalRead(clkPinNumber) != Gpio.HIGH) {
        currentDt = Gpio.digitalRead(dtPinNumber);
        flag = 1;
    }
    
    if(flag == 1) {
        flag = 0;
        if(lastDt == Gpio.LOW && currentDt == Gpio.HIGH)
            globalCounter++;
        if(lastDt == Gpio.HIGH && currentDt == Gpio.LOW)
            globalCounter--;
    }
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:24,代码来源:RotaryEncoder.java

示例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);
    }
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:46,代码来源:WiringPiGpioExample.java

示例6: getValue

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Override
public boolean getValue() throws RuntimeIOException {
	return Gpio.digitalRead(gpio) == 1;
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:5,代码来源:WiringPiDigitalOutputDevice.java

示例7: detectSignal

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
 * Polls until an infrared signal is detected and then return this signal.
 * <p><b>! Attention !</b> Polling means ~100% of CPU for 1 core.</p>
 * @return the IRSignal corresponding to the newly detected infrared signal.
 */
public IRSignal detectSignal() {
    // We will store up to 100 pulse pairs (this is -a lot-).
    // Pair is high and low pulse (2 int per pulse).
    int[] signal = new int[200];
    // temporary storage timing
    int highPulse, lowPulse;
    
    boolean completeSignalDetected = false;
    int currentPulse = 0;
    // setted to true as soon as a new signal start to be detected
    boolean newSignalDetected = false;
    
    while(!completeSignalDetected) {
        highPulse = 0;
        lowPulse = 0;
        
        // HIGH / OFF
        while(Gpio.digitalRead(pinNumber) == 1 && !completeSignalDetected) {
            // pin is still HIGH
            
            // count off another few microseconds
            highPulse++;
            Gpio.delayMicroseconds(RESOLUTION);
            
            // If the pulse is too long, we timed out:
            // either nothing was received or the code is finished,
            if((highPulse * RESOLUTION >= MAX_PULSE) && newSignalDetected) {
                completeSignalDetected = true;
            }
        }
        if(!completeSignalDetected) {
            // we didn't time out so lets stash the reading
            signal[currentPulse * 2] = highPulse * RESOLUTION;
        }
        
        // LOW / ON
        // same as above for low pulse
        while(Gpio.digitalRead(pinNumber) == 0 && !completeSignalDetected) {
            // pin is still LOW
            
            if(!newSignalDetected)
                newSignalDetected = true;
            
            // count off another few microseconds
            lowPulse++;
            Gpio.delayMicroseconds(RESOLUTION);
            
            // If the pulse is too long, we timed out:
            // either nothing was received or the code is finished,
            // so print what we've grabbed so far and then reset
            if(lowPulse * RESOLUTION >= MAX_PULSE) {
                completeSignalDetected = true;
            }
        }
        if(!completeSignalDetected) {
            signal[currentPulse * 2 + 1] = lowPulse * RESOLUTION;
        }
        
        // we read one high-low pulse successfully, continue !
        currentPulse++;
    }
    
    return new IRSignal(signal);
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:70,代码来源:IRReceiver.java

示例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);
    }
}
 
开发者ID:iot-labs,项目名称:communication,代码行数:46,代码来源:WiringPiGpioExample.java


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