本文整理匯總了Java中com.pi4j.io.gpio.GpioPinDigitalOutput.setState方法的典型用法代碼示例。如果您正苦於以下問題:Java GpioPinDigitalOutput.setState方法的具體用法?Java GpioPinDigitalOutput.setState怎麽用?Java GpioPinDigitalOutput.setState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.pi4j.io.gpio.GpioPinDigitalOutput
的用法示例。
在下文中一共展示了GpioPinDigitalOutput.setState方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入方法依賴的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
}
示例2: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入方法依賴的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
}
示例3: switchRelay
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入方法依賴的package包/類
@Override
public synchronized void switchRelay(int num, boolean on) {
if (num < 0 || num >= mMapping.length) {
LOG.warn("Invalid relay number: " + num);
return;
}
LOG.info("Switching relay" + num + " on? " + on);
GpioPinDigitalOutput gpio = mActivePins.get(num);
if (gpio != null) {
// If we already initialize the pin, simply switch the state.
gpio.setState(on ? PinState.LOW : PinState.HIGH);
return;
}
// A relay is 'ON' when its pin is set to LOW. However, there is an issue if
// we call provisionDigitalOutputPin with state HIGH to have the pin off as
// it will very briefly switch it to LOW. This is not acceptable, since e.g.
// we might accidentally open up a garage door when initializing the pins.
// This is why we don't provision the pin here until we need it.
if (!on) {
// If a pin has not been provisioned yet and is supposed to be switched
// 'off', don't do anything.
return;
}
// Only if a pin has not been provisioned yet and is to be switched on,
// provision it to the relay state 'ON' which is 'LOW'.
final GpioPinDigitalOutput pin = mGpioController.provisionDigitalOutputPin(
Pins.GPIO_PIN[mMapping[num]], PinState.LOW);
// Important: When the program is exited the pin needs to go into 'HIGH'
// state so that the relay stays off. We don't want garage doors to open
// when the app exits.
pin.setShutdownOptions(true, PinState.HIGH, PinPullResistance.OFF);
mActivePins.put(num, pin);
}
示例4: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
// START SNIPPET: usage-create-controller-snippet
// create gpio controller instance
final GpioController gpio = GpioFactory.getInstance();
// END SNIPPET: usage-create-controller-snippet
// START SNIPPET: usage-provision-input-pin-snippet
// provision gpio pin #02 as an input pin with its internal pull down resistor enabled
// (configure pin edge to both rising and falling to get notified for HIGH and LOW state
// changes)
GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02, // PIN NUMBER
"MyButton", // PIN FRIENDLY NAME (optional)
PinPullResistance.PULL_DOWN); // PIN RESISTANCE (optional)
// END SNIPPET: usage-provision-input-pin-snippet
// START SNIPPET: usage-provision-output-pin-snippet
// provision gpio pins #04 as an output pin and make sure is is set to LOW at startup
GpioPinDigitalOutput myLed = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, // PIN NUMBER
"My LED", // PIN FRIENDLY NAME (optional)
PinState.LOW); // PIN STARTUP STATE (optional)
// END SNIPPET: usage-provision-output-pin-snippet
// START SNIPPET: usage-shutdown-pin-snippet
// 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
myLed.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
// END SNIPPET: usage-shutdown-pin-snippet
// START SNIPPET: usage-control-pin-snippet
// explicitly set a state on the pin object
myLed.setState(PinState.HIGH);
// use convenience wrapper method to set state on the pin object
myLed.low();
myLed.high();
// use toggle method to apply inverse state on the pin object
myLed.toggle();
// use pulse method to set the pin to the HIGH state for
// an explicit length of time in milliseconds
myLed.pulse(1000);
// END SNIPPET: usage-control-pin-snippet
// START SNIPPET: usage-read-pin-snippet
// get explicit state enumeration for the GPIO pin associated with the button
PinState myButtonState = myButton.getState();
// use convenience wrapper method to interrogate the button state
boolean buttonPressed = myButton.isHigh();
// END SNIPPET: usage-read-pin-snippet
// START SNIPPET: usage-register-listener-snippet
// create and register gpio pin listener
myButton.addListener(new GpioUsageExampleListener());
// END SNIPPET: usage-register-listener-snippet
// START SNIPPET: usage-trigger-snippet
// create a gpio synchronization trigger on the input pin
// when the input state changes, also set LED controlling gpio pin to same state
myButton.addTrigger(new GpioSyncStateTrigger(myLed));
// END SNIPPET: usage-trigger-snippet
// keep program running until user aborts (CTRL-C)
while (true) {
Thread.sleep(500);
}
// 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
}
示例5: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
// START SNIPPET: usage-create-controller-snippet
// create gpio controller instance
final GpioController gpio = GpioFactory.getInstance();
// END SNIPPET: usage-create-controller-snippet
// START SNIPPET: usage-provision-input-pin-snippet
// provision gpio pin #02 as an input pin with its internal pull down resistor enabled
// (configure pin edge to both rising and falling to get notified for HIGH and LOW state
// changes)
GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02, // PIN NUMBER
"MyButton", // PIN FRIENDLY NAME (optional)
PinPullResistance.PULL_DOWN); // PIN RESISTANCE (optional)
// END SNIPPET: usage-provision-input-pin-snippet
// START SNIPPET: usage-provision-output-pin-snippet
// provision gpio pins #04 as an output pin and make sure is is set to LOW at startup
GpioPinDigitalOutput myLed = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, // PIN NUMBER
"My LED", // PIN FRIENDLY NAME (optional)
PinState.LOW); // PIN STARTUP STATE (optional)
// END SNIPPET: usage-provision-output-pin-snippet
// START SNIPPET: usage-shutdown-pin-snippet
// 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
myLed.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
// END SNIPPET: usage-shutdown-pin-snippet
// START SNIPPET: usage-control-pin-snippet
// explicitly set a state on the pin object
myLed.setState(PinState.HIGH);
// use convenience wrapper method to set state on the pin object
myLed.low();
myLed.high();
// use toggle method to apply inverse state on the pin object
myLed.toggle();
// use pulse method to set the pin to the HIGH state for
// an explicit length of time in milliseconds
myLed.pulse(1000);
// END SNIPPET: usage-control-pin-snippet
// START SNIPPET: usage-read-pin-snippet
// get explicit state enumeration for the GPIO pin associated with the button
PinState myButtonState = myButton.getState();
// use convenience wrapper method to interrogate the button state
boolean buttonPressed = myButton.isHigh();
// END SNIPPET: usage-read-pin-snippet
// START SNIPPET: usage-register-listener-snippet
// create and register gpio pin listener
myButton.addListener(new GpioUsageExampleListener());
// END SNIPPET: usage-register-listener-snippet
// START SNIPPET: usage-trigger-snippet
// create a gpio synchronization trigger on the input pin
// when the input state changes, also set LED controlling gpio pin to same state
myButton.addTrigger(new GpioSyncStateTrigger(myLed));
// END SNIPPET: usage-trigger-snippet
// keep program running until user aborts (CTRL-C)
for (;;) {
Thread.sleep(500);
}
// 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
}
示例6: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
printCommands();
GpioFactory.setDefaultProvider(new RaspiGpioProvider(RaspiPinNumberingScheme.BROADCOM_PIN_NUMBERING));
GpioPinDigitalOutput led = GpioFactory.getInstance().provisionDigitalOutputPin(RaspiPin.GPIO_17);
led.setState(PinState.HIGH);
// Initialize SPI and I2C bus:
I2CBus iic1 = I2CFactory.getInstance(I2CBus.BUS_1);
SpiDevice spi0 = SpiFactory.getInstance(
SpiChannel.CS0,
SpiDevice.DEFAULT_SPI_SPEED, // default spi speed 1 MHz
SpiDevice.DEFAULT_SPI_MODE);
rover = new Rover();
// create the concrete instance of the compass chip:
compass = new HMC5883L(iic1.getDevice(0x1e), HMC5883LConfig.Default);
adc = new Mcp3008(spi0);
ir = new Sharp0A41SK(adc, (short) 0);
roverTest();
led.setState(PinState.LOW);
rover.end();
iic1.close();
}