本文整理汇总了Java中com.pi4j.io.gpio.PinPullResistance类的典型用法代码示例。如果您正苦于以下问题:Java PinPullResistance类的具体用法?Java PinPullResistance怎么用?Java PinPullResistance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PinPullResistance类属于com.pi4j.io.gpio包,在下文中一共展示了PinPullResistance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPinDetectorResistor
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
public void setPinDetectorResistor(String pinDetectorResistor) {
if (pinDetectorResistor==null || pinDetectorResistor.trim().length()==0)
this.pinDetectorResistor = PinPullResistance.OFF;
else {
switch (pinDetectorResistor.trim().toUpperCase()) {
case "UP":
this.pinDetectorResistor = PinPullResistance.PULL_UP;
break;
case "DOWN":
this.pinDetectorResistor = PinPullResistance.PULL_DOWN;
break;
case "OFF":
this.pinDetectorResistor = PinPullResistance.OFF;
break;
default:
throw new UnsupportedOperationException("Unknown value for internal resistor used with IR detector pin: "+pinDetectorResistor);
}
}
}
示例2: RGBLed
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的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);
}
示例3: IRSend
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的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");
}
}
示例4: SwitchImpl
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的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());
});
});
}
示例5: Led
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
/**
* Constructs a led with its number
* @param ledNb the led number (1 or 2)
*/
protected Led(int ledNb) {
GpioController gpio = GpioFactory.getInstance();
// provision the corresponding gpio pin as an output pin
// and make sure it is set to LOW at startup
if(ledNb == 1) {
ledOutputPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "led1", PinState.LOW);
} else {
ledOutputPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02, "led2", PinState.LOW);
}
// configure the pin shutdown behavior; these settings will be
// automatically applied to the pin when the application is terminated
// ensure that the LED is turned OFF when the application is shutdown
ledOutputPin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
}
示例6: FlowMeterFlux
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
public FlowMeterFlux(GpioController gpioController, Pin flowMeterPin) {
this.gpio = gpioController;
this.pin = flowMeterPin;
flowMeterEmitter = EmitterProcessor.create();
flowMeterSink = flowMeterEmitter.connectSink();
gpioInput = gpio.provisionDigitalInputPin(pin, PinPullResistance.PULL_DOWN);
gpioInput.addListener(new GpioPinListenerDigital() {
long counter = 0L;
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
counter++;
// System.out.println(
// "--> GPIO PIN STATE CHANGE " + event.getPin() + " " + event.getState() + " --> " + counter);
// if (flowMeterSink.requestedFromDownstream() > 0)
// System.out.println("--> " + flowMeterSink.emit(counter * MILILITERS_PER_IMPULS));
flowMeterSink.emit(counter * MILILITERS_PER_IMPULS);
// else
// System.err.println("Error: Missed FlowMeter reading because of missing subscriber request.");
}
});
}
示例7: setup
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
@Override
protected void setup(String[] args) {
wiringPiSetup();
ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
sigPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);
sigPin.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
if(event.getState().isLow()){
logger.debug("Magic cup connected.");
ledPin.high();
}else{
ledPin.low();
}
}
});
logger.debug("Magic cup sensor ready!");
}
示例8: setup
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
@Override
protected void setup(String[] args) {
wiringPiSetup();
ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
tiltSwitch = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);
tiltSwitch.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
logger.debug("Tilt state: "+event.getState());
if(event.getState().isHigh()){
ledPin.high();
}else{
ledPin.low();
}
}
});
logger.debug("Tilt switch sensor ready!");
}
示例9: setup
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
@Override
protected void setup(String[] args) {
wiringPiSetup();
ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
lightBreakPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);
lightBreakPin.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
if(event.getState().isHigh()){
logger.debug("Light beam is broken");
ledPin.high();
}else{
ledPin.low();
}
}
});
logger.debug("Light break ready!");
}
示例10: setup
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
@Override
protected void setup(String[] args) {
super.setup(args);
if(args.length == 1){
device_fileName = args[0];
}else{
throw new RuntimeException(
"Please provide a device file name from "
+Ex16_Ds18b20.W1_DEVICES_PATH);
}
ledRed = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03);
ledGreen = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04);
ledBlue = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05);
beep = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_08);
joyStick_Z = gpio.provisionDigitalInputPin(RaspiPin.GPIO_06, PinPullResistance.PULL_UP);
joyStick_Z.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent gpdsce) {
sys_state = PinState.LOW;
logger.debug("interrupt occur !");
}
});
sys_state = PinState.HIGH;
logger.debug("Temperature monitor ready!");
}
示例11: setup
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
@Override
protected void setup(String[] args) {
wiringPiSetup();
ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);
myButton.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
if(event.getState().isLow()){
logger.debug("Button is pressed");
ledPin.toggle();
}
}
});
logger.debug("Button sensor ready!");
}
示例12: startListenDigitalPin
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
private boolean startListenDigitalPin(MessageParsedInfo messageParsedInfo) {
int pinNum = (Integer)messageParsedInfo.getParsedValues()[0];
GpioPinListenerDigital listener = digitalListeners.get(pinNum);
if(listener == null) {
listener = createDigitalListener(pinNum);
GpioPinDigitalInput pin = (GpioPinDigitalInput)getPin(pinNum);
pin.setMode(PinMode.DIGITAL_INPUT);
pin.setPullResistance(PinPullResistance.PULL_DOWN);
digitalListeners.put(pinNum, listener);
pin.addListener(listener);
}
return true;
}
示例13: startListenAnalogPin
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
private boolean startListenAnalogPin(MessageParsedInfo messageParsedInfo) {
int pinNum = (Integer)messageParsedInfo.getParsedValues()[0];
GpioPinListenerAnalog listener = analogListeners.get(pinNum);
if(listener == null) {
listener = createAnalogListener(pinNum);
GpioPinAnalogInput pin = (GpioPinAnalogInput)getPin(pinNum);
pin.setMode(PinMode.ANALOG_INPUT);
pin.setPullResistance(PinPullResistance.PULL_DOWN);
analogListeners.put(pinNum, listener);
pin.addListener(listener);
}
return true;
}
示例14: GPIOButton
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
/**
* Constructing a software representation of an GPIO connected hardware
* button.
*
* @param pin
* the GPIO pin that the button is connected to.
*/
public GPIOButton(Pin pin) {
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// provision gpio pin as an input pin with its internal pull down
// resistor enabled
final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(pin, PinPullResistance.PULL_DOWN);
// register an anonymous listener with the pi4j library to connect to
// our internal listeners.
myButton.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
event.getState();
if (event.getState() == PinState.HIGH) {
setState(ButtonState.ON);
} else {
setState(ButtonState.OFF);
}
}
});
}
示例15: main
import com.pi4j.io.gpio.PinPullResistance; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, FileNotFoundException {
lp0 = new FileOutputStream(new File("/dev/usb/lp0"));
GpioController gpio;
GpioPinDigitalInput printButton;
gpio = GpioFactory.getInstance();
printButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_04, PinPullResistance.PULL_DOWN);
printButton.addListener(new ButtonListener());
System.out.println("Start pi cam");
picam = new Camera();
new Thread(picam).start();
try {
printer = new TMT20();
} catch (SecurityException | UsbException e) {
e.printStackTrace();
}
System.out.println("Press the big button !");
}