当前位置: 首页>>代码示例>>Python>>正文


Python GPIO.BOARD属性代码示例

本文整理汇总了Python中RPi.GPIO.BOARD属性的典型用法代码示例。如果您正苦于以下问题:Python GPIO.BOARD属性的具体用法?Python GPIO.BOARD怎么用?Python GPIO.BOARD使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在RPi.GPIO的用法示例。


在下文中一共展示了GPIO.BOARD属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOARD [as 别名]
def __init__(self, red, green, blue, pinmode=GPIO.BOARD, freq=50):
        GPIO.setmode(pinmode)
        self.pins = {
            "red": red,
            "green": green,
            "blue": blue
            }
        for pin in self.pins.values():
            GPIO.setup(pin, GPIO.OUT)

        # Turn all on and all off
        for pin in self.pins.values():
            GPIO.output(pin, GPIO.HIGH)
            GPIO.output(pin, GPIO.LOW)

        self.pwms = dict([
             (name, GPIO.PWM(pin, freq))
             for name, pin in self.pins.items()
            ])
        for pwm in self.pwms.values():
            pwm.start(0) 
开发者ID:PacktPublishing,项目名称:Mastering-GUI-Programming-with-Python,代码行数:23,代码来源:three_color_led_gui.py

示例2: main

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOARD [as 别名]
def main():
    """Calculate the distance of an object in centimeters using a HCSR04 sensor
       and a Raspberry Pi"""
    # Use GPIO.BOARD values instead of BCM
    trig_pin = 11
    echo_pin = 13
    gpio_mode = GPIO.BOARD  # library uses GPIO.BCM by default
    # Default values
    # unit = 'metric'
    # temperature = 20

    # Create a distance reading with the hcsr04 sensor module
    # using GPIO.BOARD pin values.
    value = sensor.Measurement(trig_pin, echo_pin, gpio_mode=gpio_mode)
    raw_measurement = value.raw_distance()

    # Calculate the distance in centimeters
    print("The Distance = {} centimeters".format(round(raw_measurement, 1))) 
开发者ID:alaudet,项目名称:hcsr04sensor,代码行数:20,代码来源:metric_distance_board_pin_values.py

示例3: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOARD [as 别名]
def __init__(self, address=0x40):
        """
        init object with i2c address, default is 0x40 for ServoPi board

        :param address: device i2c address, defaults to 0x40
        :type address: int, optional
        """
        self.__address = address
        self.__bus = self.__get_smbus()
        self.__write(self.__MODE1, self.__mode1_default)
        self.__write(self.__MODE2, self.__mode2_default)
        GPIO.setwarnings(False)

        mode = GPIO.getmode()  # check if the GPIO mode has been set

        if (mode == 10):  # Mode set to GPIO.BOARD
            self.__oe_pin = 7
        elif (mode == 11):  # Mode set to GPIO.BCM
            self.__oe_pin = 4
        else:  # Mode not set
            GPIO.setmode(GPIO.BOARD)
            self.__oe_pin = 7

        GPIO.setup(self.__oe_pin, GPIO.OUT) 
开发者ID:abelectronicsuk,项目名称:ABElectronics_Python_Libraries,代码行数:26,代码来源:ServoPi.py

示例4: checkSwitch

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOARD [as 别名]
def checkSwitch():
	v0 = not GPIO.input(4)
	v1 = not GPIO.input(23)
	v2 = not GPIO.input(10)
	v3 = not GPIO.input(9)
	return v3, v0, v1, v2
	#return v0, v1, v2, v3



#lcd = CharLCD(cols=16, rows=2)
#lcd = CharLCD(pin_rs=15, pin_rw=18, pin_e=16, pins_data=[21, 22, 23, 24], numbering_mode=GPIO.BOARD, cols=20, rows=4, dotsize=8) 
开发者ID:timwaizenegger,项目名称:raspberrypi-examples,代码行数:14,代码来源:lcd-demo.py

示例5: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOARD [as 别名]
def __init__(self, use_board=False):
        """
        Initialize function for AMSpi class

        :param bool use_board: True if GPIO.BOARD numbering will be used
        """
        if use_board:
            GPIO.setmode(GPIO.BOARD)
            print("PIN numbering: BOARD")
        else:
            GPIO.setmode(GPIO.BCM)
            print("PIN numbering: BCM") 
开发者ID:lipoja,项目名称:AMSpi,代码行数:14,代码来源:AMSpi.py

示例6: _gpio_get_pin

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOARD [as 别名]
def _gpio_get_pin(self, pin):
        if (GPIO.getmode() == GPIO.BOARD and self.GPIOMode == 'BOARD') or (GPIO.getmode() == GPIO.BCM and self.GPIOMode == 'BCM'):
            return pin
        elif GPIO.getmode() == GPIO.BOARD and self.GPIOMode == 'BCM':
            return self._gpio_bcm_to_board(pin)
        elif GPIO.getmode() == GPIO.BCM and self.GPIOMode == 'BOARD':
            return self._gpio_board_to_bcm(pin)
        else:
            return 0 
开发者ID:kantlivelong,项目名称:OctoPrint-PSUControl,代码行数:11,代码来源:__init__.py

