def moveStop(self,channel): GPIO.remove_event_detect(channel) #PWM.start(self.pwmPIN, 0, self.freq, 0) GPIO.output(self.upDIR, GPIO.LOW) GPIO.output(self.downDIR, GPIO.LOW) print "Motor STOP...!!" return time.time()
def cleanup(self): '''cleanup single GPIO pin: remove event detect and set to GPIO.IN with GPIO.PUD_OFF''' logger.debug('cleanup ' + self.__class__.__name__ + ': cleanup single GPIO pin ' + self.gpio_pin) GPIO.remove_event_detect(self.gpio_pin) GPIO.setup(self.gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
def moveStop(self, channel): GPIO.remove_event_detect(channel) #PWM.start(self.pwmPIN, 0, self.freq, 0) GPIO.output(self.upDIR, GPIO.LOW) GPIO.output(self.downDIR, GPIO.LOW) print "Motor STOP...!!" return time.time()
def cleanup(self): '''cleanup individual GPIO pins: remove event detect and set to GPIO.IN with GPIO.PUD_OFF''' for gpio_pin in [self.gpio_pin_green, self.gpio_pin_red]: self.logger.debug('cleanup ' + self.__class__.__name__ + ': cleanup single GPIO pin ' + gpio_pin) GPIO.remove_event_detect(gpio_pin) GPIO.setup(gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
def hw_exit(self): '''exit/de-initialize gpio port.''' self.logger.info('exitting {} on gpio pin {:s}.'.format(self.config_name, str(self.gpio_pin))) # remove event detect if any.. GPIO.remove_event_detect(self.gpio_pin) # reset state by setting to GPIO.IN and GPIO.LOW GPIO.setup(self.gpio_pin, GPIO.IN, initial=GPIO.LOW)
def __init__(self, port, callback): self.port = port self.callback = callback GPIO.setup(self.port, GPIO.IN) print "DETECT EVENTS:", self.port # GPIO.RISING, GPIO.FALLING, GPIO.BOTH GPIO.remove_event_detect(self.port) GPIO.add_event_detect(self.port, GPIO.RISING, callback=self.check_rising, bouncetime=300)
def __init__(self, port, callback): self.port = port self.callback = callback GPIO.setup(self.port, GPIO.IN) print "DETECT EVENTS:", self.port # GPIO.RISING, GPIO.FALLING, GPIO.BOTH GPIO.remove_event_detect(self.port) GPIO.add_event_detect(self.port, GPIO.RISING, callback=self.check_rising, bouncetime=300)
def handleClose(self): self.do_beep(0.25) for PIN in self.PROXIMITY_GPIO: GPIO.remove_event_detect(PIN) GPIO.remove_event_detect(self.STOP_BUTTON) GPIO.remove_event_detect(self.ECHO_RETURN) self.SCAN = False sleep(1) PWM.stop(self.SERVO_PWM) PWM.stop(self.SPEAKER_PWM) self.saber.stop() print self.address, 'closed'
def handleClose(self): self.do_beep(0.25) for PIN in self.PROXIMITY_GPIO: GPIO.remove_event_detect(PIN) GPIO.remove_event_detect(self.STOP_BUTTON) GPIO.remove_event_detect(self.ECHO_RETURN) self.SCAN = False sleep(1) PWM.stop(self.SERVO_PWM) PWM.stop(self.SPEAKER_PWM) self.saber.stop() print self.address, 'closed'
def setMode(self, mode): """Set device mode.""" if (mode in self._settings['modes']): self._mode = mode if mode == 'State': GPIO.remove_event_detect(self._pin) # Remove event detection elif mode == 'Rising Edge': GPIO.remove_event_detect(self._pin) # Remove event detection GPIO.add_event_detect(self._pin, GPIO.RISING) # Set rising edge detection elif mode == 'Falling Edge': GPIO.remove_event_detect(self._pin) # Remove event detection GPIO.add_event_detect( self._pin, GPIO.FALLING) # Set falling edge detection else: raise ValueError('mode {} is not allowed'.format(mode))
def handleClose(self): for PIN in self.PROXIMITY_GPIO: GPIO.remove_event_detect(PIN) self.saber.stop() print self.address, 'closed'
def echoStart(self, pin): self.t1 = time.time() GPIO.remove_event_detect("P9_27") GPIO.add_event_detect("P9_27", GPIO.FALLING, self.echoEnd)
def _shutdownInterrupt(self): GPIO.remove_event_detect(self.pin)
def setup_digital_pin(self): """ This method processes the Scratch "Digital Pin" Block that establishes the mode for the pin :return: None """ # clear out any residual problem strings # self.report_problem('1-0\n') self.last_problem = '1-0\n' # retrieve mode from command mode = self.payload['mode'] # Is the user enabling or disabling the pin? Get the 'raw' value and translate it. enable = self.payload['enable'] if mode == 'SONAR': self.last_problem = '7-0\n' pin = self.validate_pin(self.analog_pins) if pin == 99: self.last_problem = '7-1\n' return index = self.analog_pins.index(pin) pin_entry = self.analog_pin_states[index] if self.payload['enable'] == 'Enable': pin_entry['enabled'] = True pin_entry['mode'] = 'sonar' self.analog_pin_states[index] = pin_entry else: pin_entry['enabled'] = False self.analog_pin_states[index] = pin_entry if not self.analog_reader: self.analog_reader = AnalogReader(self.board_num, self.analog_pin_states) ADC.setup() self.analog_reader.start() elif mode == 'PWM' or mode == 'Servo' or mode == 'Tone': pin = self.validate_pin(self.pwm_pins) if pin == 99: self.last_problem = '1-2\n' return index = self.pwm_pins.index(pin) pin_entry = self.pwm_pin_states[index] if self.payload['enable'] == 'Enable': pin_entry['enabled'] = True self.pwm_pin_states[index] = pin_entry if mode == 'PWM' or mode == 'Tone': PWM.start(pin, 0.0) else: PWM.start(pin, 3, 60.0, self.servo_polarity) else: pin_entry['enabled'] = False self.pwm_pin_states[index] = pin_entry else: pin = self.validate_pin(self.black_gpio_pins) if pin == 99: self.last_problem = '1-1\n' return # retrieve mode from command mode = self.payload['mode'] # if enable == 'Enable': # validate the mode for this pin if mode == 'Input': index = self.black_gpio_pins.index(pin) pin_entry = self.gpio_pin_states[index] pin_entry['mode'] = GPIO.IN pin_entry['enabled'] = True self.gpio_pin_states[index] = pin_entry GPIO.setup(pin, GPIO.IN) GPIO.add_event_detect(pin, GPIO.BOTH, callback=self.digital_input_callback) elif mode == 'Output': index = self.black_gpio_pins.index(pin) pin_entry = self.gpio_pin_states[index] # update the pin table # pin_entry = {'pin': pin, 'mode': GPIO.OUT, 'enabled': True} pin_entry['mode'] = GPIO.OUT pin_entry['enabled'] = True self.gpio_pin_states[index] = pin_entry GPIO.setup(pin, GPIO.OUT) # must be disable else: if mode == 'Output': index = self.black_gpio_pins.index(pin) pin_entry = self.gpio_pin_states[index] pin_entry['enabled'] = False self.gpio_pin_states[index] = pin_entry elif mode == 'Input': index = self.black_gpio_pins.index(pin) pin_entry = self.gpio_pin_states[index] pin_entry['enabled'] = False self.gpio_pin_states[index] = pin_entry GPIO.remove_event_detect(pin)
def remove_event(self): # function: remove event detection GPIO.remove_event_detect(self.sig)
def cleanup(self): # function: clean up pin GPIO.remove_event_detect(self.sig) GPIO.cleanup()
stop = time.time() if count_l > count_max_l and not l_stop: GPIO.output(LEFT_DIR, GPIO.LOW) PWM.set_duty_cycle(LEFT_PWM,0) l_stop = 1 if count_r > count_max_r and not r_stop: GPIO.output(RIGHT_DIR, GPIO.LOW) PWM.set_duty_cycle(RIGHT_PWM,0) r_stop = 1 GPIO.output(LEFT_DIR, GPIO.LOW) GPIO.output(RIGHT_DIR, GPIO.LOW) PWM.start(LEFT_PWM, 0) PWM.start(RIGHT_PWM, 0) GPIO.remove_event_detect(L_ENC) GPIO.remove_event_detect(R_ENC) #################################################################### def main(): global run_flag #setup pins GPIO.setup(LEFT_DIR, GPIO.OUT) GPIO.setup(RIGHT_DIR, GPIO.OUT) GPIO.setup(pin1trigger, GPIO.OUT) GPIO.setup(pin2trigger, GPIO.OUT) GPIO.setup(pin3trigger, GPIO.OUT) GPIO.setup(pin4trigger, GPIO.OUT)
def trigEN(self): GPIO.remove_event_detect("P9_27") GPIO.add_event_detect("P9_27", GPIO.RISING, self.echoStart) self.trigRD = 1
# The wait_for_edge method is blocking, and will wait until something happens: GPIO.wait_for_edge("P8_14", GPIO.RISING) # Another option, that is non-blocking is to add an event to detect. # First, you setup your event to watch for, then you can do whatever else your # program will do, and later on, you can check if that event was detected. # A simple example of this is as follows: GPIO.add_event_detect("P8_14", GPIO.FALLING) #your amazing code here #detect wherever: time.sleep(5) if GPIO.event_detected("P8_14"): print("event detected!") # Or if you want you can define a callback function. def my_callback(channel): print('Edge detected on channel %s' % channel) # Then have it called when the event occurs GPIO.remove_event_detect("P8_14") GPIO.add_event_detect("P8_14", GPIO.BOTH, callback=my_callback) while True: # Do something while waiting for event time.sleep(100) GPIO.cleanup()