本文整理汇总了Java中com.pi4j.io.gpio.GpioPinDigitalOutput.toggle方法的典型用法代码示例。如果您正苦于以下问题:Java GpioPinDigitalOutput.toggle方法的具体用法?Java GpioPinDigitalOutput.toggle怎么用?Java GpioPinDigitalOutput.toggle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.io.gpio.GpioPinDigitalOutput
的用法示例。
在下文中一共展示了GpioPinDigitalOutput.toggle方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
@Override
public Integer write(Integer endereco, Integer comando) {
Integer resultante = null;
GpioPinDigitalOutput pino = (GpioPinDigitalOutput) this.pinos.get(endereco);
switch(comando){
case 1:
pino.high();
resultante = 1;
break;
case 0:
pino.low();
resultante = 0;
break;
case 2:
pino.toggle();
if(pino.isHigh()){
resultante = 1;
}else{
resultante = 0;
}
break;
}
return resultante;
}
示例2: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Control 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, "MyLED", PinState.HIGH);
// set shutdown state for this pin
pin.setShutdownOptions(true, PinState.LOW);
System.out.println("--> GPIO state should be: ON");
Thread.sleep(10);
// turn off gpio pin #01
pin.low();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(10);
for(int i=0;i<200;i++)
{
pin.toggle();
Thread.sleep(10);
pin.toggle();
Thread.sleep(10);
}
// 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("Exiting MotorControl");
}
示例3: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Control 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, "MyLED", PinState.HIGH);
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// turn off gpio pin #01
pin.low();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
// toggle the current state of gpio pin #01 (should turn on)
pin.toggle();
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// toggle the current state of gpio pin #01 (should turn off)
pin.toggle();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
// turn on gpio pin #01 for 1 second and then off
System.out.println("--> GPIO state should be: ON for only 1 second");
pin.pulse(1000, true); // set second argument to 'true' use a blocking call
// 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();
}
示例4: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Control 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, "MyLED", PinState.HIGH);
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// turn off gpio pin #01
pin.low();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
// toggle the current state of gpio pin #01 (should turn on)
pin.toggle();
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// toggle the current state of gpio pin #01 (should turn off)
pin.toggle();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
// turn on gpio pin #01 for 1 second and then off
System.out.println("--> GPIO state should be: ON for only 1 second");
pin.pulse(1000, true); // set second argument to 'true' use a blocking call
// 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();
}
示例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)
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
}
示例6: 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
}
示例7: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Control 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, "MyLED", PinState.HIGH);
// set shutdown state for this pin
pin.setShutdownOptions(true, PinState.LOW);
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// turn off gpio pin #01
pin.low();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
// toggle the current state of gpio pin #01 (should turn on)
pin.toggle();
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// toggle the current state of gpio pin #01 (should turn off)
pin.toggle();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
// turn on gpio pin #01 for 1 second and then off
System.out.println("--> GPIO state should be: ON for only 1 second");
pin.pulse(1000, true); // set second argument to 'true' use a blocking call
// 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("Exiting ControlGpioExample");
}
示例8: main
import com.pi4j.io.gpio.GpioPinDigitalOutput; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Control 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, "MyLED", PinState.HIGH);
// set shutdown state for this pin
pin.setShutdownOptions(true, PinState.LOW);
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// turn off gpio pin #01
pin.low();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
// toggle the current state of gpio pin #01 (should turn on)
pin.toggle();
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// toggle the current state of gpio pin #01 (should turn off)
pin.toggle();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
// turn on gpio pin #01 for 1 second and then off
System.out.println("--> GPIO state should be: ON for only 1 second");
pin.pulse(1000, true); // set second argument to 'true' use a blocking call
// 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();
}