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


Java GpioController.shutdown方法代碼示例

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


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

示例1: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的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");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:38,代碼來源:MotorControl.java

示例2: main

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

        System.out.println("<--Pi4J--> GPIO Shutdown 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.HIGH);

        // configure the pin shutdown behavior; these settings will be
        // automatically applied to the pin when the application is terminated
        pin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);

        System.out.println("--> GPIO state should be: ON");
        System.out.println("    This program will automatically terminate in 10 seconds,");
        System.out.println("    or you can use the CTRL-C keystroke to terminate at any time.");
        System.out.println("    When the program terminates, the GPIO state should be shutdown and set to: OFF");

        // wait 10 seconds
        Thread.sleep(10000);

        System.out.println(" .. shutting down now ...");

        // 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 ShutdownGpioExample");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:31,代碼來源:ShutdownGpioExample.java

示例3: main

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

示例4: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
    
    System.out.println("<--Pi4J--> GPIO Shutdown 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.HIGH);
    
    // configure the pin shutdown behavior; these settings will be 
    // automatically applied to the pin when the application is terminated
    pin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
    
    System.out.println("--> GPIO state should be: ON");
    System.out.println("    This program will automatically terminate in 10 seconds,");
    System.out.println("    or you can use the CTRL-C keystroke to terminate at any time.");
    System.out.println("    When the program terminates, the GPIO state should be shutdown and set to: OFF");
    
    // wait 10 seconds
    Thread.sleep(10000);
    
    System.out.println(" .. shutting down now ...");
    
    // 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();
}
 
開發者ID:iot-labs,項目名稱:communication,代碼行數:29,代碼來源:ShutdownGpioExample.java

示例5: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的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();
    }
 
開發者ID:starksm64,項目名稱:RaspberryPi,代碼行數:40,代碼來源:ControlGpioExample.java

示例6: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
@Test
public void main() throws InterruptedException {

     System.out.println("<--Pi4J--> GPIO Shutdown 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.HIGH);

     // configure the pin shutdown behavior; these settings will be
     // automatically applied to the pin when the application is terminated
     pin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);

     System.out.println("--> GPIO state should be: ON");
     System.out.println("    This program will automatically terminate in 10 seconds,");
     System.out.println("    or you can use the CTRL-C keystroke to terminate at any time.");
     System.out.println("    When the program terminates, the GPIO state should be shutdown and set to: OFF");

     // wait 10 seconds
     Thread.sleep(10000);

     System.out.println(" .. shutting down now ...");

     // 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();
 }
 
開發者ID:starksm64,項目名稱:RaspberryPi,代碼行數:30,代碼來源:ShutdownGpioExample.java

示例7: destroy

import com.pi4j.io.gpio.GpioController; //導入方法依賴的package包/類
@Override
public void destroy()
{
    ServletContext servletContext = getServletContext();
    GpioController gpio = (GpioController) servletContext.getAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY);
    gpio.shutdown();
}
 
開發者ID:onebeartoe,項目名稱:photorama,代碼行數:8,代碼來源:PhotoBoothServlet.java

示例8: main

import com.pi4j.io.gpio.GpioController; //導入方法依賴的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();
}
 
開發者ID:Wyliodrin,項目名稱:wyliodrin-server-nodejs,代碼行數:40,代碼來源:ControlGpioExample.java

