本文整理汇总了Python中RPi.GPIO.BOTH属性的典型用法代码示例。如果您正苦于以下问题:Python GPIO.BOTH属性的具体用法?Python GPIO.BOTH怎么用?Python GPIO.BOTH使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类RPi.GPIO
的用法示例。
在下文中一共展示了GPIO.BOTH属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, pin, real_true = GPIO.HIGH):
'''
Init the tact
:param pin: pin number in array
:param real_true: GPIO.HIGH or GPIO.LOW
:return: void
'''
self.__pin = pin
self.__real_true = real_true
if self.__real_true:
self.__status = GPIO.input(self.__pin)
else:
self.__status = not GPIO.input(self.__pin)
GPIO.add_event_detect(pin, GPIO.BOTH, callback = self.make_event, bouncetime = 1)
try:
t1 = Thread(target = self.watching)
t1.setDaemon(True)
except:
print "Error: Unable to start thread by Tact"
#Stauts.
示例2: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, port="5550"):
self.__bind_addr = "tcp://*:%s" % port
app.logger.info("Bind address: " + self.__bind_addr)
self.__relay_lock = threading.Lock()
self.__db = GarageDb(app.instance_path, app.resource_path)
# Get initial reed state and subscribe to events
GPIO.setup(app.config['REED_PIN'], GPIO.IN)
GPIO.add_event_detect(app.config['REED_PIN'], GPIO.BOTH, callback=self.door_opened_or_closed)
self.__door_state = None # 1 for open, 0 for closed, None for uninitialized
self.door_opened_or_closed(app.config['REED_PIN']) # force update
# Set up warning timer if there's a setting
if app.config['DOOR_OPEN_WARNING_TIME']:
app.logger.info('Starting schedule to check door at {0}...'.format(app.config['DOOR_OPEN_WARNING_TIME']))
schedule.every().day.at(app.config['DOOR_OPEN_WARNING_TIME']).do(self.check_door_open_for_warning)
t = Thread(target=self.run_schedule)
t.start()
else:
app.logger.info('No schedule to run.')
示例3: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self):
# Set GPIO mode to Broadcom SOC numbering
GPIO.setmode(GPIO.BCM)
# Listen for rotary movements
GPIO.setup(self.pin_rotary, GPIO.IN)
GPIO.add_event_detect(self.pin_rotary, GPIO.BOTH, callback = self.NumberCounter)
# Listen for on/off hooks
GPIO.setup(self.pin_onhook, GPIO.IN)
GPIO.add_event_detect(self.pin_onhook, GPIO.BOTH, callback = self.HookEvent, bouncetime=100)
self.onhook_timer = Timer(2, self.verifyHook)
self.onhook_timer.start()
# Handle counting of rotary movements and respond with digit after timeout
示例4: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [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
示例5: _setup_callback
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def _setup_callback(self, bouncetime):
if self.has_callback:
return False
def handle_callback(pin):
if self.read() == 1 and callable(self.handle_pressed):
self.handle_pressed(self)
elif self.read() == 0 and callable(self.handle_released):
self.handle_released(self)
if callable(self.handle_changed):
self.handle_changed(self)
self._setup_gpio()
GPIO.add_event_detect(self.pin, GPIO.BOTH, callback=handle_callback, bouncetime=bouncetime)
self.has_callback = True
return True
示例6: init
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def init(self, switch_pin=None, clock_pin=None, data_pin=None, **kwargs):
_log.info("setup")
self._switch_pin = switch_pin
self._clock_pin = clock_pin
self._data_pin = data_pin
gpio.setmode(gpio.BCM)
if self._switch_pin:
_log.info("Setting up button pin")
gpio.setup(self._switch_pin, gpio.IN, gpio.PUD_UP)
gpio.add_event_detect(self._switch_pin, gpio.BOTH, callback=self._switch_cb, bouncetime=2)
if self._data_pin:
_log.info("Setting up data pin")
gpio.setup(self._data_pin, gpio.IN)
if self._clock_pin:
gpio.setup(self._clock_pin, gpio.IN, gpio.PUD_UP)
gpio.add_event_detect(self._clock_pin, gpio.FALLING, callback=self._knob_cb, bouncetime=2)
self._values = []
_log.info("Systems are go")
示例7: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, hw_model):
self.callback = None
self.button_sequence = 0
self.button_timer = None
self.button_sequence_lock = Lock()
self.button_state = "up"
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)
if hw_model == NabIO.MODEL_2018:
self.button_channel = ButtonGPIO.BUTTON_CHANNEL_2018
else:
self.button_channel = ButtonGPIO.BUTTON_CHANNEL_2019
GPIO.setup(self.button_channel, GPIO.IN)
try:
GPIO.add_event_detect(
self.button_channel, GPIO.BOTH, callback=self._button_event
)
except RuntimeError:
print("Could not set edge detection (please reboot ?)")
sys.exit(1)
示例8: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, pins, real_true = GPIO.HIGH):
'''
Init the dip switch
:param pin: pin numbers in array
:param real_true: GPIO.HIGH or GPIO.LOW
:return: void
'''
self.__pins = pins
self.__real_true = real_true
for p in pins:
self.__status.append(not real_true)
if self.__real_true:
self.__status[0] = GPIO.input(self.__pins[0])
self.__status[1] = GPIO.input(self.__pins[1])
else:
self.__status[0] = not GPIO.input(self.__pins[0])
self.__status[1] = not GPIO.input(self.__pins[1])
GPIO.add_event_detect(self.__pins[0], GPIO.BOTH, callback = self.make_event, bouncetime = 50)
GPIO.add_event_detect(self.__pins[1], GPIO.BOTH, callback = self.make_event, bouncetime = 50)
try:
t1 = Thread(target = self.watching)
t1.setDaemon(True)
#t1.start()
except:
print("Error: Unable to start thread by DipSwitch")
#Stauts.
示例9: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, pin, real_true = GPIO.HIGH):
'''
Init the tact
:param pin: pin number in array
:param real_true: GPIO.HIGH or GPIO.LOW
:return: void
'''
self.__pin = pin
self.__real_true = real_true
if self.__real_true:
self.__status = GPIO.input(self.__pin)
else:
self.__status = not GPIO.input(self.__pin)
GPIO.add_event_detect(pin, GPIO.BOTH, callback = self.make_event, bouncetime = 1)
try:
t1 = Thread(target = self.watching)
t1.setDaemon(True)
#t1.start()
except:
print("Error: Unable to start thread by Tact")
#Stauts.
示例10: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def setup(self):
"""Set up the GPIO button."""
if self._is_setup:
return
GPIO.setup(self._gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(self._gpio_pin, GPIO.BOTH, bouncetime=1, callback=self._handle_button)
self._is_setup = True
示例11: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self):
super(myDriver, self).__init__()
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_INP, GPIO.IN)
GPIO.setup(PIN_OUT, GPIO.OUT)
GPIO.setup(PIN_PWM, GPIO.OUT)
GPIO.add_event_detect(PIN_INP, GPIO.BOTH, callback=self.input_callback)
self.pwm = GPIO.PWM(PIN_PWM, 1) # 1 Hz
示例12: initialize_gpio
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def initialize_gpio():
GPIO.setmode(GPIO.BOARD)
GPIO.setup([11, 32, 36], GPIO.OUT) # LEDs: Blue (metronome), Green (ok), Red (error)
GPIO.setup(31, GPIO.IN)
GPIO.output([32, 36], GPIO.LOW)
GPIO.add_event_detect(31, GPIO.BOTH, callback=intercept_morse_code)
# Blink a blue LED on/off (one full cycle per BASE_TIME_SECONDS)
示例13: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, pins, real_true = GPIO.HIGH):
'''
Init the dip switch
:param pin: pin numbers in array
:param real_true: GPIO.HIGH or GPIO.LOW
:return: void
'''
self.__pins = pins
self.__real_true = real_true
for p in pins:
self.__status.append(not real_true)
if self.__real_true:
self.__status[0] = GPIO.input(self.__pins[0])
self.__status[1] = GPIO.input(self.__pins[1])
else:
self.__status[0] = not GPIO.input(self.__pins[0])
self.__status[1] = not GPIO.input(self.__pins[1])
GPIO.add_event_detect(self.__pins[0], GPIO.BOTH, callback = self.make_event, bouncetime = 50)
GPIO.add_event_detect(self.__pins[1], GPIO.BOTH, callback = self.make_event, bouncetime = 50)
try:
t1 = Thread(target = self.watching)
t1.setDaemon(True)
except:
print "Error: Unable to start thread by DipSwitch"
#Stauts.