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


Java Pin类代码示例

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


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

示例1: RGBLed

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public RGBLed(DiodeType type,Pin red,Pin green,Pin blue) {
	this.type = type;
	this.pinR = red;
	this.pinG = green;
	this.pinB = blue;
	this.color = LedColor.OFF;
	gpio = GpioFactory.getInstance();
	int defaultValue = (DiodeType.ANODE_COMMON.equals(type)) ? 1 : 0;
	PinState defaultState = (DiodeType.ANODE_COMMON.equals(type)) ? PinState.HIGH : PinState.LOW;
	outRed = gpio.provisionSoftPwmOutputPin(pinR, "Red", defaultValue);
	outRed.setShutdownOptions(true, defaultState, PinPullResistance.OFF);
	outGreen = gpio.provisionSoftPwmOutputPin(pinG, "Green", defaultValue);
	outGreen.setShutdownOptions(true, defaultState, PinPullResistance.OFF);
	outBlue = gpio.provisionSoftPwmOutputPin(pinB, "Blue", defaultValue);
	outBlue.setShutdownOptions(true, defaultState, PinPullResistance.OFF);
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:17,代码来源:RGBLed.java

示例2: IRSend

import com.pi4j.io.gpio.Pin; //导入依赖的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

示例3: SwitchImpl

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public SwitchImpl (final RobotGPIO pi2goGPIO, Pin switchPin){

        button = pi2goGPIO.provisionDigitalInputPin(switchPin, PinPullResistance.PULL_UP);
        //button.setShutdownOptions(Boolean.TRUE, PinState.LOW, PinPullResistance.OFF);
//com.pi4j.io.gpio.exception.InvalidPinModeException: Invalid pin mode on pin [GPIO 14]; cannot setState() when pin mode is [input]
//at com.pi4j.io.gpio.GpioProviderBase.setState(GpioProviderBase.java:180)
//at com.pi4j.io.gpio.RaspiGpioProvider.setState(RaspiGpioProvider.java:150)
//	at com.pi4j.io.gpio.impl.GpioPinImpl.setState(GpioPinImpl.java:325)
//	at com.pi4j.io.gpio.impl.GpioControllerImpl.shutdown(GpioControllerImpl.java:939)
//	at com.pi4j.io.gpio.impl.GpioControllerImpl$ShutdownHook.run(GpioControllerImpl.java:888)

        // create and register gpio pin listeners
        button.addListener((GpioPinListenerDigital) (GpioPinDigitalStateChangeEvent event) -> {
            
            synchronized(this){
                if(event.getState().isLow()) lastLow = System.currentTimeMillis();
                if(event.getState().isHigh()) lastHigh = System.currentTimeMillis();
            }
            
            listeners.stream().forEach((listener) -> {
                listener.changedEvent(event.getState().isLow());
            });
        });
    }
 
开发者ID:fustinoni-net,项目名称:PiRobotPlatform,代码行数:25,代码来源:SwitchImpl.java

示例4: MotorControllerImpl

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public MotorControllerImpl(PWMOutput output,
		MotorControllerConfiguration configuration) {

	this.output = output;
	this.configuration = configuration;
	this.gpio = GpioFactory.getInstance();

	try {
		Pin myGPIOMotorPin = (Pin) FieldUtils.readDeclaredStaticField(
				RaspiPin.class, configuration.gpioPin());

		motorPin = gpio.provisionDigitalOutputPin(myGPIOMotorPin,
				configuration.name(), PinState.LOW);
		motorPin.setShutdownOptions(true, PinState.LOW);

	} catch (IllegalAccessException e) {
		LOGGER.error("Error on construct MotorControllerImpl", e);
	}

}
 
开发者ID:weiss19ja,项目名称:amos-ss16-proj2,代码行数:21,代码来源:MotorControllerImpl.java

示例5: initPins

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
private void initPins() {
    this.pins = new GpioPinDigitalOutput[16];

    int k = 0;
    for (Pin p : MCP23017Pin.ALL) {
        this.pins[k] = this.pins[k] = gpioCtrl.provisionDigitalOutputPin(provider, p, "MCP " + p.getName(), PinState.LOW);
        k++;
    }
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:10,代码来源:McpOutputController.java

示例6: addMcp

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
/**
 * Add a new MCP23017 GPIO expander chip to the manager. This allows the
 * assignment of 16 additional GPIO pins.
 *
 * Note that each chip assigned must have a different address.
 *
 * @param address The I2C address of the chip, in the range 0x20 to 0x27
 * @throws I2CFactory.UnsupportedBusNumberException If the bus # is invalid.
 * @throws IOException If the chip can't be communicated with.
 */
public void addMcp(int bus, int address)
        throws I2CFactory.UnsupportedBusNumberException, IOException {
    GpioProvider provider = new MCP23017GpioProvider(bus, address);
    for (Pin mcpPin : MCP23017Pin.ALL) {
        String name = mcpPin.getName() + " " + Integer.toHexString(address);
        NamedPin newPin = new NamedPin(name, mcpPin, provider);
        this.availablePins.add(newPin);
    }

}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:21,代码来源:GpioManager.java

示例7: parsePin

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
/**
 * Parse input value and translates it into GPIO Pin.
 * @param input Text value of pin number (following wiringPi convention) or
 * corresponding alphanumeric name.
 */
public static Pin parsePin(String input) {
	if (input==null || input.length()==0)
		return null;
	input = input.trim();
	if (input.matches("\\d+")) {
		int num = Integer.parseInt(input);
		return RaspiPin.getPinByAddress(num);
	}
	else {
		return RaspiPin.getPinByName(input);
	}
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:18,代码来源:GPIOUtils.java

示例8: setPinDetectorDevices

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public void setPinDetectorDevices(String... pinDetectorDevices) {
	if (pinDetectorDevices==null || pinDetectorDevices.length==0)
		this.pinDetectorDevices = null;
	else {
		this.pinDetectorDevices = new Pin[pinDetectorDevices.length];
		for (int i=0;i<pinDetectorDevices.length;i++) {
			this.pinDetectorDevices[i] = GPIOUtils.parsePin(pinDetectorDevices[i].trim());
		}
	}
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:11,代码来源:RoboToyServerController.java

示例9: IRReceive

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public IRReceive(Pin pin,PinPullResistance resistance,IRReceiveCallback callback) {
	this.pin = pin;
	this.resistance = resistance;
	this.callback = callback;
	running = new AtomicBoolean(false);
	pendingSignalSaturated = new AtomicBoolean();
	signalReceived = new Semaphore(0);
	pulseCount = new LongAdder();
       gpio = GpioFactory.getInstance();
       previousSignalPulseCount = 0;
       input =  gpio.provisionDigitalInputPin(pin, "IR_DETECTOR", resistance);
       input.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
       currentPulseStart = (System.nanoTime()-MAX_PULSE_NS);
       currentSignalStart = (onIsHigh) ? 0 : 1;
       currentPulse = input.isHigh() ? 0 : 1; 
       prevEdge = null;
       if (log.isLoggable(Level.FINEST)) {
       	log.log(Level.FINEST, "STARTING AT INDEX "+currentPulse+", START SIGNAL AT "+currentSignalStart);
       }
       input.addListener(new GpioPinListenerDigital() {			
		@Override
		public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
			switch (event.getEdge()) {
			case FALLING:
				onSignalFalling(event.getState());
				break;
			case RISING:
				onSignalRising(event.getState());
				break;
			default:
			}
		}
	});
       if (log.isLoggable(Level.INFO)) {
       	log.log(Level.INFO, "IR DETECTOR pin "+pin);
       }
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:38,代码来源:IRReceive.java

示例10: buildBeamDevice

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public void buildBeamDevice(Pin pinBeamDevice) {
	IRSend beamDevice = new IRSend(pinBeamDevice,PWMType.HARDWARE,38_000);
	beamDevice.setEncoder(beamEncoder);
	beamDevice.setNumRepeats(15);	// 16 signals total
	beamDevice.setDelayBetweenRepeats(beamEncoder.getHeaderOffPulse());
	context.setBeamDevice(beamDevice);
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:8,代码来源:RoboToyWeaponary.java

示例11: buildBeamDetectors

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public void buildBeamDetectors(PinPullResistance internalResistance,Pin... pinDetectorDevices) {
	IRBeamDecoder beamDecoder = IRBeamDecoder.forEncoder(beamEncoder);
	beamDecoder.setBitsPerByte(8);	// chunk together 4 data bits (low order in byte) with 4 checksum bits (high order in byte)
	beamDecoder.setChecksum(false);
	for (int pin_index=0;pin_index<pinDetectorDevices.length;pin_index++) {
		Pin pin = pinDetectorDevices[pin_index];
		IRReceive receiver = new IRReceive(pin,internalResistance,new RobotoyReceiver(pin_index,beamDecoder));
		receiver.setMinStartPulseDelay(beamEncoder.getHeaderOnPulse()*2/3);
		receiver.init();
	}
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:12,代码来源:RoboToyWeaponary.java

示例12: MFRC522

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public MFRC522(GpioController gpio,Pin pinNRSTPD,SpiChannel channel) throws IOException {	
	this.pinNRSTPD = pinNRSTPD;
	this.spiChannel = channel;
       spi = SpiFactory.getInstance(spiChannel,
               SpiDevice.DEFAULT_SPI_SPEED, // default spi speed 1 MHz
               SpiDevice.DEFAULT_SPI_MODE); // default spi mode 0

       rstOut =  gpio.provisionDigitalOutputPin(pinNRSTPD, "RC522RST");
       rstOut.setShutdownOptions(true, PinState.HIGH, PinPullResistance.OFF);
       rstOut.high();
	init();
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:13,代码来源:MFRC522.java

示例13: LedImpl

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public LedImpl(final RobotGPIO pi2goGPIO, final Pin ledPin, boolean onIsHigh) {

        if (onIsHigh){
            this.on = PinState.HIGH;
            this.off = PinState.LOW;
        }else{
            this.on = PinState.LOW;
            this.off = PinState.HIGH;
        }
        
        this.ledPin = ledPin;
        this.led = pi2goGPIO.provisionDigitalOutputPin(ledPin, off);
        this.led.setShutdownOptions(true, off);
    }
 
开发者ID:fustinoni-net,项目名称:PiRobotPlatform,代码行数:15,代码来源:LedImpl.java

示例14: MotorImpl

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public MotorImpl(final RobotGPIO pi2goGPIO, final Pin forwardPin, final Pin backwardPin) {
       forward = true;
       speed = 0;
       this.forwardPin = forwardPin;
       this.backwardPin = backwardPin;
       SoftPwm.softPwmCreate( forwardPin.getAddress(), 0, 100 );
SoftPwm.softPwmCreate( backwardPin.getAddress(), 0, 100 );
   }
 
开发者ID:fustinoni-net,项目名称:PiRobotPlatform,代码行数:9,代码来源:MotorImpl.java

示例15: IRSensorImpl

import com.pi4j.io.gpio.Pin; //导入依赖的package包/类
public IRSensorImpl (final RobotGPIO pi2goGPIO, final Pin IRPin){

        iRSensor = pi2goGPIO.provisionDigitalInputPin(IRPin, PinPullResistance.PULL_DOWN);
        //iRSensor.setShutdownOptions(Boolean.TRUE);
        
        // create and register gpio pin listeners
        iRSensor.addListener((GpioPinListenerDigital) (GpioPinDigitalStateChangeEvent event) -> {
            listeners.stream().forEach((listener) -> {
                listener.triggered(event.getState().isLow());
            });
        });
    }
 
开发者ID:fustinoni-net,项目名称:PiRobotPlatform,代码行数:13,代码来源:IRSensorImpl.java


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