示例9: main

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

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

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

        // create custom MCP23017 GPIO provider
        final MCP23017GpioProvider provider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x20);
        
        
        
        

        // provision gpio input pins from MCP23017
        GpioPinDigitalInput myInputs[] = {
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A0, "MyInput-A0", PinPullResistance.OFF),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A1, "MyInput-A1", PinPullResistance.OFF),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A2, "MyInput-A2", PinPullResistance.OFF),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A3, "MyInput-A3", PinPullResistance.OFF),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A4, "MyInput-A4", PinPullResistance.OFF),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A5, "MyInput-A5", PinPullResistance.OFF),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A6, "MyInput-A6", PinPullResistance.OFF),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A7, "MyInput-A7", PinPullResistance.OFF),
            };

        // create and register gpio pin listener
        gpio.addListener(new GpioPinListenerDigital() {
            @Override
            public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                // display pin state on console
                System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = "
                        + event.getState());
            }
        }, myInputs);

        // provision gpio output pins and make sure they are all LOW at startup
        GpioPinDigitalOutput myOutputs[] = {
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B0, "MyOutput-B0", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B1, "MyOutput-B1", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B2, "MyOutput-B2", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B3, "MyOutput-B3", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B4, "MyOutput-B4", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B5, "MyOutput-B5", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B6, "MyOutput-B6", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B7, "MyOutput-B7", PinState.LOW)
          };
        
        

        // keep program running for 20 seconds
        for (int count = 0; count < 1000; count++) {
            gpio.setState(true, myOutputs);
            Thread.sleep(1000);
            gpio.setState(false, myOutputs);
            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("Exiting MCP23017GpioExample");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:65,代碼來源:MCP23017E.java

示例10: main

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

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

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

        // create custom PiFace GPIO provider
        final PiFaceGpioProvider gpioProvider = new PiFaceGpioProvider(PiFaceGpioProvider.DEFAULT_ADDRESS, SpiChannel.CS0);

        // provision gpio input pins from PiFaceGpioProvider
        GpioPinDigitalInput myInputs[] = {
                gpio.provisionDigitalInputPin(gpioProvider, PiFacePin.INPUT_00),
                gpio.provisionDigitalInputPin(gpioProvider, PiFacePin.INPUT_01),
                gpio.provisionDigitalInputPin(gpioProvider, PiFacePin.INPUT_02),
                gpio.provisionDigitalInputPin(gpioProvider, PiFacePin.INPUT_03),
                gpio.provisionDigitalInputPin(gpioProvider, PiFacePin.INPUT_04),
                gpio.provisionDigitalInputPin(gpioProvider, PiFacePin.INPUT_05),
                gpio.provisionDigitalInputPin(gpioProvider, PiFacePin.INPUT_06),
                gpio.provisionDigitalInputPin(gpioProvider, PiFacePin.INPUT_07)
            };

        // create and register gpio pin listener
        gpio.addListener(new GpioPinListenerDigital() {
            @Override
            public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                // display pin state on console
                System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = "
                        + event.getState());
            }
        }, myInputs);

        // provision gpio output pins and make sure they are all LOW at startup
        GpioPinDigitalOutput myOutputs[] = {
            gpio.provisionDigitalOutputPin(gpioProvider, PiFacePin.OUTPUT_00),
            gpio.provisionDigitalOutputPin(gpioProvider, PiFacePin.OUTPUT_01),
            gpio.provisionDigitalOutputPin(gpioProvider, PiFacePin.OUTPUT_02),
            gpio.provisionDigitalOutputPin(gpioProvider, PiFacePin.OUTPUT_03),
            gpio.provisionDigitalOutputPin(gpioProvider, PiFacePin.OUTPUT_04),
            gpio.provisionDigitalOutputPin(gpioProvider, PiFacePin.OUTPUT_05),
            gpio.provisionDigitalOutputPin(gpioProvider, PiFacePin.OUTPUT_06),
            gpio.provisionDigitalOutputPin(gpioProvider, PiFacePin.OUTPUT_07),
          };

        // keep program running for 20 seconds
        for (int count = 0; count < 10; count++) {
            gpio.setState(true, myOutputs);
            Thread.sleep(1000);
            gpio.setState(false, myOutputs);
            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("Exiting PiFaceGpioExample");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:59,代碼來源:PiFaceGpioExample.java

示例11: main

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

        System.out.println("<--Pi4J--> MCP3008 ADC Example ... started.");

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

        // Create custom MCP3008 analog gpio provider
        // we must specify which chip select (CS) that that ADC chip is physically connected to.
        final AdcGpioProvider provider = new MCP3008GpioProvider(SpiChannel.CS0);

        // Provision gpio analog input pins for all channels of the MCP3008.
        // (you don't have to define them all if you only use a subset in your project)
        final GpioPinAnalogInput inputs[] = {
                gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH0, "MyAnalogInput-CH0"),
                gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH1, "MyAnalogInput-CH1"),
                gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH2, "MyAnalogInput-CH2"),
                gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH3, "MyAnalogInput-CH3"),
                gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH4, "MyAnalogInput-CH4"),
                gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH5, "MyAnalogInput-CH5"),
                gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH6, "MyAnalogInput-CH6"),
                gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH7, "MyAnalogInput-CH7")
        };


        // Define the amount that the ADC input conversion value must change before
        // a 'GpioPinAnalogValueChangeEvent' is raised.  This is used to prevent unnecessary
        // event dispatching for an analog input that may have an acceptable or expected
        // range of value drift.
        provider.setEventThreshold(100, inputs); // all inputs; alternatively you can set thresholds on each input discretely

        // Set the background monitoring interval timer for the underlying framework to
        // interrogate the ADC chip for input conversion values.  The acceptable monitoring
        // interval will be highly dependant on your specific project.  The lower this value
        // is set, the more CPU time will be spend collecting analog input conversion values
        // on a regular basis.  The higher this value the slower your application will get
        // analog input value change events/notifications.  Try to find a reasonable balance
        // for your project needs.
        provider.setMonitorInterval(250); // milliseconds

        // Print current analog input conversion values from each input channel
        for(GpioPinAnalogInput input : inputs){
            System.out.println("<INITIAL VALUE> [" + input.getName() + "] : RAW VALUE = " + input.getValue());
        }

        // Create an analog pin value change listener
        GpioPinListenerAnalog listener = new GpioPinListenerAnalog()
        {
            @Override
            public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event)
            {
                // get RAW value
                double value = event.getValue();

                // display output
                System.out.println("<CHANGED VALUE> [" + event.getPin().getName() + "] : RAW VALUE = " + value);
            }
        };

        // Register the gpio analog input listener for all input pins
        gpio.addListener(listener, inputs);

        // Keep this sample program running for 10 minutes
        for (int count = 0; count < 600; count++) {
            Thread.sleep(1000);
        }

        // When your program is finished, make sure to stop all GPIO activity/threads by shutting
        // down the GPIO controller (this method will forcefully shutdown all GPIO monitoring threads
        // and background scheduled tasks)
        gpio.shutdown();

        System.out.println("Exiting MCP3008GpioExample");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:75,代碼來源:MCP3008GpioExample.java

