Python RPi.GPIO.wait_for_edge() Examples
The following are 6
code examples of RPi.GPIO.wait_for_edge().
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: 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 #2
Source File: main.py From AlexaPi with MIT License | 6 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: GPIOSR04.py From calvin-base with Apache License 2.0 | 6 votes |
def _trigger(self): try : self._detection = True self._t0 = time.time() gpio.output(self._trigger_pin, gpio.HIGH) time.sleep(0.00005) gpio.output(self._trigger_pin, gpio.LOW) pin = gpio.wait_for_edge(self._echo_pin, gpio.FALLING, timeout=1000) self._elapsed = time.time() - self._t0 if pin is None: _log.debug("echo timeout exceeded") # self._detection = None async.call_from_thread(self.scheduler_wakeup) except Exception as e: _log.warning("Failed sonar triggering: {}".format(e))
Example #4
Source File: coinacceptor.py From LightningATM with MIT License | 5 votes |
def firstFunction(): global counter global ts global counting count = 1 counter = 0 ts = time.time() while True: if count == 1: GPIO.wait_for_edge(6, GPIO.FALLING) counting = 1 counter += 1 print(f"Pulse comming ! {counter}") ts = time.time()
Example #5
Source File: main.py From GassistPi with GNU General Public License v3.0 | 5 votes |
def ircommands(self): if irreceiver!=None: try: print("IR Sensor Started") while True: time.sleep(.1) #print("Listening for IR Signal on GPIO "+irreceiver) GPIO.wait_for_edge(irreceiver, GPIO.FALLING) code = on_ir_receive(irreceiver) if code: if self.can_start_conversation == True: for codenum, usercode in enumerate(configuration['IR']['Codes']): if usercode==code: if 'custom' in (configuration['IR']['Commands'][codenum]).lower(): self.custom_command((configuration['IR']['Commands'][codenum]).lower()) elif 'start conversation' in (configuration['IR']['Commands'][codenum]).lower(): self.assistant.start_conversation() elif 'mute' in (configuration['IR']['Commands'][codenum]).lower(): self.buttonsinglepress() else: self.assistant.send_text_query(configuration['IR']['Commands'][codenum]) break except KeyboardInterrupt: pass except RuntimeError: pass print("Stopping IR Sensor")
Example #6
Source File: radiohackbox.py From radio-hackbox with GNU General Public License v3.0 | 4 votes |
def buttonCallback(self, channel): """Callback function for user input (pressed buttons)""" # record button state transitions if channel == RECORD_BUTTON: # if the current state is IDLE change it to RECORD if self.state == IDLE: # set RECORD state self.setState(RECORD) # empty payloads list self.payloads = [] # if the current state is RECORD change it to IDLE elif self.state == RECORD: # set IDLE state self.setState(IDLE) # play button state transitions elif channel == REPLAY_BUTTON: # if the current state is IDLE change it to REPLAY if self.state == IDLE: # set REPLAY state self.setState(REPLAY) # scan button state transitions elif channel == SCAN_BUTTON: # wait a short a time to see whether the record button is also # press in order to perform a graceful shutdown # remove event detection for record button GPIO.remove_event_detect(RECORD_BUTTON) chan = GPIO.wait_for_edge(RECORD_BUTTON, GPIO.RISING, timeout=1000) if chan != None: # set SHUTDOWN state self.setState(SHUTDOWN) # set callback function for record button GPIO.remove_event_detect(RECORD_BUTTON) GPIO.add_event_detect(RECORD_BUTTON, GPIO.RISING, callback = self.buttonCallback, bouncetime = 250) # if the current state is IDLE change it to SCAN if self.state == IDLE: # set SCAN state self.setState(SCAN) # attack button state transitions elif channel == ATTACK_BUTTON: # if the current state is IDLE change it to ATTACK if self.state == IDLE: # set ATTACK state self.setState(ATTACK) # debug output debug("State: {0}".format(self.state))