本文整理汇总了Python中Adafruit_BBIO.GPIO.setup方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.setup方法的具体用法?Python GPIO.setup怎么用?Python GPIO.setup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_BBIO.GPIO
的用法示例。
在下文中一共展示了GPIO.setup方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from Adafruit_BBIO import GPIO [as 别名]
# 或者: from Adafruit_BBIO.GPIO import setup [as 别名]
def init(self, mode=IN, pull=None):
"""Initialize the Pin"""
if mode is not None:
if mode == self.IN:
self._mode = self.IN
GPIO.setup(self.id, GPIO.IN)
elif mode == self.OUT:
self._mode = self.OUT
GPIO.setup(self.id, GPIO.OUT)
else:
raise RuntimeError("Invalid mode for pin: %s" % self.id)
if pull is not None:
if self._mode != self.IN:
raise RuntimeError("Cannot set pull resistor on output")
if pull == self.PULL_UP:
GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
elif pull == self.PULL_DOWN:
GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
else:
raise RuntimeError("Invalid pull for pin: %s" % self.id)
示例2: __init__
# 需要导入模块: from Adafruit_BBIO import GPIO [as 别名]
# 或者: from Adafruit_BBIO.GPIO import setup [as 别名]
def __init__(self, port, callback):
self.port = port
self.callback = callback
GPIO.setup(self.port, GPIO.IN)
print "DETECT EVENTS:", self.port
# GPIO.RISING, GPIO.FALLING, GPIO.BOTH
GPIO.remove_event_detect(self.port)
GPIO.add_event_detect(self.port, GPIO.RISING, callback=self.check_rising, bouncetime=300)
#GPIO.add_event_detect(self.port, GPIO.BOTH, callback=self.check_rising)
#GPIO.add_event_detect(self.port, GPIO.FALLING, callback=self.check_falling)
#GPIO.add_event_detect(self.port, GPIO.FALLING, self.check_falling)
示例3: __init__
# 需要导入模块: from Adafruit_BBIO import GPIO [as 别名]
# 或者: from Adafruit_BBIO.GPIO import setup [as 别名]
def __init__(self, pin):
self.pin = pin
GPIO.setup(pin, GPIO.OUT)
示例4: __init__
# 需要导入模块: from Adafruit_BBIO import GPIO [as 别名]
# 或者: from Adafruit_BBIO.GPIO import setup [as 别名]
def __init__(self, step_pin, dir_pin, fault_key, dac_channel, shiftreg_nr, name):
""" Init """
self.dac_channel = dac_channel # Which channel on the dac is connected to this stepper
self.step_pin = step_pin
self.dir_pin = dir_pin
self.fault_key = fault_key
self.name = name
self.enabled = False
self.in_use = False
self.steps_pr_mm = 1
self.microsteps = 1.0
self.microstepping = 0
self.direction = 1
self.current_disabled = False
# Set up the Shift register
ShiftRegister.make(8)
self.shift_reg = ShiftRegister.registers[shiftreg_nr]
# Set up the GPIO pins - we just have to initialize them so the PRU can flip them
# terrible hack to cover a bug in Adafruit
dir_name = "EHRPWM2A" if dir_pin == "GPIO0_22" else dir_pin
try:
GPIO.setup(dir_name, GPIO.OUT)
GPIO.setup(step_pin, GPIO.OUT)
except ValueError:
logging.warning("*** Stepper {} Pin {} initialization failure:".format(self.name, dir_name))
# Add a key code to the key listener
# Steppers have an nFAULT pin, so callback on falling
Key_pin(name, fault_key, Key_pin.FALLING, self.fault_callback)
示例5: __init__
# 需要导入模块: from Adafruit_BBIO import GPIO [as 别名]
# 或者: from Adafruit_BBIO.GPIO import setup [as 别名]
def __init__(self, m0, m1, m2):
GPIO.setup(m0, GPIO.OUT)
GPIO.setup(m1, GPIO.OUT)
GPIO.setup(m2, GPIO.OUT)
self.m0 = m0
self.m1 = m1
self.m2 = m2
示例6: __init__
# 需要导入模块: from Adafruit_BBIO import GPIO [as 别名]
# 或者: from Adafruit_BBIO.GPIO import setup [as 别名]
def __init__(self, bus=0, device=0, speed=1000000, pin_rst=def_pin_rst,
pin_ce=0, pin_irq=def_pin_irq, pin_mode = def_pin_mode):
self.pin_rst = pin_rst
self.pin_ce = pin_ce
self.pin_irq = pin_irq
self.spi = SPIClass()
self.spi.open(bus, device)
if board == RASPBERRY:
self.spi.max_speed_hz = speed
else:
self.spi.mode = 0
self.spi.msh = speed
if pin_mode is not None:
GPIO.setmode(pin_mode)
if pin_rst != 0:
GPIO.setup(pin_rst, GPIO.OUT)
GPIO.output(pin_rst, 1)
GPIO.setup(pin_irq, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(pin_irq, GPIO.FALLING,
callback=self.irq_callback)
if pin_ce != 0:
GPIO.setup(pin_ce, GPIO.OUT)
GPIO.output(pin_ce, 1)
self.init()
示例7: _set_digital_mode
# 需要导入模块: from Adafruit_BBIO import GPIO [as 别名]
# 或者: from Adafruit_BBIO.GPIO import setup [as 别名]
def _set_digital_mode(self, pin, mode):
GPIO.setup(pin.location, self.PIN_MODES[mode])