示例12: main

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

        System.out.println("<--Pi4J--> MCP3204 ADC Example ... started.");

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

        // Create custom MCP3204 analog gpio provider
        // we must specify which chip select (CS) that that ADC chip is physically connected to.
        final AdcGpioProvider provider = new MCP3204GpioProvider(SpiChannel.CS0);

        // Provision gpio analog input pins for all channels of the MCP3204.
        // (you don't have to define them all if you only use a subset in your project)
        final GpioPinAnalogInput inputs[] = {
                gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH0, "MyAnalogInput-CH0"),
                gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH1, "MyAnalogInput-CH1"),
                gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH2, "MyAnalogInput-CH2"),
                gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH3, "MyAnalogInput-CH3")
        };


        // Define the amount that the ADC input conversion value must change before
        // a 'GpioPinAnalogValueChangeEvent' is raised.  This is used to prevent unnecessary
        // event dispatching for an analog input that may have an acceptable or expected
        // range of value drift.
        provider.setEventThreshold(100, inputs); // all inputs; alternatively you can set thresholds on each input discretely

        // Set the background monitoring interval timer for the underlying framework to
        // interrogate the ADC chip for input conversion values.  The acceptable monitoring
        // interval will be highly dependant on your specific project.  The lower this value
        // is set, the more CPU time will be spend collecting analog input conversion values
        // on a regular basis.  The higher this value the slower your application will get
        // analog input value change events/notifications.  Try to find a reasonable balance
        // for your project needs.
        provider.setMonitorInterval(250); // milliseconds

        // Print current analog input conversion values from each input channel
        for(GpioPinAnalogInput input : inputs){
            System.out.println("<INITIAL VALUE> [" + input.getName() + "] : RAW VALUE = " + input.getValue());
        }

        // Create an analog pin value change listener
        GpioPinListenerAnalog listener = new GpioPinListenerAnalog()
        {
            @Override
            public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event)
            {
                // get RAW value
                double value = event.getValue();

                // display output
                System.out.println("<CHANGED VALUE> [" + event.getPin().getName() + "] : RAW VALUE = " + value);
            }
        };

        // Register the gpio analog input listener for all input pins
        gpio.addListener(listener, inputs);

        // Keep this sample program running for 10 minutes
        for (int count = 0; count < 600; count++) {
            Thread.sleep(1000);
        }

        // When your program is finished, make sure to stop all GPIO activity/threads by shutting
        // down the GPIO controller (this method will forcefully shutdown all GPIO monitoring threads
        // and background scheduled tasks)
        gpio.shutdown();

        System.out.println("Exiting MCP3204GpioExample");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:71,代碼來源:MCP3204GpioExample.java

