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


Java GpioFactory类代码示例

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


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

示例1: provisionPwmOutputs

import com.pi4j.io.gpio.GpioFactory; //导入依赖的package包/类
private static GpioPinPwmOutput[] provisionPwmOutputs(final PCA9685GpioProvider gpioProvider) {
    GpioController gpio = GpioFactory.getInstance();
    GpioPinPwmOutput myOutputs[] = {
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_00, "Pulse 00"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_01, "Pulse 01"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_02, "Pulse 02"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_03, "Pulse 03"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_04, "Pulse 04"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_05, "Pulse 05"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_06, "Pulse 06"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_07, "Pulse 07"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_08, "Pulse 08"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_09, "Pulse 09"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_10, "Always ON"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_11, "Always OFF"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_12, "Servo pulse MIN"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_13, "Servo pulse NEUTRAL"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_14, "Servo pulse MAX"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_15, "not used")};
    return myOutputs;
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:22,代码来源:PCA9685GpioExample.java

示例2: provisionPwmOutputs

import com.pi4j.io.gpio.GpioFactory; //导入依赖的package包/类
private GpioPinPwmOutput[] provisionPwmOutputs(final PCA9685GpioProvider gpioProvider) {
    GpioController gpio = GpioFactory.getInstance();
    GpioPinPwmOutput myOutputs[] = {
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_00, "Servo 00"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_01, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_02, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_03, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_04, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_05, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_06, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_07, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_08, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_09, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_10, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_11, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_12, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_13, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_14, "not used"),
            gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_15, "not used")};
    return myOutputs;
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:22,代码来源:PCA9685GpioServoExample.java

示例3: main

import com.pi4j.io.gpio.GpioFactory; //导入依赖的package包/类
public static void main(String[] args) {

        System.out.println("<--Pi4J--> GPIO Frequency Example ... started.");

        // create gpio controller
        final GpioController gpio = GpioFactory.getInstance();

        // provision gpio pin #01 as an output pin and turn on
        final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, PinState.LOW);

        // continuous loop
        while(true) {
            pin.setState(true);
            pin.setState(false);
        }

        // stop all GPIO activity/threads by shutting down the GPIO controller
        // (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
        // gpio.shutdown();   <--- implement this method call if you wish to terminate the Pi4J GPIO controller
    }
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:21,代码来源:FrequencyGpioExample.java

示例4: PumpDiagGuiSingle

import com.pi4j.io.gpio.GpioFactory; //导入依赖的package包/类
/**
 * Creates new form MainWindow
 *
 * @throws com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException
 * @throws java.io.IOException
 */
public PumpDiagGuiSingle() throws I2CFactory.UnsupportedBusNumberException, IOException, IOException, InterruptedException {
    gpio = GpioFactory.getInstance(); // Singleton instance
    mcpProvider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x23);

    // Provision direction control pins as outputs
    System.out.println("Provisioning direction pin");
    dir = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A7, "Direction", PinState.LOW);

    // Provision step control pins as outputs
    System.out.println("Provisioning step pin");
    step = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A6, "Step", PinState.LOW);

    // Provision enable pins as outputs. 
    // Note that the pin state "high" means the pump is disabled;
    // the enable pump on the chip is inverted.
    System.out.println("Provisioning enable pin");
    enable = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A5, "~Enable", PinState.HIGH);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:25,代码来源:PumpDiagGuiSingle.java

示例5: GpioManager

