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


Java Gpio类代码示例

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


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

示例1: IRSend

import com.pi4j.wiringpi.Gpio; //导入依赖的package包/类
public IRSend(Pin pin, PWMType type, int carrierFrequency) {
    this.pin = pin;
    gpio = GpioFactory.getInstance();
    if (PWMType.SOFTWARE.equals(type))
    	pwm = gpio.provisionSoftPwmOutputPin(pin, "IR_PWM", 0);
    else
    	pwm = gpio.provisionPwmOutputPin(pin, "IR_PWM", 0);
    pwm.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
    pwm.setPwm(0);
    Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
    Gpio.pwmSetRange(MAX_PWM_LEVEL);
    
    setFrequency(carrierFrequency);
    
    if (log.isLoggable(Level.INFO)) {
    	log.log(Level.INFO, "IR LED pin "+pin+" PWM type "+type+" carrier frequency "+carrierFrequency+" Hz");
    }
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:19,代码来源:IRSend.java

示例2: send

import com.pi4j.wiringpi.Gpio; //导入依赖的package包/类
public void send(int[] pulses,int size) {
	if (log.isLoggable(Level.FINEST)) {
		StringBuilder pulse_as_text = new StringBuilder();
		for (int i=0;i<size;i++) {
			if (i>0)
				pulse_as_text.append(",");
        	if ((i%2)==1) {
        		pulse_as_text.append("(l:"+pulses[i]+")");
        	}
        	else {
        		pulse_as_text.append("(h:"+pulses[i]+")");
        	}    			
		}
		log.log(Level.FINEST,"Pulse: "+pulse_as_text.toString());
	}
    for(int i = 0; i < size; i++) {
    	if ((i%2)==1) {
    		Gpio.delayMicroseconds(pulses[i]); // off
    	}
    	else {
    		pulse(pulses[i]); // on
    	}
    }
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:25,代码来源:IRSend.java

示例3: 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

示例4: 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);
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:19,代码来源:ButtonTestWiringPi.java

示例5: 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();
	}
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:27,代码来源:Pi4jPwmTest.java

示例6: 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");
}
 
开发者ID:DexterInd,项目名称:PivotPi,代码行数:28,代码来源:WiringPiPinAltExample.java

示例7: 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

示例8: 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

示例9: 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

示例10: setPWM

import com.pi4j.wiringpi.Gpio; //导入依赖的package包/类
/**
 * Sets for each full pulse of the PWM signal, the tick where the signal turns off (low).
 * 
 * <p>The rangeGenerator is used to define the range of values that the off tick can take.
 * As an example, a rangeGenerator of 20000 and an off value of 5000 means that
 * each PWM full pulse is composed of 25% high signal, followed by 75% of low signal.</p>
 * 
 * <p><b>! Attention !</b> when using the PCA9685, the maximum rangeGenerator is 4096 (maximum 12-bits value).</p>
 * 
 * <p>If you use a higher value for the off than for the rangeGenerator, we will set
 * the off value to the rangeGenerator value.</p>
 * 
 * <p>Note that an off value of zero will stop the PWM signal.</p>
 * @param off the tick where the signal turns off (low). 0 to stop the PWM signal.
 * @see PWMComponent#setPWM(int, long)
 */
public void setPWM(int off) {
    off = Math.max(off, 0);
    off = Math.min(off, rangeGenerator);
    
    if(stop)
        off = 0;
    
    if(selectedMode == PCA9685_MODE) {
        // with the PCA9685, a pulse is composed of 4096 ticks (12bits).
        // the range of values for the on, off ticks, must then be adapted to this 0..4096 range.
        off = (int)(((double)off / (double)rangeGenerator) * PCA9685_PULSE_TICKS);
        
        pca9685.setPWM(channel, 0, off);
    } else if(selectedMode == RPI_PWM_PIN_MODE) {
        Gpio.pwmWrite(pin.getPin().getWiringPiNb(), off);
    }
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:34,代码来源:PWMComponent.java

示例11: 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.");
}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:22,代码来源:CoctailMachine.java

示例12: 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	
}
 
开发者ID:MHAVLOVICK,项目名称:Sketchy,代码行数:18,代码来源:RaspberryPIServoController.java

示例13: 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;
        }
    });
}
 
开发者ID:marcandreuf,项目名称:sunfounder-sensors-raspi-4j,代码行数:27,代码来源:Ex13_ButtonISR.java

示例14: setFrequency

import com.pi4j.wiringpi.Gpio; //导入依赖的package包/类
public void setFrequency(double frequency) {
    int pwmClockDivisor = (int) ((double)DEFAULT_RPI_PWM_CLOCK_FREQUENCY / (frequency * (double)MAX_PWM_LEVEL));
    Gpio.pwmSetClock(pwmClockDivisor);
    if (log.isLoggable(Level.FINE)) {
    	log.log(Level.FINE, "Clock Divisor "+pwmClockDivisor+" DEFAULT_RPI_PWM_CLOCK_FREQUENCY "+DEFAULT_RPI_PWM_CLOCK_FREQUENCY);
    }
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:8,代码来源:IRSend.java

示例15: sendBeam

import com.pi4j.wiringpi.Gpio; //导入依赖的package包/类
@Override
  public void sendBeam(byte[] message) throws Exception {
  	if (encoder==null)
  		throw new Exception("Could not send beam. Did not setup encoder yet!");
  	int signal[] = encoder.getEncodedSignal(message);
  	send(signal);
for (int i=0;i<numRepeats;i++) {
	Gpio.delayMicroseconds(delayBetweenRepeats); // off
	send(signal);
}
  }
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:12,代码来源:IRSend.java


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