Python RPi.GPIO.input() Examples
The following are 30
code examples of RPi.GPIO.input().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
RPi.GPIO
, or try the search function
.
Example #1
Source File: dip_switch_2bit.py From SAKS-SDK with GNU General Public License v2.0 | 7 votes |
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)
Example #2
Source File: main.py From AlexaPiDEPRECATED with MIT License | 7 votes |
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()
Example #3
Source File: __init__.py From automation-hat with MIT License | 7 votes |
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
Example #4
Source File: tm1637.py From raspberrypi-examples with MIT License | 6 votes |
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)
Example #5
Source File: ultrasonic-distance.py From raspberrypi-examples with MIT License | 6 votes |
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)
Example #6
Source File: dip_switch_2bit.py From SAKS-SDK with GNU General Public License v2.0 | 6 votes |
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()
Example #7
Source File: test_two_button.py From makerspace-auth with Apache License 2.0 | 6 votes |
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))
Example #8
Source File: circo.py From circo with MIT License | 6 votes |
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)
Example #9
Source File: controller.py From ran-django-template with GNU General Public License v3.0 | 6 votes |
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
Example #10
Source File: epdif.py From epd-library-python with GNU General Public License v3.0 | 5 votes |
def epd_digital_read(pin): return GPIO.input(pin)
Example #11
Source File: rpi_gpio.py From pcaspy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def input_callback(self, channel): level = GPIO.input(channel) self.setParam('INP', level) if level == 0: self.setParam('TRIGED', 2) elif level == 1: self.setParam('TRIGED', 1) self.updatePVs()
Example #12
Source File: epdif.py From epd-library-python with GNU General Public License v3.0 | 5 votes |
def epd_digital_read(pin): return GPIO.input(pin)
Example #13
Source File: epdif.py From epd-library-python with GNU General Public License v3.0 | 5 votes |
def epd_digital_read(pin): return GPIO.input(pin)
Example #14
Source File: epdif.py From epd-library-python with GNU General Public License v3.0 | 5 votes |
def epd_digital_read(pin): return GPIO.input(pin)
Example #15
Source File: sensors.py From rl-rc-car with MIT License | 5 votes |
def get_reading(self): return gpio.input(self.in_p)
Example #16
Source File: GPIOq.py From atlas-python with MIT License | 5 votes |
def digitalRead(pin): return GPIO.input(pin)
Example #17
Source File: GPIOq.py From atlas-python with MIT License | 5 votes |
def digitalRead(pin): return GPIO.input(pin)
Example #18
Source File: hx711.py From pydPiper with MIT License | 5 votes |
def is_ready(self): return GPIO.input(self.DOUT) == 0
Example #19
Source File: hx711.py From pydPiper with MIT License | 5 votes |
def read(self): while not self.is_ready(): #print("WAITING") pass dataBits = [self.createBoolList(), self.createBoolList(), self.createBoolList()] dataBytes = [0x0] * 4 for j in range(self.byte_range_values[0], self.byte_range_values[1], self.byte_range_values[2]): for i in range(self.bit_range_values[0], self.bit_range_values[1], self.bit_range_values[2]): GPIO.output(self.PD_SCK, True) dataBits[j][i] = GPIO.input(self.DOUT) GPIO.output(self.PD_SCK, False) dataBytes[j] = numpy.packbits(numpy.uint8(dataBits[j])) #set channel and gain factor for next reading for i in range(self.GAIN): GPIO.output(self.PD_SCK, True) GPIO.output(self.PD_SCK, False) #check for all 1 #if all(item is True for item in dataBits[0]): # return long(self.lastVal) dataBytes[2] ^= 0x80 return dataBytes
Example #20
Source File: tact.py From SAKS-SDK with GNU General Public License v2.0 | 5 votes |
def is_on(self): ''' Get current of tact ''' if self.__real_true: if self.__status != GPIO.input(self.__pin): self.__status = GPIO.input(self.__pin) else: if self.__status == GPIO.input(self.__pin): self.__status = not GPIO.input(self.__pin) return self.__status #Events
Example #21
Source File: epdif.py From epd-library-python with GNU General Public License v3.0 | 5 votes |
def epd_digital_read(pin): return GPIO.input(pin)
Example #22
Source File: epdif.py From epd-library-python with GNU General Public License v3.0 | 5 votes |
def epd_digital_read(pin): return GPIO.input(pin)
Example #23
Source File: inky212x104.py From inky-phat with MIT License | 5 votes |
def _busy_wait(self): """Wait for the e-paper driver to be ready to receive commands/data. """ wait_for = GPIO.HIGH if self.inky_version == 2: wait_for = GPIO.LOW while(GPIO.input(self.busy_pin) != wait_for): pass
Example #24
Source File: read_sensors_d.py From openplotter with GNU General Public License v2.0 | 5 votes |
def publish_sk(io,channel,current_state,name): if io=='in':io='input' else: io='output' if current_state: current_state='1' else: current_state='0' SignalK='{"updates":[{"$source":"OPnotifications.GPIO.'+io+'.'+str(channel)+'","values":[{"path":"sensors.'+name+'","value":'+current_state+'}]}]}\n' sock.sendto(SignalK, ('127.0.0.1', 55558))
Example #25
Source File: read_sensors_d.py From openplotter with GNU General Public License v2.0 | 5 votes |
def work_gpio(): threading.Timer(rate_gpio, work_gpio).start() c=0 for i in gpio_list: channel=int(i[2]) name = i[0] current_state = GPIO.input(channel) last_state=gpio_list[c][4] if current_state!=last_state: gpio_list[c][4]=current_state publish_sk(i[1],channel,current_state, name) c+=1
Example #26
Source File: _button.py From ai-makers-kit with MIT License | 5 votes |
def _debounce(self): start = time.time() while time.time() < start + self.debounce_time: if GPIO.input(self.channel) != self.expected_value: return False time.sleep(0.01) return True
Example #27
Source File: _button.py From ai-makers-kit with MIT License | 5 votes |
def _debounce(self): start = time.time() while time.time() < start + self.debounce_time: if GPIO.input(self.channel) != self.expected_value: return False time.sleep(0.01) return True
Example #28
Source File: touch.py From rainbow-hat with MIT License | 5 votes |
def _handle_button(self, pin): self.pressed = GPIO.input(pin) != GPIO.HIGH if self.pressed and callable(self._on_press_handler): try: self._on_press_handler(self._index, self._gpio_pin) except TypeError: self._on_press_handler(self._index) elif callable(self._on_release_handler): try: self._on_release_handler(self._index, self._gpio_pin) except TypeError: self._on_release_handler(self._index)
Example #29
Source File: tact.py From SAKS-SDK with GNU General Public License v2.0 | 5 votes |
def watching(self): if self.__real_true: while True: if GPIO.input(self.__pin) != self.__status: self.__status = GPIO.input(self.__pin) self.notify_observers(self.__real_true if self.__status else not self.__real_true) time.sleep(0.05) else: while True: if GPIO.input(self.__pin) == self.__status: self.__status = not GPIO.input(self.__pin) self.notify_observers(self.__real_true if not self.__status else not self.__real_true) time.sleep(0.05)
Example #30
Source File: __init__.py From phat-beat with MIT License | 5 votes |
def _do_handle_button(pin): if _handle_hold(pin): return if pin in _button_handlers.keys() and callable(_button_handlers[pin]): _button_handlers[pin](pin) if not _button_repeat[pin]: return delay = 0.25 ramp_rate = 0.90 t_delay = 0.5 t_end = time.time() + t_delay while time.time() < t_end: if GPIO.input(pin): return time.sleep(0.001) while not GPIO.input(pin): _button_handlers[pin](pin) time.sleep(delay) delay *= ramp_rate delay = max(0.01, delay)