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


Java GpioController類代碼示例

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


GpioController類屬於com.pi4j.io.gpio包,在下文中一共展示了GpioController類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: provisionPwmOutputs

import com.pi4j.io.gpio.GpioController; //導入依賴的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.GpioController; //導入依賴的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.GpioController; //導入依賴的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: CollisionRunnable

import com.pi4j.io.gpio.GpioController; //導入依賴的package包/類
@Inject
public CollisionRunnable(IRSensorFactory sensorFactory,
                         GpioController gpio,
                         ClientManager clientManager,
                         RoverHandler roverHandler) {
    LOGGER.info("creating new CollisionRunnable via injected constructor");
    this.sensorFrontRight = sensorFactory.create(PCF8591ADConverter.InputChannel.ZERO,
            gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03, PinState.LOW));
    this.sensorFrontLeft = sensorFactory.create(PCF8591ADConverter.InputChannel.ONE,
            gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05, PinState.LOW));
    this.sensorBackRight = sensorFactory.create(PCF8591ADConverter.InputChannel.THREE,
            gpio.provisionDigitalOutputPin(RaspiPin.GPIO_29, PinState.LOW));
    this.sensorBackLeft = sensorFactory.create(PCF8591ADConverter.InputChannel.TWO,
            gpio.provisionDigitalOutputPin(RaspiPin.GPIO_24, PinState.LOW));

    this.clientManager = clientManager;
}
 
開發者ID:weiss19ja,項目名稱:amos-ss16-proj2,代碼行數:18,代碼來源:CollisionRunnable.java

示例5: Led

import com.pi4j.io.gpio.GpioController; //導入依賴的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

示例6: main

import com.pi4j.io.gpio.GpioController; //導入依賴的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

示例7: main

import com.pi4j.io.gpio.GpioController; //導入依賴的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

示例8: FlowMeterFlux

import com.pi4j.io.gpio.GpioController; //導入依賴的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.");
			}
		});
	}
 
開發者ID:iproduct,項目名稱:course-social-robotics,代碼行數:24,代碼來源:FlowMeterFlux.java

示例9: start

import com.pi4j.io.gpio.GpioController; //導入依賴的package包/類
@Override
public void start() {
    GpioController gpioController = getGpioController();
    if(gpioController != null) {
        try {
            outputPin = gpioController.provisionDigitalOutputPin(getGpio(), adjustState(PinState.LOW));
            logger.info("{}: Switch uses {} reverseStates={}", getApplianceId(), getGpio(), reverseStates);
        }
        catch(Exception e) {
            logger.error("{}: Error starting {} for {}", getApplianceId(), getClass().getSimpleName(), getGpio(), e);
        }
    }
    else {
        logGpioAccessDisabled();
    }
}
 
開發者ID:camueller,項目名稱:SmartApplianceEnabler,代碼行數:17,代碼來源:Switch.java

示例10: GPIOButton

import com.pi4j.io.gpio.GpioController; //導入依賴的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

示例11: main

import com.pi4j.io.gpio.GpioController; //導入依賴的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

示例12: init

import com.pi4j.io.gpio.GpioController; //導入依賴的package包/類
@Override
public void init() throws ServletException
{
    super.init();
    
    takingSnapshot = false;
    
    ServletContext servletContext = getServletContext();
    GpioController gpio = (GpioController) servletContext.getAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY);
    if(gpio == null)
    {
        System.err.println("The foot pedal servlet could not obtain a GPIO contorller from the servlet context");
    }
    else
    {            
        GpioPinDigitalInput photoBoothButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_17, 
                                                                             "foot pedal button", 
                                                                             PinPullResistance.PULL_UP);
        photoBoothButton.addListener(this);
        servletContext.setAttribute(PHOTO_BOOTH_FOOT_PEDAL_KEY, photoBoothButton);
    }
}
 
開發者ID:onebeartoe,項目名稱:photorama,代碼行數:23,代碼來源:FootPedalServlet.java

示例13: ReedControllerImpl

import com.pi4j.io.gpio.GpioController; //導入依賴的package包/類
public ReedControllerImpl(int mapping[], GpioController gpioController) {
  LOG.info("Initializing with mapping: " + Arrays.toString(mapping));
  mRelayClosed = new boolean[mapping.length];
  initializePins(mapping, gpioController, (relayNum, closed) -> {
    LOG.debug("Relay " + relayNum + " now " + (closed ? "Closed" : "Open"));
    mRelayClosed[relayNum] = closed;

    synchronized (mListeners) {
      // TODO: Think about creating a separate event delivery thread.
      for (final RelayStateChangedListener listener : mListeners) {
        listener.onRelayStateChanged(relayNum, closed);
      }
    }
  });
  LOG.info("Reed relays initialized");
}
 
開發者ID:shaeberling,項目名稱:winston,代碼行數:17,代碼來源:ReedControllerImpl.java

示例14: initializePins

import com.pi4j.io.gpio.GpioController; //導入依賴的package包/類
private static GpioPinDigitalInput[] initializePins(int mapping[], GpioController gpioController,
                                                    final RelayStateChangedListener listener) {
  final GpioPinDigitalInput[] pins = new GpioPinDigitalInput[mapping.length];
  for (int i = 0; i < mapping.length; ++i) {
    pins[i] = gpioController.provisionDigitalInputPin(Pins.GPIO_PIN[mapping[i]],
        PinPullResistance.PULL_UP);
    final int relayNum = i;
    pins[i].addListener((GpioPinListenerDigital) event -> {
      listener.onRelayStateChanged(relayNum, event.getState() == PinState.LOW);
    });

    // Tell the listener about the current state before change events are
    // received.
    listener.onRelayStateChanged(relayNum, pins[i].getState() == PinState.LOW);
  }
  return pins;
}
 
開發者ID:shaeberling,項目名稱:winston,代碼行數:18,代碼來源:ReedControllerImpl.java

示例15: main

import com.pi4j.io.gpio.GpioController; //導入依賴的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


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