本文整理汇总了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);
}
示例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");
}
}
示例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());
});
});
}
示例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);
}
}
示例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++;
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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();
}
示例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);
}
示例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 );
}
示例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());
});
});
}