本文整理汇总了Python中RPi.GPIO.setmode方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.setmode方法的具体用法?Python GPIO.setmode怎么用?Python GPIO.setmode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RPi.GPIO
的用法示例。
在下文中一共展示了GPIO.setmode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def __init__(self, id, params):
super(Buzzer, self).__init__(id, params)
try:
self.duration = int(params["duration"])
self.gpio_pin = int(params["gpio_pin"])
except KeyError as ke: # if config parameters are missing in file
logging.error("Buzzer: Wasn't able to initialize the device, it seems there is a config parameter missing: %s" % ke)
self.corrupted = True
return
except ValueError as ve: # if a parameter can't be parsed as int
logging.error("Buzzer: Wasn't able to initialize the device, please check your configuration: %s" % ve)
self.corrupted = True
return
try:
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.gpio_pin, GPIO.OUT)
except ValueError as ve: # GPIO pin number is not in valid range
logging.error("Buzzer: The given pin number is not in a valid range: %s" % ve)
self.corrupted = True
return
logging.debug("Buzzer: Audio device initialized")
示例2: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def __init__(self, id, params, worker):
super(GPIOSensor, self).__init__(id, params, worker)
self.active = False
try:
self.gpio = int(params["gpio"])
self.bouncetime = int(self.params['bouncetime'])
except ValueError as ve: # if one configuration parameter can't be parsed as int
logging.error("GPIOSensor: Wasn't able to initialize the sensor, please check your configuration: %s" % ve)
self.corrupted = True
return
except KeyError as ke: # if config parameters are missing in the file
logging.error("GPIOSensor: Wasn't able to initialize the sensor, it seems there is a config parameter missing: %s" % ke)
self.corrupted = True
return
GPIO.setmode(GPIO.BCM)
logging.debug("GPIOSensor: Sensor initialized")
示例3: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def __init__(self):
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(self.MotorFront1, GPIO.OUT)
GPIO.setup(self.MotorFront2, GPIO.OUT)
GPIO.setup(self.MotorFront, GPIO.OUT)
GPIO.output(self.MotorFront, 0)
GPIO.setup(self.MotorBack1, GPIO.OUT)
GPIO.setup(self.MotorBack2, GPIO.OUT)
GPIO.setup(self.MotorBack, GPIO.OUT)
GPIO.output(self.MotorBack, 0)
self.BackPWM = GPIO.PWM(self.MotorBack,100)
self.BackPWM.start(0)
self.BackPWM.ChangeDutyCycle(0)
self.direction = 0
示例4: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def __init__(self):
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.dir_pin, GPIO.OUT)
GPIO.setup(self.pulse_pin, GPIO.OUT)
GPIO.setup(self.ms1_pin, GPIO.OUT)
GPIO.setup(self.ms2_pin, GPIO.OUT)
GPIO.setup(self.sleep_pin, GPIO.OUT)
GPIO.setup(self.reset_pin, GPIO.OUT)
dir=False
GPIO.output(self.dir_pin, dir)
GPIO.output(self.pulse_pin, False)
GPIO.output(self.ms1_pin, True)
GPIO.output(self.ms2_pin, False)
GPIO.output(self.sleep_pin, False)
GPIO.output(self.reset_pin, True)
self.p1 = GPIO.PWM(self.pulse_pin, self.pulse_freq)
示例5: InitHardware
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def InitHardware(self):
# NOTE: This function assumes the underlying hardware is the LTE Cat 1 Pi Hat
# http://wiki.seeedstudio.com/LTE_Cat_1_Pi_HAT/
try:
self.power_pin = 29
self.reset_pin = 31
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(self.power_pin, GPIO.OUT) # Setup module power pin
GPIO.setup(self.reset_pin, GPIO.OUT) # Setup module reset pin
GPIO.output(self.power_pin, False)
GPIO.output(self.reset_pin, False)
return self.PowerUp()
except Exception as e1:
self.LogErrorLine("Error in LTEPiHat:InitHardware: " + str(e1))
return False
#------------------LTEPiHat::PowerDown-------------------------------------
示例6: saks_gpio_init
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def saks_gpio_init(self):
#print 'saks_gpio_init'
GPIO.setwarnings(False)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(PINS.BUZZER, GPIO.OUT)
GPIO.output(PINS.BUZZER, GPIO.HIGH)
for p in [PINS.IC_TM1637_DI, PINS.IC_TM1637_CLK, PINS.IC_74HC595_DS, PINS.IC_74HC595_SHCP, PINS.IC_74HC595_STCP]:
GPIO.setup(p, GPIO.OUT)
GPIO.output(p, GPIO.LOW)
for p in [PINS.BUZZER, PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]:
GPIO.setup(p, GPIO.OUT)
GPIO.output(p, GPIO.HIGH)
for p in [PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]:
GPIO.setup(p, GPIO.IN, pull_up_down = GPIO.PUD_UP)
示例7: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def setup():
"""Setup piezo buzzer."""
global _is_setup, pwm
if _is_setup:
return
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(BUZZER, GPIO.OUT)
# Set up the PWM and then set the pin to input
# to prevent the signal from being output.
# Since starting/stopping PWM causes a segfault,
# this is the only way to manage the buzzer.
pwm = GPIO.PWM(BUZZER, 1)
GPIO.setup(BUZZER, GPIO.IN)
pwm.start(50)
_is_setup = True
示例8: show
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def show():
"""Output the buffer."""
global _gpio_setup
if not _gpio_setup:
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup([DAT, CLK, CS], GPIO.OUT)
_gpio_setup = True
GPIO.output(CS, 0)
_sof()
for pixel in pixels:
r, g, b, brightness = pixel
_write_byte(0b11100000 | brightness)
_write_byte(b)
_write_byte(g)
_write_byte(r)
_eof()
GPIO.output(CS, 1)
示例9: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def __init__(self,
channel,
polarity=GPIO.FALLING,
pull_up_down=GPIO.PUD_UP,
debounce_time=0.08):
if polarity not in [GPIO.FALLING, GPIO.RISING]:
raise ValueError(
'polarity must be one of: GPIO.FALLING or GPIO.RISING')
self.channel = int(channel)
self.polarity = polarity
self.expected_value = polarity == GPIO.RISING
self.debounce_time = debounce_time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(channel, GPIO.IN, pull_up_down=pull_up_down)
self.callback = None
示例10: init_process
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def init_process():
print " "
print "MSG - [S100, T110 CO2 Sensor Driver on RASPI2, Please check log file : ", LOG_PATH
print "MSG - now starting to read SERIAL PORT"
print " "
# HW setup, GPIO
GPIO.setwarnings(False)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.setup(25, GPIO.OUT)
logger.info(' *start* GPIO all set, trying to open serial port, SW starting ')
rledAllOn()
######################################################################
# START Here. Main
######################################################################
# set logger file
示例11: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def __init__(self, left_p=13, right_p=15, forward_p=12, backward_p=11,
apply_time=0.3, wait_time=0):
self.left_p = left_p
self.right_p = right_p
self.forward_p = forward_p
self.backward_p = backward_p
self.apply_time = apply_time
self.wait_time = wait_time
print("Setting up GPIO pins.")
GPIO.setmode(GPIO.BOARD)
GPIO.setup(self.backward_p, GPIO.OUT) # Backwards.
GPIO.setup(self.forward_p, GPIO.OUT) # Forwards.
GPIO.setup(self.left_p, GPIO.OUT) # Left.
GPIO.setup(self.right_p, GPIO.OUT) # Right.
# Reset in case they're still on from before.
GPIO.output(self.backward_p, 0)
GPIO.output(self.forward_p, 0)
GPIO.output(self.left_p, 0)
GPIO.output(self.right_p, 0)
示例12: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def setup():
global _is_setup
if _is_setup:
return True
atexit.register(_exit)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup([DAT, CLK], GPIO.OUT)
GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP)
for button in BUTTONS:
GPIO.add_event_detect(button, GPIO.FALLING, callback=_handle_button, bouncetime=200)
_is_setup = True
示例13: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def __init__(self):
self.gpio=gpio
gpio.setmode(gpio.BOARD)
示例14: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def setup():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(pd, GPIO.OUT)
GPIO.setup(pc, GPIO.OUT)
GPIO.output(pd,0)
GPIO.output(pc,0)
#sendData(CmdMode)
for i in range(1,13):
sendData(OFF)
latchData()
示例15: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setmode [as 别名]
def __init__(self, pin=27, frequency=1000, duration=100):
self.pin = pin
self.frequency = frequency
self.duration = duration
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)