當前位置: 首頁>>代碼示例>>Java>>正文


Java GpioFactory.getInstance方法代碼示例

本文整理匯總了Java中com.pi4j.io.gpio.GpioFactory.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java GpioFactory.getInstance方法的具體用法?Java GpioFactory.getInstance怎麽用?Java GpioFactory.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.pi4j.io.gpio.GpioFactory的用法示例。


在下文中一共展示了GpioFactory.getInstance方法的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: 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

示例3: 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

示例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: 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

示例6: 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

示例7: 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

示例8: main

import com.pi4j.io.gpio.GpioFactory; //導入方法依賴的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 !");

}
 
開發者ID:pierre-muth,項目名稱:selfpi,代碼行數:25,代碼來源:PrintImage.java

示例9: OpenSprinklerGpioApi

import com.pi4j.io.gpio.GpioFactory; //導入方法依賴的package包/類
/**
 * Constructor for the OpenSprinkler PI class to create a connection to the OpenSprinkler PI
 * device for control and obtaining status info using the GPIO.
 *
 * @param stations The number of stations to control on the OpenSprinkler PI device.
 */
public OpenSprinklerGpioApi(int stations) {
    this.numberOfStations = stations;
    this.stationState = new boolean[stations];

    for (int i = 0; i < stations; i++) {
        stationState[i] = false;
    }

    gpio = GpioFactory.getInstance();

    /* Initialize the OpenSprinkler Pi */
    SR_CLK_OUTPUT_PIN = gpio.provisionDigitalOutputPin(SR_CLK_PIN);
    SR_NOE_OUTPUT_PIN = gpio.provisionDigitalOutputPin(SR_NOE_PIN);
    SR_NOE_OUTPUT_PIN.high(); /* Disable shift register output */
    SR_DAT_OUTPUT_PIN = gpio.provisionDigitalOutputPin(SR_DAT_PIN);
    SR_LAT_OUTPUT_PIN = gpio.provisionDigitalOutputPin(SR_LAT_PIN);
    SR_NOE_OUTPUT_PIN.low(); /* Disable shift register output */

    pullStationState();
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:27,代碼來源:OpenSprinklerGpioApi.java

示例10: PhotoramaKeypadTesting

import com.pi4j.io.gpio.GpioFactory; //導入方法依賴的package包/類
public PhotoramaKeypadTesting() 
{
    logger = Logger.getLogger( getClass().getName() );
    
    try 
    {
        camera = new RaspberryPiCamera();

        
        
        Thread.sleep(1000);

        gpio = GpioFactory.getInstance();

        configureKeypadPins(gpio, camera);
    } 
    catch (Exception ex) 
    {
        logger.log(Level.SEVERE, null, ex);
    }
}
 
開發者ID:onebeartoe,項目名稱:photorama,代碼行數:22,代碼來源:PhotoramaKeypadTesting.java

示例11: PiService

import com.pi4j.io.gpio.GpioFactory; //導入方法依賴的package包/類
/**
 * PiService creator. Record itself as a managed service.
 * 
 */
public PiService() {
	
	gpioController = GpioFactory.getInstance();

	String[] clazzes = new String[] { ManagedService.class.getName() };
	// register the class as a managed service.
	Hashtable<String, Object> properties = new Hashtable<String,Object>();
	properties.put(Constants.SERVICE_PID, this.getClass().getName());

	Activator.bc.registerService(clazzes, this, properties);
	
	Activator.log(LogService.LOG_INFO, "Registered "
			+ this.getClass().getName() +  ", Pid = "
			+ (String) properties.get(Constants.SERVICE_PID));
}
 
開發者ID:lathil,項目名稱:Ptoceti,代碼行數:20,代碼來源:PiService.java

示例12: main

import com.pi4j.io.gpio.GpioFactory; //導入方法依賴的package包/類
public static void main(String [] args) throws Exception
{        
    GpioController gpio = GpioFactory.getInstance();
    
    String outpath = System.getProperty("user.home") + "/lizard-enclosure/photos";
    Camera camera = new RaspberryPiCamera();
    camera.setOutputPath(outpath);
            
    LizardEnclosureSevice lizardEnclosureSevice = new RaspberryPiLizardEnclosureSevice(camera);
    
    GpioPinListenerDigital selfieListener = lizardEnclosureSevice.newSelfieListener();
    
    GpioPinDigitalInput selfieSensorPin = lizardEnclosureSevice.provisionSelfiePin(gpio);
    selfieSensorPin.addListener(selfieListener);
    
    System.out.println("Ctrl+C to quit");
    while(true)
    {
        Sleeper.sleepo(1000);
    }
}
 
開發者ID:onebeartoe,項目名稱:lizard-enclosure,代碼行數:22,代碼來源:SelfieSensorTest.java

示例13: initializeIO

import com.pi4j.io.gpio.GpioFactory; //導入方法依賴的package包/類
public void initializeIO() {
	GpioController controller = GpioFactory.getInstance();
	m_controlPin = controller.provisionDigitalOutputPin(
			PinTable2.get(controlPin), PinStateTable2.get(controlPinState));
	m_statePin = controller.provisionDigitalInputPin(
			PinTable2.get(statePin),
			PinPullResistanceTable2.get(statePinResistance));

	m_statePin.addListener(m_stateListener);

	if (m_statePin.isHigh())
		m_doorState = doorStateEnum.CLOSED;
	else
		m_doorState = doorStateEnum.OPEN;

}
 
開發者ID:mitchellriley,項目名稱:OpenGarageServer,代碼行數:17,代碼來源:GarageDoor.java

示例14: LedManager

import com.pi4j.io.gpio.GpioFactory; //導入方法依賴的package包/類
/**
 * Constructor of class.
 * 
 * @param pin1
 *            Pin for first line of led.
 * @param pin2
 *            Pin for second line of led.
 * @param pin3
 *            Pin for third line of led.
 */
public LedManager(Pin pin1, Pin pin2, Pin pin3) {
	GpioController gpio = GpioFactory.getInstance();
	this.pin1 = gpio.provisionDigitalOutputPin(pin1, "MyLED", PinState.LOW);

	this.pin2 = gpio.provisionDigitalOutputPin(pin2, "MyLED", PinState.LOW);

	this.pin3 = gpio.provisionDigitalOutputPin(pin3, "MyLED", PinState.LOW);

	List<GpioPinDigitalOutput> gpioLed = new ArrayList<GpioPinDigitalOutput>();
	gpioLed.add(this.pin1);
	gpioLed.add(this.pin2);
	gpioLed.add(this.pin3);

	ledBlinking = new LedBlinking(gpioLed);
}
 
開發者ID:benoitm76,項目名稱:F1TelemetryOnRpi,代碼行數:26,代碼來源:LedManager.java

示例15: main

import com.pi4j.io.gpio.GpioFactory; //導入方法依賴的package包/類
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {

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

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

        // create custom MCP3424 GPIO provider
        final MCP3424GpioProvider provider = new MCP3424GpioProvider(I2CBus.BUS_1, 0x6C, 18, 1);

        // provision gpio input pins from MCP3424
        GpioPinAnalogInput inputs[] = { gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH0, "Channel-0"),
                gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH1, "Channel-1"),
                gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH2, "Channel-2"),
                gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH3, "Channel-3") };

        // Keep this sample program running for 10 minutes
        for (int count = 0; count < 600; count++) {
            StringBuilder sb  = new StringBuilder();

            // Print current analog input conversion values from each input channel
            for(GpioPinAnalogInput input : inputs){
                double analog = provider.getAnalogValue(input.getPin());
                sb.append(" \t[" + input.getValue() + " -> " + analog + " V] ");
            }

            // Print out all analog input conversion values
            System.out.println("<MCP3424 VALUES> " + sb.toString());

            Thread.sleep(1000);
        }

        // 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();

        System.out.println("<--Pi4J--> Exiting MCP3424 GPIO Example.");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:39,代碼來源:MCP3424GpioExampleNonMonitored.java


注:本文中的com.pi4j.io.gpio.GpioFactory.getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。