示例13: main

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

        System.out.println("<--Pi4J--> MCP3208 ADC Example (NON-MONITORED) ... started.");

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

        // Create custom MCP3208 analog gpio provider
        // we must specify which chip select (CS) that that ADC chip is physically connected to.
        final AdcGpioProvider provider = new MCP3208GpioProvider(SpiChannel.CS0,
                SpiDevice.DEFAULT_SPI_SPEED,
                SpiDevice.DEFAULT_SPI_MODE,
                false);   // <<-- the 'false' value here disable the base background monitoring thread

        // So why would I want to disable the background monitoring thread?
        // Well, that depends on how you plan on integrating this into your project.
        // If you need/want pin event notification, then you must keep the background
        // monitoring thread enabled.  If you only need to periodically obtain analog
        // input conversion values or only need to acquire the value as the result of
        // some other event or condition in your application, then you can disable the
        // background monitoring thread to reduce the runtime overhead.
        // If its disabled, then anytime you request the pin.getValue() to get an analog
        // conversion value it will get the value directly from the ADC chip synchronously
        // in your process call.  If background monitoring is enabled, then calls to
        // pin.getValue() return you the last acquired (cached) value and does not
        // perform an immediate data acquisition.

        // Provision gpio analog input pins for all channels of the MCP3208.
        // (you don't have to define them all if you only use a subset in your project)
        final GpioPinAnalogInput inputs[] = {
                gpio.provisionAnalogInputPin(provider, MCP3208Pin.CH0, "MyAnalogInput-CH0"),
                gpio.provisionAnalogInputPin(provider, MCP3208Pin.CH1, "MyAnalogInput-CH1"),
                gpio.provisionAnalogInputPin(provider, MCP3208Pin.CH2, "MyAnalogInput-CH2"),
                gpio.provisionAnalogInputPin(provider, MCP3208Pin.CH3, "MyAnalogInput-CH3"),
                gpio.provisionAnalogInputPin(provider, MCP3208Pin.CH4, "MyAnalogInput-CH4"),
                gpio.provisionAnalogInputPin(provider, MCP3208Pin.CH5, "MyAnalogInput-CH5"),
                gpio.provisionAnalogInputPin(provider, MCP3208Pin.CH6, "MyAnalogInput-CH6"),
                gpio.provisionAnalogInputPin(provider, MCP3208Pin.CH7, "MyAnalogInput-CH7")
        };

        // 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){
                sb.append(" \t[" + input.getValue() + "] ");
            }

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

            Thread.sleep(1000);
        }

        // When your program is finished, make sure to stop all GPIO activity/threads by shutting
        // down the GPIO controller (this method will forcefully shutdown all GPIO monitoring threads
        // and background scheduled tasks)
        gpio.shutdown();

        System.out.println("Exiting MCP3208GpioExampleNonMonitored");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:63,代碼來源:MCP3208GpioExampleNonMonitored.java

