本文整理汇总了Python中RPi.GPIO.PUD_UP属性的典型用法代码示例。如果您正苦于以下问题:Python GPIO.PUD_UP属性的具体用法?Python GPIO.PUD_UP怎么用?Python GPIO.PUD_UP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类RPi.GPIO
的用法示例。
在下文中一共展示了GPIO.PUD_UP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [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
示例2: saks_gpio_init
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [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)
示例3: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [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
示例4: main
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [as 别名]
def main():
global pulses
## We're using BCM Mode
GPIO.setmode(GPIO.BCM)
## Setup coin interrupt channel
GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# GPIO.setup(PIN_COIN_INTERRUPT,GPIO.IN)
GPIO.add_event_detect(6, GPIO.FALLING, callback=coinEventHandler)
while True:
time.sleep(0.5)
if (time.time() - lastImpulse > 0.5) and (pulses > 0):
if pulses == 1:
print("Coin 1")
pulses = 0
GPIO.cleanup()
# handle the coin event
示例5: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [as 别名]
def __init__(self, config):
# Config
self.relay_pin = config['relay']
self.state_pin = config['state']
self.id = config['id']
self.mode = int(config.get('state_mode') == 'normally_closed')
self.invert_relay = bool(config.get('invert_relay'))
# Setup
self._state = None
self.onStateChange = EventHook()
# Set relay pin to output, state pin to input, and add a change listener to the state pin
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.relay_pin, GPIO.OUT)
GPIO.setup(self.state_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(self.state_pin, GPIO.BOTH, callback=self.__stateChanged, bouncetime=300)
# Set default relay state to false (off)
GPIO.output(self.relay_pin, self.invert_relay)
# Release rpi resources
示例6: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [as 别名]
def __init__(self):
self.__RESET = 26
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(self.__RESET, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Do not proceed unless the reset signal has turned off
# attempt to prevent restart storm in systemd
print("waiting for reset to complete.")
while GPIO.input(self.__RESET) != 1:
time.sleep(0.100)
pass
GPIO.add_event_detect(
self.__RESET, GPIO.FALLING, callback=onReset, bouncetime=100
)
print("GPIO initialized.")
示例7: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [as 别名]
def __init__(self, clockPin, dataPin, switchPin=None, rotaryCallback=None, switchCallback=None, rotaryBouncetime=250, switchBouncetime=300):
# persist values
self.clockPin = clockPin
self.dataPin = dataPin
self.switchPin = switchPin
self.rotaryCallback = rotaryCallback
self.switchCallback = switchCallback
self.rotaryBouncetime = rotaryBouncetime
self.switchBouncetime = switchBouncetime
#setup pins
GPIO.setup(clockPin, GPIO.IN)
GPIO.setup(dataPin, GPIO.IN)
if None != self.switchPin:
GPIO.setup(switchPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
示例8: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [as 别名]
def setup():
global counter
global Last_RoB_Status, Current_RoB_Status
GPIO.setmode(GPIO.BCM)
GPIO.setup(RoAPin, GPIO.IN)
GPIO.setup(RoBPin, GPIO.IN)
GPIO.setup(RoSPin,GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Set up a falling edge detect to callback clear
GPIO.add_event_detect(RoSPin, GPIO.FALLING, callback=clear)
# Set up a counter as a global variable
counter = 0
Last_RoB_Status = 0
Current_RoB_Status = 0
# Define a function to deal with rotary encoder
示例9: Setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [as 别名]
def Setup():
global logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.FileHandler('/var/log/rodi.log')
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(message)s',"%Y-%m-%d %H:%M:%S")
handler.setFormatter(formatter)
logger.addHandler(handler)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(WATER_VALVE, GPIO.OUT)
GPIO.setup(FLOATSW_HIGH_WL, GPIO.IN, pull_up_down=GPIO.PUD_UP) #, initial = GPIO.HIGH)
if not sys.stdout.isatty():
sys.stderr = open('/var/log/rodi_stderr.log', 'a')
sys.stdout = open('/var/log/rodi_stdout.log', 'a')
示例10: init
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [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)
示例11: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [as 别名]
def __init__(self,
controller: Controller,
button_gpio: int = 26,
led_gpio: int = 21) -> None:
self.button_gpio = button_gpio
self.controller = controller
GPIO.setmode(GPIO.BCM)
GPIO.setup(button_gpio, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(led_gpio, GPIO.OUT)
self.led_gpio = led_gpio
def call_back(channel: int) -> None:
def new_thread():
self.controller.update_and_redraw()
logger.info('Update of the screen due to button event')
thread = threading.Thread(target=new_thread)
thread.start()
GPIO.add_event_detect(button_gpio,
GPIO.FALLING,
callback=call_back,
bouncetime=500)
self.led_off()
示例12: initButtons
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [as 别名]
def initButtons():
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(9, GPIO.IN, pull_up_down=GPIO.PUD_UP)
示例13: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [as 别名]
def __init__(self, gpio = None, trigger = GPIO.FALLING, resistorpull = GPIO.PUD_UP, log = None, callback = None, uselibcallbacks = False, bouncetime = None):
super(MyGPIOInput, self).__init__()
self.Trigger = trigger
self.ResistorPull = resistorpull
self.GPIO = gpio
self.log = log
self.TimeoutSeconds = 1
self.BounceTime = bouncetime
self.Callback = callback
self.UseLibCallbacks = uselibcallbacks
self.Exiting = False
try:
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(True)
GPIO.setup(gpio, GPIO.IN, pull_up_down=resistorpull)
if callback != None and callable(callback):
if self.BounceTime > 0:
GPIO.add_event_detect(gpio = self.GPIO, edge = self.Trigger, bouncetime = self.BounceTime)
else:
GPIO.add_event_detect(gpio = self.GPIO, edge = self.Trigger)
if self.UseLibCallbacks:
GPIO.add_event_callback(gpio = self.GPIO, callback = self.Callback)
else:
# setup callback
self.Threads["GPIOInputMonitor"] = MyThread(self.GPIOInputMonitor, Name = "GPIOInputMonitor", start = False)
self.Threads["GPIOInputMonitor"].Start()
except Exception as e1:
self.LogErrorLine("Error in MyGPIOInput:init: " + str(gpio) + " : " + str(e1))
#-----------------GPIOInputMonitor------------------------------------------
示例14: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [as 别名]
def __init__(
self, event_queue, config_name, input_pin, output_pin, initial_output=GPIO.LOW
):
super(BasePinThread, self).__init__(event_queue, config_name)
self.input_pin = input_pin
self.output_pin = output_pin
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False) # for reusing pins
if self.input_pin:
GPIO.setup(self.input_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
if self.output_pin:
GPIO.setup(self.output_pin, GPIO.OUT, initial=initial_output)
示例15: saks_gpio_init
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PUD_UP [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.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.LEDS + PINS.DIGITAL_DISPLAY + PINS.DIGITAL_DISPLAY_SELECT:
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)
#GPIO.setup(p, GPIO.IN)
#由于SAKS的蓝色LED和数码管共享引脚,此处将数码管位选关闭,只让信号作用于LED
#GPIO.setup(17, GPIO.OUT, initial = GPIO.HIGH)
#GPIO.setup(27, GPIO.OUT, initial = GPIO.HIGH)
#GPIO.setup(22, GPIO.OUT, initial = GPIO.HIGH)
#GPIO.setup(10, GPIO.OUT, initial = GPIO.HIGH)