示例7: get_settings_defaults

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOARD [as 别名]
def get_settings_defaults(self):
        return dict(
            GPIOMode = 'BOARD',
            switchingMethod = 'GCODE',
            onoffGPIOPin = 0,
            invertonoffGPIOPin = False,
            onGCodeCommand = 'M80', 
            offGCodeCommand = 'M81', 
            onSysCommand = '',
            offSysCommand = '',
            enablePseudoOnOff = False,
            pseudoOnGCodeCommand = 'M80',
            pseudoOffGCodeCommand = 'M81',
            postOnDelay = 0.0,
            disconnectOnPowerOff = False,
            sensingMethod = 'INTERNAL',
            senseGPIOPin = 0,
            sensePollingInterval = 5,
            invertsenseGPIOPin = False,
            senseGPIOPinPUD = '',
            senseSystemCommand = '',
            autoOn = False,
            autoOnTriggerGCodeCommands = "G0,G1,G2,G3,G10,G11,G28,G29,G32,M104,M106,M109,M140,M190",
            enablePowerOffWarningDialog = True,
            powerOffWhenIdle = False,
            idleTimeout = 30,
            idleIgnoreCommands = 'M105',
            idleTimeoutWaitTemp = 50
        ) 
开发者ID:kantlivelong,项目名称:OctoPrint-PSUControl,代码行数:31,代码来源:__init__.py

示例8: setup_gpio

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOARD [as 别名]
def setup_gpio(self):
        try:
            current_mode = GPIO.getmode()
            set_mode = GPIO.BOARD if self._settings.get(["use_board_pin_number"]) else GPIO.BCM
            if current_mode is None:
                outputs = list(filter(
                    lambda item: item['output_type'] == 'regular' or item['output_type'] == 'pwm' or item[
                        'output_type'] == 'temp_hum_control' or item['output_type'] == 'neopixel_direct',
                    self.rpi_outputs))
                inputs = list(filter(lambda item: item['input_type'] == 'gpio', self.rpi_inputs))
                gpios = outputs + inputs
                if gpios:
                    GPIO.setmode(set_mode)
                    tempstr = "BOARD" if set_mode == GPIO.BOARD else "BCM"
                    self._logger.info("Setting GPIO mode to %s", tempstr)
            elif current_mode != set_mode:
                GPIO.setmode(current_mode)
                tempstr = "BOARD" if current_mode == GPIO.BOARD else "BCM"
                self._settings.set(["use_board_pin_number"], True if current_mode == GPIO.BOARD else False)
                warn_msg = "GPIO mode was configured before, GPIO mode will be forced to use: " + tempstr + " as pin numbers. Please update GPIO accordingly!"
                self._logger.info(warn_msg)
                self._plugin_manager.send_plugin_message(self._identifier,
                    dict(is_msg=True, msg=warn_msg, msg_type="error"))
            GPIO.setwarnings(False)
        except Exception as ex:
            self.log_error(ex) 
开发者ID:vitormhenrique,项目名称:OctoPrint-Enclosure,代码行数:28,代码来源:__init__.py

示例9: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOARD [as 别名]
def __init__(self, clk_pin, mosi_pin, miso_pin, num_bits=8, gpio_mode=gpio.BOARD, send_recv_delay=0.0005):
        self._clk_pin = clk_pin
        self._mosi_pin = mosi_pin
        self._miso_pin = miso_pin
        self._num_bits = num_bits
        self._gpio_mode = gpio_mode

        self.send_recv_delay = send_recv_delay
        self.last_send = 0 
开发者ID:autopi-io,项目名称:autopi-core,代码行数:11,代码来源:gpio_spi_conn.py

示例10: _configure_gpio

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOARD [as 别名]
def _configure_gpio(self):
        if not self._hasGPIO:
            self._logger.error("RPi.GPIO is required.")
            return
        
        self._logger.info("Running RPi.GPIO version %s" % GPIO.VERSION)
        if GPIO.VERSION < "0.6":
            self._logger.error("RPi.GPIO version 0.6.0 or greater required.")
        
        GPIO.setwarnings(False)

        for pin in self._configuredGPIOPins:
            self._logger.debug("Cleaning up pin %s" % pin)
            try:
                GPIO.cleanup(self._gpio_get_pin(pin))
            except (RuntimeError, ValueError) as e:
                self._logger.error(e)
        self._configuredGPIOPins = []

        if GPIO.getmode() is None:
            if self.GPIOMode == 'BOARD':
                GPIO.setmode(GPIO.BOARD)
            elif self.GPIOMode == 'BCM':
                GPIO.setmode(GPIO.BCM)
            else:
                return
        
        if self.sensingMethod == 'GPIO':
            self._logger.info("Using GPIO sensing to determine PSU on/off state.")
            self._logger.info("Configuring GPIO for pin %s" % self.senseGPIOPin)

            if self.senseGPIOPinPUD == 'PULL_UP':
                pudsenseGPIOPin = GPIO.PUD_UP
            elif self.senseGPIOPinPUD == 'PULL_DOWN':
                pudsenseGPIOPin = GPIO.PUD_DOWN
            else:
                pudsenseGPIOPin = GPIO.PUD_OFF
    
            try:
                GPIO.setup(self._gpio_get_pin(self.senseGPIOPin), GPIO.IN, pull_up_down=pudsenseGPIOPin)
                self._configuredGPIOPins.append(self.senseGPIOPin)
            except (RuntimeError, ValueError) as e:
                self._logger.error(e)
        
        if self.switchingMethod == 'GPIO':
            self._logger.info("Using GPIO for On/Off")
            self._logger.info("Configuring GPIO for pin %s" % self.onoffGPIOPin)
            try:
                if not self.invertonoffGPIOPin:
                    initial_pin_output=GPIO.LOW
                else:
                    initial_pin_output=GPIO.HIGH
                GPIO.setup(self._gpio_get_pin(self.onoffGPIOPin), GPIO.OUT, initial=initial_pin_output)
                self._configuredGPIOPins.append(self.onoffGPIOPin)
            except (RuntimeError, ValueError) as e:
                self._logger.error(e) 
开发者ID:kantlivelong,项目名称:OctoPrint-PSUControl,代码行数:58,代码来源:__init__.py


注:本文中的RPi.GPIO.BOARD属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。