示例14: main

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

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

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

        // create custom MCP23017 GPIO provider
        final PCF8574GpioProvider provider = new PCF8574GpioProvider(I2CBus.BUS_1, PCF8574GpioProvider.PCF8574A_0x3F);

        // provision gpio input pins from MCP23017
        GpioPinDigitalInput myInputs[] = {
                gpio.provisionDigitalInputPin(provider, PCF8574Pin.GPIO_00),
                gpio.provisionDigitalInputPin(provider, PCF8574Pin.GPIO_01),
                gpio.provisionDigitalInputPin(provider, PCF8574Pin.GPIO_02)
            };

        // create and register gpio pin listener
        gpio.addListener(new GpioPinListenerDigital() {
            @Override
            public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                // display pin state on console
                System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = "
                        + event.getState());
            }
        }, myInputs);

        // provision gpio output pins and make sure they are all LOW at startup
        GpioPinDigitalOutput myOutputs[] = {
            gpio.provisionDigitalOutputPin(provider, PCF8574Pin.GPIO_04, PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, PCF8574Pin.GPIO_05, PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, PCF8574Pin.GPIO_06, PinState.LOW)
          };

        // on program shutdown, set the pins back to their default state: HIGH
        gpio.setShutdownOptions(true, PinState.HIGH, myOutputs);

        // keep program running for 20 seconds
        for (int count = 0; count < 10; count++) {
            gpio.setState(true, myOutputs);
            Thread.sleep(1000);
            gpio.setState(false, myOutputs);
            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("Exiting PCF8574GpioExample");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:52,代碼來源:PCF8574GpioExample.java

示例15: main

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

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

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

        // create custom MCP23017 GPIO provider
        final MCP23017GpioProvider provider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x21);

        // provision gpio input pins from MCP23017
        GpioPinDigitalInput myInputs[] = {
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A0, "MyInput-A0", PinPullResistance.PULL_UP),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A1, "MyInput-A1", PinPullResistance.PULL_UP),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A2, "MyInput-A2", PinPullResistance.PULL_UP),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A3, "MyInput-A3", PinPullResistance.PULL_UP),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A4, "MyInput-A4", PinPullResistance.PULL_UP),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A5, "MyInput-A5", PinPullResistance.PULL_UP),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A6, "MyInput-A6", PinPullResistance.PULL_UP),
                gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A7, "MyInput-A7", PinPullResistance.PULL_UP),
            };

        // create and register gpio pin listener
        gpio.addListener(new GpioPinListenerDigital() {
            @Override
            public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                // display pin state on console
                System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = "
                        + event.getState());
            }
        }, myInputs);

        // provision gpio output pins and make sure they are all LOW at startup
        GpioPinDigitalOutput myOutputs[] = {
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B0, "MyOutput-B0", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B1, "MyOutput-B1", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B2, "MyOutput-B2", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B3, "MyOutput-B3", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B4, "MyOutput-B4", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B5, "MyOutput-B5", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B6, "MyOutput-B6", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B7, "MyOutput-B7", PinState.LOW)
          };

        // keep program running for 20 seconds
        for (int count = 0; count < 10; count++) {
            gpio.setState(true, myOutputs);
            Thread.sleep(1000);
            gpio.setState(false, myOutputs);
            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("Exiting MCP23017GpioExample");
    }
 
開發者ID:uwigem,項目名稱:uwigem2017,代碼行數:59,代碼來源:MCP23017GpioExample.java


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