com.pi4j.io.gpio.Pin Java Examples
The following examples show how to use
com.pi4j.io.gpio.Pin.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignalSegmentImpl.java From osgi.iot.contest.sdk with Apache License 2.0 | 5 votes |
private GpioPinDigitalOutput setup(String name) { Pin pin = RaspiPin.getPinByName(name); if (pin == null) { info("Pin<{}> is null", name); return null; } for (GpioPin e : gpio.getProvisionedPins()) { if (e.getPin().equals(pin)) { gpio.unprovisionPin(e); break; } } return this.gpio.provisionDigitalOutputPin(pin); }
Example #2
Source File: SwitchSegmentImpl.java From osgi.iot.contest.sdk with Apache License 2.0 | 5 votes |
private GpioPinDigitalOutput setup(String name) { Pin pin = RaspiPin.getPinByName(name); if (pin == null) { info("Pin<{}> is null", name); return null; } for (GpioPin e : gpio.getProvisionedPins()) { if (e.getPin().equals(pin)) { gpio.unprovisionPin(e); break; } } return this.gpio.provisionDigitalOutputPin(pin); }
Example #3
Source File: MicroSwitchSegmentImpl.java From osgi.iot.contest.sdk with Apache License 2.0 | 5 votes |
@Activate void activate(Config config) { this.config = config; Pin pin = RaspiPin.getPinByName(config.pin()); if ( pin == null) { System.out.println("Pin is " + config.pin() + " is null"); } for (GpioPin e : gpio.getProvisionedPins()) { if (e.getPin().equals(pin)) { gpio.unprovisionPin(e); break; } } GpioPinDigitalInput microSwitch = gpio.provisionDigitalInputPin(pin, PinPullResistance.PULL_DOWN); microSwitch.addListener(new GpioPinListenerDigital() { @Override public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) { // display pin state on console if(event.getState() == PinState.LOW){ if (System.currentTimeMillis() > debounce) { System.out.println("RFID triggered at controller "+config.controller_id()); debounce = System.currentTimeMillis() + 1000L; trigger(config.rfid()); } else { System.out.println("ignored RFID triggered at controller "+config.controller_id()); } } } }); }
Example #4
Source File: MCP23017Binding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private void bindGpioPin(MCP23017BindingProvider provider, String itemName) { try { int address = provider.getBusAddress(itemName); MCP23017GpioProvider mcp = mcpProviders.get(address); if (mcp == null) { try { mcp = new MCP23017GpioProvider(I2CBus.BUS_1, address); mcp.setPollingTime(pollingInterval); } catch (UnsupportedBusNumberException ex) { throw new IllegalArgumentException("Tried to access not available I2C bus"); } mcpProviders.put(address, mcp); } Pin pin = provider.getPin(itemName); PinMode mode = provider.getPinMode(itemName); if (mode.equals(PinMode.DIGITAL_OUTPUT)) { GpioPinDigitalOutput output = gpio.provisionDigitalOutputPin(mcp, pin, itemName, provider.getDefaultState(itemName)); gpioPins.put(itemName, output); logger.debug("Provisioned digital output for {}", itemName); } else if (mode.equals(PinMode.DIGITAL_INPUT)) { GpioPinDigitalInput input = gpio.provisionDigitalInputPin(mcp, pin, itemName, PinPullResistance.OFF); input.setDebounce(20); input.addListener(this); gpioPins.put(itemName, input); logger.debug("Provisioned digital input for {}", itemName); } else { throw new IllegalArgumentException("Invalid Pin Mode in config " + mode.name()); } } catch (IOException exception) { logger.error("I/O error {}", exception.getMessage()); } }
Example #5
Source File: MCP3424Binding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private void bindGpioPin(MCP3424BindingProvider provider, String itemName) { try { int address = provider.getBusAddress(itemName); MCP3424GpioProvider mcp = mcpProviders.get(address); if (mcp == null) { try { int gain = provider.getGain(itemName); int resolution = provider.getResolution(itemName); mcp = new MCP3424GpioProvider(I2CBus.BUS_1, address, resolution, gain); mcp.setMonitorInterval(pollingInterval); } catch (UnsupportedBusNumberException ex) { throw new IllegalArgumentException("Tried to access not available I2C bus"); } mcpProviders.put(address, mcp); } mcp.setMonitorEnabled(false); Pin pin = provider.getPin(itemName); GpioPinAnalogInput input = gpio.provisionAnalogInputPin(mcp, pin, itemName); input.addListener(this); input.setTag(provider.getItem(itemName)); gpioPins.put(itemName, input); mcp.setEventThreshold(0, input); mcp.setMonitorEnabled(true); logger.debug("Provisioned analog input for {}", itemName); } catch (IOException exception) { logger.error("I/O error {}", exception.getMessage()); } }
Example #6
Source File: GpioControllable.java From SmartApplianceEnabler with GNU General Public License v2.0 | 4 votes |
protected Pin getGpio() { return RaspiPin.getPinByName("GPIO " + gpio); }
Example #7
Source File: MCP23017GenericBindingProvider.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * @return the pin */ public Pin getPin() { return pin; }
Example #8
Source File: MCP23017GenericBindingProvider.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * @param pin the pin to set */ public void setPin(Pin pin) { this.pin = pin; }
Example #9
Source File: MCP23017GenericBindingProvider.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * @return the pin */ @Override public Pin getPin(String itemName) { return getConfig(itemName).getPin(); }
Example #10
Source File: RCSwitch.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
public RCSwitch(Pin transmitterPin) { final GpioController gpio = GpioFactory.getInstance(); this.transmitterPin = gpio.provisionDigitalOutputPin(transmitterPin); }
Example #11
Source File: MCP3424GenericBindingProvider.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * @return the pin */ public Pin getPin() { return pin; }
Example #12
Source File: MCP3424GenericBindingProvider.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * @param pin the pin to set */ public void setPin(Pin pin) { this.pin = pin; }
Example #13
Source File: MCP3424GenericBindingProvider.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * @return the pin */ @Override public Pin getPin(String itemName) { return getConfig(itemName).getPin(); }
Example #14
Source File: PCA9685GpioExample.java From wyliodrin-server-nodejs with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("resource") public static void main(String args[]) throws Exception { System.out.println("<--Pi4J--> PCA9685 PWM Example ... started."); // This would theoretically lead into a resolution of 5 microseconds per step: // 4096 Steps (12 Bit) // T = 4096 * 0.000005s = 0.02048s // f = 1 / T = 48.828125 BigDecimal frequency = new BigDecimal("48.828"); // Correction factor: actualFreq / targetFreq // e.g. measured actual frequency is: 51.69 Hz // Calculate correction factor: 51.65 / 48.828 = 1.0578 // --> To measure actual frequency set frequency without correction factor(or set to 1) BigDecimal frequencyCorrectionFactor = new BigDecimal("1.0578"); // Create custom PCA9685 GPIO provider I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1); final PCA9685GpioProvider gpioProvider = new PCA9685GpioProvider(bus, 0x40, frequency, frequencyCorrectionFactor); // Define outputs in use for this example GpioPinPwmOutput[] myOutputs = provisionPwmOutputs(gpioProvider); // Reset outputs gpioProvider.reset(); // // Set various PWM patterns for outputs 0..9 final int offset = 400; final int pulseDuration = 600; for (int i = 0; i < 10; i++) { Pin pin = PCA9685Pin.ALL[i]; int onPosition = checkForOverflow(offset * i); int offPosition = checkForOverflow(pulseDuration * (i + 1)); gpioProvider.setPwm(pin, onPosition, offPosition); } // Set full ON gpioProvider.setAlwaysOn(PCA9685Pin.PWM_10); // Set full OFF gpioProvider.setAlwaysOff(PCA9685Pin.PWM_11); // Set 0.9ms pulse (R/C Servo minimum position) gpioProvider.setPwm(PCA9685Pin.PWM_12, SERVO_DURATION_MIN); // Set 1.5ms pulse (R/C Servo neutral position) gpioProvider.setPwm(PCA9685Pin.PWM_13, SERVO_DURATION_NEUTRAL); // Set 2.1ms pulse (R/C Servo maximum position) gpioProvider.setPwm(PCA9685Pin.PWM_14, SERVO_DURATION_MAX); // // Show PWM values for outputs 0..14 for (GpioPinPwmOutput output : myOutputs) { int[] onOffValues = gpioProvider.getPwmOnOffValues(output.getPin()); System.out.println(output.getPin().getName() + " (" + output.getName() + "): ON value [" + onOffValues[0] + "], OFF value [" + onOffValues[1] + "]"); } System.out.println("Press <Enter> to terminate..."); new Scanner(System.in).nextLine(); }
Example #15
Source File: MCP23017BindingProvider.java From openhab1-addons with Eclipse Public License 2.0 | 2 votes |
/** * @return the pin */ public Pin getPin(String itemName);
Example #16
Source File: MCP3424BindingProvider.java From openhab1-addons with Eclipse Public License 2.0 | 2 votes |
/** * @return Pin */ public Pin getPin(String itemName);