import com.pi4j.io.gpio.GpioFactory; //导入依赖的package包/类
public GpioManager() {
    this.gpio = GpioFactory.getInstance();
    this.assignedPins = new ArrayList<NamedPin>();
    this.availablePins = new ArrayList<NamedPin>();

    // The following must be done in this long form 
    // due to the lack of pattern in true GPIO
    // pin numbering.
    availablePins.add(new NamedPin("GPIO 4", RaspiPin.GPIO_07, null));
    availablePins.add(new NamedPin("GPIO 5", RaspiPin.GPIO_20, null));
    availablePins.add(new NamedPin("GPIO 6", RaspiPin.GPIO_22, null));
    availablePins.add(new NamedPin("GPIO 12", RaspiPin.GPIO_26, null));
    availablePins.add(new NamedPin("GPIO 13", RaspiPin.GPIO_23, null));
    availablePins.add(new NamedPin("GPIO 16", RaspiPin.GPIO_27, null));
    availablePins.add(new NamedPin("GPIO 17", RaspiPin.GPIO_00, null));
    availablePins.add(new NamedPin("GPIO 19", RaspiPin.GPIO_24, null));
    availablePins.add(new NamedPin("GPIO 21", RaspiPin.GPIO_29, null));
    availablePins.add(new NamedPin("GPIO 20", RaspiPin.GPIO_28, null));
    availablePins.add(new NamedPin("GPIO 22", RaspiPin.GPIO_03, null));
    availablePins.add(new NamedPin("GPIO 23", RaspiPin.GPIO_04, null));
    availablePins.add(new NamedPin("GPIO 24", RaspiPin.GPIO_05, null));
    availablePins.add(new NamedPin("GPIO 25", RaspiPin.GPIO_06, null));
    availablePins.add(new NamedPin("GPIO 26", RaspiPin.GPIO_25, null));
    availablePins.add(new NamedPin("GPIO 27", RaspiPin.GPIO_02, null));
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:26,代码来源:GpioManager.java

示例6: RGBLed

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

示例7: IRSend

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

示例8: init

import com.pi4j.io.gpio.GpioFactory; //导入依赖的package包/类
public void init() throws IOException {
	
	if (isRunning())
		throw new IOException("Already running!");
	
	if (gpio==null)
		gpio = GpioFactory.getInstance();
	mfrc522 = new MFRC522(gpio,pinNRSTPD,spiChannel);
	
	final AtomicBoolean newThreadRunning = new AtomicBoolean(true);
	Thread pooling_thread = new Thread(()->{ checkRFIDContinuously(mfrc522,newThreadRunning,callback); });
	pooling_thread.setName("RFIDPooling");
	pooling_thread.setDaemon(true);
	pooling_thread.start();
	currentThreadRunning = newThreadRunning;
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:17,代码来源:RFIDRead.java

示例9: MotorControllerImpl

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

示例10: Led

import com.pi4j.io.gpio.GpioFactory; //导入依赖的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);
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:20,代码来源:Led.java

示例11: main

import com.pi4j.io.gpio.GpioFactory; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    System.out.println("<--Pi4J--> MCP4725 DAC Example ... started.");
    // create gpio controller
    final GpioController gpio = GpioFactory.getInstance();

    // create gpio provider
    final MCP4725GpioProvider gpioProvider = new MCP4725GpioProvider(I2CBus.BUS_1, MCP4725GpioProvider.MCP4725_ADDRESS_1);

    // create output pin
    final GpioPinAnalogOutput vout = gpio.provisionAnalogOutputPin(gpioProvider, MCP4725Pin.OUTPUT);

    // generate sinus wave on output pin
    for (int i = 0; i < 360; i++) {
        double y = Math.sin(Math.toRadians(i));
        y = y / 2 + 0.5;
        vout.setValue(y);
        if (i == 359) {
            i = 0;
        }
    }
}
 
开发者ID:iot-labs,项目名称:communication,代码行数:22,代码来源:MCP4725GpioExample.java

示例12: main

import com.pi4j.io.gpio.GpioFactory; //导入依赖的package包/类
public static void main(String[] args) {
    
    System.out.println("<--Pi4J--> GPIO Frequency Example ... started.");
    
    // create gpio controller
    final GpioController gpio = GpioFactory.getInstance();
    
    // provision gpio pin #01 as an output pin and turn on
    final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, PinState.LOW);

    // continuous loop
    while(true) {            
        pin.setState(true);
        pin.setState(false);
    }
    
    // stop all GPIO activity/threads by shutting down the GPIO controller
    // (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
    // gpio.shutdown();   <--- implement this method call if you wish to terminate the Pi4J GPIO controller        
}
 
开发者ID:iot-labs,项目名称:communication,代码行数:21,代码来源:FrequencyGpioExample.java

示例13: RasPi

import com.pi4j.io.gpio.GpioFactory; //导入依赖的package包/类
public RasPi(String n) {
	super(n);

	Platform platform = Platform.getLocalInstance();
	log.info(String.format("platform is %s", platform));
	if ("arm".equals(platform.getArch())) {
		// init I2C
		gpio = GpioFactory.getInstance();
		gpio01 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
		gpio03 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03);

	} else {
		// we should be running on a Raspberry Pi
		log.error("architecture is not arm");
	}

}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:18,代码来源:RasPi.java

示例14: init

import com.pi4j.io.gpio.GpioFactory; //导入依赖的package包/类
public void init(){
	try {
		_gpioController = GpioFactory.getInstance();
		_i2cbus = I2CFactory.getInstance(I2CBus.BUS_1);

		_temperatureSensor = _i2cbus.getDevice(0x40);
		_lightActuator = _gpioController.provisionDigitalMultipurposePin(RaspiPin.GPIO_00, "led", PinMode.DIGITAL_OUTPUT);
		_lightActuator.setShutdownOptions(true); // unexport on shutdown

		// monitor temperature changes
		// every change of more than 0.1C will notify SensorChangedListeners
		_scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
		_handle = _scheduledThreadPoolExecutor.scheduleAtFixedRate(temperatureReader, 0, 100, TimeUnit.MILLISECONDS);

	} catch (IOException e) {
		log.error("An error occurred whilst trying to read temperature from GPIO Pins.");
	}
}
 
开发者ID:wso2-incubator,项目名称:iot-server-appliances,代码行数:19,代码来源:AgentOperationManagerImpl.java

示例15: GPIOButton

import com.pi4j.io.gpio.GpioFactory; //导入依赖的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);
			}
		}
	});
}
 
开发者ID:SebiGo,项目名称:BrewControlServer,代码行数:31,代码来源:GPIOButton.java


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