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


Python RPi.GPIO属性代码示例

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


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

示例1: make_adc

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def make_adc(wiring_config):
    """Creates ADC instance based on the given wiring_config.

    Args:
        wiring_config: Wiring configuration for the GreenPiThumb.

    Returns:
        An ADC instance for the specified wiring config.
    """
    # The MCP3008 spec and Adafruit library use different naming for the
    # Raspberry Pi GPIO pins, so we translate as follows:
    # * CLK -> CLK
    # * CS/SHDN -> CS
    # * DOUT -> MISO
    # * DIN -> MOSI
    return adc_thread_safe.Adc(
        Adafruit_MCP3008.MCP3008(
            clk=wiring_config.gpio_pins.mcp3008_clk,
            cs=wiring_config.gpio_pins.mcp3008_cs_shdn,
            miso=wiring_config.gpio_pins.mcp3008_dout,
            mosi=wiring_config.gpio_pins.mcp3008_din)) 
开发者ID:JeetShetty,项目名称:GreenPiThumb,代码行数:23,代码来源:greenpithumb.py

示例2: get_platform_pwm

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def get_platform_pwm(**keywords):
    """Attempt to return a PWM instance for the platform which the code is being
    executed on.  Currently supports only the Raspberry Pi using the RPi.GPIO
    library and Beaglebone Black using the Adafruit_BBIO library.  Will throw an
    exception if a PWM instance can't be created for the current platform.  The
    returned PWM object has the same interface as the RPi_PWM_Adapter and
    BBIO_PWM_Adapter classes.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        import RPi.GPIO
        return RPi_PWM_Adapter(RPi.GPIO, **keywords)
    elif plat == Platform.BEAGLEBONE_BLACK:
        import Adafruit_BBIO.PWM
        return BBIO_PWM_Adapter(Adafruit_BBIO.PWM, **keywords)
    elif plat == Platform.UNKNOWN:
        raise RuntimeError('Could not determine platform.') 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:19,代码来源:PWM.py

示例3: setup

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def setup(self):
        """Set up Inky GPIO and reset display."""
        if not self._gpio_setup:
            if self._gpio is None:
                try:
                    import RPi.GPIO as GPIO
                    self._gpio = GPIO
                except ImportError:
                    raise ImportError('This library requires the RPi.GPIO module\nInstall with: sudo apt install python-rpi.gpio')
            self._gpio.setmode(self._gpio.BCM)
            self._gpio.setwarnings(False)
            self._gpio.setup(self.dc_pin, self._gpio.OUT, initial=self._gpio.LOW, pull_up_down=self._gpio.PUD_OFF)
            self._gpio.setup(self.reset_pin, self._gpio.OUT, initial=self._gpio.HIGH, pull_up_down=self._gpio.PUD_OFF)
            self._gpio.setup(self.busy_pin, self._gpio.IN, pull_up_down=self._gpio.PUD_OFF)

            if self._spi_bus is None:
                import spidev
                self._spi_bus = spidev.SpiDev()

            self._spi_bus.open(0, self.cs_channel)
            self._spi_bus.max_speed_hz = 488000

            self._gpio_setup = True

        self._gpio.output(self.reset_pin, self._gpio.LOW)
        time.sleep(0.1)
        self._gpio.output(self.reset_pin, self._gpio.HIGH)
        time.sleep(0.1)

        self._send_command(0x12)  # Soft Reset
        self._busy_wait() 
开发者ID:pimoroni,项目名称:inky,代码行数:33,代码来源:inky.py

示例4: __init__

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def __init__(self, scl=23, rst=25, io=24):
        self.scl = scl
        self.rst = rst
        self.io = io
        # Turn off GPIO warnings.
        RPi.GPIO.setwarnings(False)
        # Configure Raspberry Pi GPIO interfaces.
        RPi.GPIO.setmode(RPi.GPIO.BCM)
        # Initiate DS1302 communication.
        self.init_ds1302()
        # Make sure write protect is turned off.
        self.write_byte(int("10001110", 2))
        self.write_byte(int("00000000", 2))
        # Make sure trickle charge mode is turned off.
        self.write_byte(int("10010000", 2))
        self.write_byte(int("00000000", 2))
        # End DS1302 communication.
        self.end_ds1302()
        self.datetime = {} 
开发者ID:sunfounder,项目名称:SunFounder_SensorKit_for_RPi2,代码行数:21,代码来源:ds1302.py

示例5: read_gpio

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def read_gpio(self, pin=None):
        """Read the state of the PN532's GPIO pins.
        :params pin: <str> specified the pin to read
        :return:
        If 'pin' is None, returns 3 bytes containing the pin state where:
            P3[0] = P30,   P7[0] = 0,   I[0] = I0,
            P3[1] = P31,   P7[1] = P71, I[1] = I1,
            P3[2] = P32,   P7[2] = P72, I[2] = 0,
            P3[3] = P33,   P7[3] = 0,   I[3] = 0,
            P3[4] = P34,   P7[4] = 0,   I[4] = 0,
            P3[5] = P35,   P7[5] = 0,   I[5] = 0,
            P3[6] = 0,     P7[6] = 0,   I[6] = 0,
            P3[7] = 0,     P7[7] = 0,   I[7] = 0,
        If 'pin' is not None, returns the specified pin state.
        """
        response = self.call_function(_COMMAND_READGPIO, response_length=3)
        if not pin:
            return tuple(response[:3])
        pins = {'p3': response[0], 'p7': response[1], 'i': response[2]}
        if pin[:-1].lower() not in pins.keys():
            return False
        return True if pins[pin[:-1].lower()] >> int(pin[-1]) & 1 else False 
开发者ID:enesbcs,项目名称:rpieasy,代码行数:24,代码来源:pn532.py

示例6: __init__

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def __init__(self):
        # LED strip configuration:
        LED_COUNT      = 176     # Number of LED pixels.
        LED_PIN        = 18      # GPIO pin connected to the pixels (18 uses PWM!).
        #LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
        LED_FREQ_HZ    = 800000  # LED signal frequency in hertz (usually 800khz)
        LED_DMA        = 10      # DMA channel to use for generating signal (try 10)
        LED_BRIGHTNESS = 110     # Set to 0 for darkest and 255 for brightest
        LED_INVERT     = False   # True to invert the signal (when using NPN transistor level shift)
        LED_CHANNEL    = 0       # set to '1' for GPIOs 13, 19, 41, 45 or 53

        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
        args = parser.parse_args()

        # Create NeoPixel object with appropriate configuration.
        self.strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
        # Intialize the library (must be called once before other functions).
        self.strip.begin() 
开发者ID:onlaj,项目名称:Piano-LED-Visualizer,代码行数:21,代码来源:randomcolor.py

示例7: __init__

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def __init__(self, rpi_gpio, mode=None):
        self.rpi_gpio = rpi_gpio
        # Suppress warnings about GPIO in use.
        rpi_gpio.setwarnings(False)
        # Set board or BCM pin numbering.
        if mode == rpi_gpio.BOARD or mode == rpi_gpio.BCM:
            rpi_gpio.setmode(mode)
        elif mode is not None:
            raise ValueError('Unexpected value for mode.  Must be BOARD or BCM.')
        else:
            # Default to BCM numbering if not told otherwise.
            rpi_gpio.setmode(rpi_gpio.BCM)
        # Store reference to each created PWM instance.
        self.pwm = {} 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:16,代码来源:PWM.py

示例8: CloseGPIO

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def CloseGPIO(self):
        '''
        Close Raspberry Pi GPIO use before finishing.
        '''
        RPi.GPIO.cleanup() 
开发者ID:sunfounder,项目名称:SunFounder_SensorKit_for_RPi2,代码行数:7,代码来源:ds1302.py

示例9: init_ds1302

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def init_ds1302(self):
        '''
        Start a transaction with the DS1302 RTC.
        '''
        RPi.GPIO.setup(self.scl, RPi.GPIO.OUT, initial=0)
        RPi.GPIO.setup(self.rst, RPi.GPIO.OUT, initial=0)
        RPi.GPIO.setup(self.io, RPi.GPIO.OUT, initial=0)
        RPi.GPIO.output(self.scl, 0)
        RPi.GPIO.output(self.io, 0)
        time.sleep(self.CLK_PERIOD)
        RPi.GPIO.output(self.rst, 1) 
开发者ID:sunfounder,项目名称:SunFounder_SensorKit_for_RPi2,代码行数:13,代码来源:ds1302.py

示例10: end_ds1302

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def end_ds1302(self):
        '''
        Complete a transaction with the DS1302 RTC.
        '''
        RPi.GPIO.setup(self.scl, RPi.GPIO.OUT, initial=0)
        RPi.GPIO.setup(self.rst, RPi.GPIO.OUT, initial=0)
        RPi.GPIO.setup(self.io, RPi.GPIO.OUT, initial=0)
        RPi.GPIO.output(self.scl, 0)
        RPi.GPIO.output(self.io, 0)
        time.sleep(self.CLK_PERIOD)
        RPi.GPIO.output(self.rst, 0) 
开发者ID:sunfounder,项目名称:SunFounder_SensorKit_for_RPi2,代码行数:13,代码来源:ds1302.py

示例11: write_byte

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def write_byte(self, Byte):
        '''
        Write a byte of data to the DS1302 RTC.
        '''
        for Count in range(8):
            time.sleep(self.CLK_PERIOD)
            RPi.GPIO.output(self.scl, 0)

            Bit = Byte % 2
            Byte = int(Byte / 2)
            time.sleep(self.CLK_PERIOD)
            RPi.GPIO.output(self.io, Bit)

            time.sleep(self.CLK_PERIOD)
            RPi.GPIO.output(self.scl, 1) 
开发者ID:sunfounder,项目名称:SunFounder_SensorKit_for_RPi2,代码行数:17,代码来源:ds1302.py

示例12: _gpio_init

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def _gpio_init(self, **kwargs):
        # Hardware GPIO init
        raise NotImplementedError 
开发者ID:enesbcs,项目名称:rpieasy,代码行数:5,代码来源:pn532.py

示例13: dir

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def dir(self, direction):
        RPi.GPIO.setup(self.pin, direction) 
开发者ID:Seeed-Studio,项目名称:grove.py,代码行数:4,代码来源:gpio_rpi.py

示例14: write

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def write(self, output):
        RPi.GPIO.output(self.pin, output) 
开发者ID:Seeed-Studio,项目名称:grove.py,代码行数:4,代码来源:gpio_rpi.py

示例15: read

# 需要导入模块: import RPi [as 别名]
# 或者: from RPi import GPIO [as 别名]
def read(self):
        return RPi.GPIO.input(self.pin) 
开发者ID:Seeed-Studio,项目名称:grove.py,代码行数:4,代码来源:gpio_rpi.py


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