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


Java GpioController.provisionAnalogOutputPin方法代碼示例

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


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

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

示例2: 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 DacGpioProvider provider = new MCP4725GpioProvider(
                I2CBus.BUS_1,                          // I2C BUS 1 on newer Raspberry Pi's
                MCP4725GpioProvider.MCP4725_ADDRESS_1  // default address
        );

        // create output pin
        final GpioPinAnalogOutput output = gpio.provisionAnalogOutputPin(provider, MCP4725Pin.OUTPUT);

        // set a startup value for the output pin
        output.setValue(0);

        // set a shutdown value for the output pin
        provider.setShutdownValue(MCP4725GpioProvider.MAX_VALUE, 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) * 100;

            // assign a percentage value instead of raw value
            // (we have to use a helper method within the provider instead of directly on the pin instance)
            provider.setPercentValue(output, y);

            // rollover
            if (i == 359) { i = 0; }
        }

        // generate a square wave on output pin
//        for(int i = 0; i < 100000; i++) {
//            output.setValue(gpioProvider.getMaxSupportedValue());
//            Thread.sleep(2);
//            output.setValue(gpioProvider.getMinSupportedValue());
//            Thread.sleep(2);
//        }

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


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