本文整理汇总了Python中RPi.GPIO.input方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.input方法的具体用法?Python GPIO.input怎么用?Python GPIO.input使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RPi.GPIO
的用法示例。
在下文中一共展示了GPIO.input方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeByte
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [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: getValue
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def getValue():
GPIO.output(ptrig, 0)
time.sleep(0.1)
GPIO.output(ptrig, 1)
time.sleep(0.00001)
GPIO.output(ptrig, 0)
while(0 == GPIO.input(pecho)):
start = time.time()
while(1 == GPIO.input(pecho)):
end = time.time()
delay = (end - start) * 1000 * 1000
time.sleep(0.1)
distance = (delay / 58.0)
if 2 < distance < 400: # working interval
print("distance: %0.1f cm" % distance)
示例3: readUltrasonicSensor
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [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
示例4: test_auth_flow
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def test_auth_flow(self):
# Out of the box, relay should be off
self.assertFalse(self.dispatcher.authorized)
self.assertFalse(GPIO.input(5))
# Badge scan sets authorized flag, but doesn't enable relay until button
# press.
self.dispatcher.badge_scan('1234')
self.assertTrue(self.dispatcher.authorized)
self.assertFalse(GPIO.input(5))
# "On" button pressed
self.dispatcher.on_button_down(None)
self.assertTrue(self.dispatcher.authorized)
self.assertTrue(GPIO.input(5))
# "Off" button pressed
self.dispatcher.abort(None)
self.assertFalse(self.dispatcher.authorized)
self.assertFalse(GPIO.input(5))
示例5: make_event
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def make_event(self, channel):
if self.__real_true:
if GPIO.input(self.__pins[0]) != self.__status[0]:
self.__status[0] = GPIO.input(self.__pins[0])
self.status_changed()
if GPIO.input(self.__pins[1]) != self.__status[1]:
self.__status[1] = GPIO.input(self.__pins[1])
self.status_changed()
else:
if GPIO.input(self.__pins[0]) == self.__status[0]:
self.__status[0] = not GPIO.input(self.__pins[0])
self.status_changed()
if GPIO.input(self.__pins[1]) == self.__status[1]:
self.__status[1] = not GPIO.input(self.__pins[1])
self.status_changed()
示例6: watching
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def watching(self):
if self.__real_true:
while True:
if GPIO.input(self.__pins[0]) != self.__status[0]:
self.__status[0] = GPIO.input(self.__pins[0])
self.status_changed()
if GPIO.input(self.__pins[1]) != self.__status[1]:
self.__status[1] = GPIO.input(self.__pins[1])
self.status_changed()
time.sleep(0.05)
else:
while True:
if GPIO.input(self.__pins[0]) == self.__status[0]:
self.__status[0] = not GPIO.input(self.__pins[0])
self.status_changed()
if GPIO.input(self.__pins[1]) == self.__status[1]:
self.__status[1] = not GPIO.input(self.__pins[1])
self.status_changed()
time.sleep(0.05)
示例7: run
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def run(self):
while not self.stoprequest.isSet():
button_state = GPIO.input(10)
if button_state is True:
# True => button pressed
# False => button not pressed
time.sleep(1)
else:
# Alarm! case open
if DEBUG:
print('Awwwwww Case Open!!!! GAME OVER')
self.bang()
if DEBUG:
#subprocess.call('echo o >/proc/sysrq-trigger', shell=True)
print('Sayonara')
os._exit(1)
示例8: enable_auto_lights
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def enable_auto_lights(state):
global _t_update_lights
setup()
if sn3218 is None:
return
input.auto_light(state)
output.auto_light(state)
relay.auto_light(state)
analog.auto_light(state)
if state and _t_update_lights is None:
_t_update_lights = AsyncWorker(_update_lights)
_t_update_lights.start()
if not state and _t_update_lights is not None:
_t_update_lights.stop()
_t_update_lights.join()
_t_update_lights = None
示例9: start
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def start():
last = GPIO.input(button)
while True:
val = GPIO.input(button)
GPIO.wait_for_edge(button, GPIO.FALLING) # we wait for the button to be pressed
GPIO.output(lights[1], GPIO.HIGH)
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, device)
inp.setchannels(1)
inp.setrate(16000)
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
inp.setperiodsize(500)
audio = ""
while(GPIO.input(button)==0): # we keep recording while the button is pressed
l, data = inp.read()
if l:
audio += data
rf = open(path+'recording.wav', 'w')
rf.write(audio)
rf.close()
inp = None
alexa()
示例10: _getSensorValue
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def _getSensorValue(self):
#return random_bin()
return GPIO.input(self.pin)
示例11: eventRotary
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def eventRotary(e):
if (GPIO.input(bPin) != GPIO.input(aPin)): # a changed before b
print('Rotating clockwise')
#position -= 1
else:
print('Rotating counterclockwise')
#position += 1
示例12: eventTrack
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def eventTrack(e):
print("Tracked!")
while(GPIO.input(e) == GPIO.HIGH): # waits until signal is off
pass
示例13: read_data
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def read_data(pin):
data = 0
for i in range(8):
if (GPIO.input(pin) == GPIO.LOW):
while (GPIO.input(pin) == GPIO.LOW): # wait for 50us
pass
time.sleep(30 * 1e-6) # determine the duration of the high level to determine the data is '0 'or '1'
if (GPIO.input(pin) == GPIO.HIGH):
data |= (1 << (7-i)) # high front and low in the post
while (GPIO.input(pin) == GPIO.HIGH): # data '1 ', wait for the next one receiver
pass
return data
示例14: yellow_is_on
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def yellow_is_on(self):
return GPIO.input(self.yellow_pin)
示例15: center
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import input [as 别名]
def center(self, trigger_pin, pct, fromState):
#to center a frame in the gate and position the projector
#mechanism properly relative to the photo trigger (i.e. 'pct'
#distance ahead of it. Winding film backwards doesn't position
#correctly, so we need to bump ahead a frame to position after
#rewinding
while GPIO.input(trigger_pin): #if trigger is engaging,reverse NO, FORWARD until it's not
GPIO.output(self.dir_pin, False) #True)
GPIO.output(self.pulse_pin, True)
time.sleep(.001)
GPIO.output(self.pulse_pin, False)
time.sleep(.001)
time.sleep(.2)
while not GPIO.input(trigger_pin): #then forward until it is
GPIO.output(self.dir_pin, False)
GPIO.output(self.pulse_pin, True)
time.sleep(.001)
GPIO.output(self.pulse_pin, False)
time.sleep(.001)
if fromState==-1: #if we had been reversing, jump forward a frame
self.windFrame(1)
logging.debug("Winding 1 frame")
stepsFwd=int(self.steps_per_rev*(100-pct)/100.0)
GPIO.output(self.dir_pin, False)
time.sleep(.01)
logging.debug("Forward "+str(stepsFwd))
for i in range(0,stepsFwd): #now forward enough to leave a proper cushion
GPIO.output(self.pulse_pin, True)
time.sleep(.001)
GPIO.output(self.pulse_pin, False)
time.sleep(.001)