本文整理汇总了Python中RPi.GPIO.IN属性的典型用法代码示例。如果您正苦于以下问题:Python GPIO.IN属性的具体用法?Python GPIO.IN怎么用?Python GPIO.IN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类RPi.GPIO
的用法示例。
在下文中一共展示了GPIO.IN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeByte
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [as 别名]
def writeByte(self, data):
for i in range(0, 8):
IO.output(self.__Clkpin, IO.LOW)
if(data & 0x01):
IO.output(self.__Datapin, IO.HIGH)
else:
IO.output(self.__Datapin, IO.LOW)
data = data >> 1
IO.output(self.__Clkpin, IO.HIGH)
# wait for ACK
IO.output(self.__Clkpin, IO.LOW)
IO.output(self.__Datapin, IO.HIGH)
IO.output(self.__Clkpin, IO.HIGH)
IO.setup(self.__Datapin, IO.IN)
while(IO.input(self.__Datapin)):
sleep(0.001)
if(IO.input(self.__Datapin)):
IO.setup(self.__Datapin, IO.OUT)
IO.output(self.__Datapin, IO.LOW)
IO.setup(self.__Datapin, IO.IN)
IO.setup(self.__Datapin, IO.OUT)
示例2: readUltrasonicSensor
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [as 别名]
def readUltrasonicSensor():
GPIO.setup(TRIGGER_PIN, GPIO.OUT)
GPIO.setup(SENSOR_PIN, GPIO.IN)
GPIO.output(TRIGGER_PIN, GPIO.LOW)
time.sleep(0.3)
GPIO.output(TRIGGER_PIN, True)
time.sleep(0.00001)
GPIO.output(TRIGGER_PIN, False)
while GPIO.input(SENSOR_PIN) == 0:
signaloff = time.time()
while GPIO.input(SENSOR_PIN) == 1:
signalon = time.time()
timepassed = signalon - signaloff
distance = timepassed * 17000
if distance < threshold:
return 1
else:
return 0
示例3: saks_gpio_init
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [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)
示例4: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [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
示例5: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [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
示例6: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [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
示例7: main
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [as 别名]
def main():
try:
while True:
for led in LEDS:
for idx, pin in enumerate(led):
if pin == O:
GPIO.setup(PINS[idx], GPIO.IN)
else:
GPIO.setup(PINS[idx], GPIO.OUT)
GPIO.output(PINS[idx], pin)
time.sleep(.1)
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
示例8: setup_sensor
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [as 别名]
def setup_sensor(self):
try:
GPIO.setup(self.gpio, GPIO.IN)
GPIO.add_event_detect(self.gpio, GPIO.RISING, callback=self.cb_alarm, bouncetime=self.bouncetime)
except ValueError as ve: # GPIO pin number or bouncetime is not in valid range
logging.error("GPIOSensor: The given pin number or bouncetime is not in a valid range: %s" % ve)
return
logging.debug("GPIOSensor: Registered sensor at pin %s!" % self.gpio)
示例9: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [as 别名]
def __init__(self, thread_id, notification_queue, sleeptime, pin = 27):
super().__init__(thread_id, notification_queue, sleeptime) # python 3 syntax only
self.pin = pin
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
示例10: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [as 别名]
def setup():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(pecho, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(ptrig, GPIO.OUT)
GPIO.output(ptrig, 0)
示例11: initButtons
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [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)
示例12: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [as 别名]
def __init__(self, triggerpin):
GPIO.setup(triggerpin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
self.pin = triggerpin
示例13: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [as 别名]
def __init__(self):
GPIO.setmode(GPIO.BCM)
self.light = lightControl(self.light_pin, True)
self.redled = lightControl(self.red_pin)
self.yellowled = lightControl(self.yellow_pin)
self.motor = stepperControl()
GPIO.setup(self.trigger_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
self.motorstate = 0
self.smart_motor = False
self.smart_headroom = 25
self.triggertime = 0
self.qlen = 5
self.triggertimes = collections.deque([],self.qlen)
self.phototimes = collections.deque([],self.qlen)
示例14: set_pin
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [as 别名]
def set_pin(pin_index, pin_state):
if pin_state == -1:
GPIO.setup(pins[pin_index], GPIO.IN)
else:
GPIO.setup(pins[pin_index], GPIO.OUT)
GPIO.output(pins[pin_index], pin_state)
示例15: charge_time
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import IN [as 别名]
def charge_time():
t1 = time.time()
GPIO.setup(pin, GPIO.IN)
while not GPIO.input(pin):
# charge for 1ms
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, True)
time.sleep(0.001)
# set to input to test again
GPIO.setup(pin, GPIO.IN)
time.sleep(0.001)
t2 = time.time()
return (t2 - t1) * 1000000
# Take an analog reading as the time taken to charge C