python类add_event_detect()的实例源码

gpio.py 文件源码 项目:aiyprojects-raspbian 作者: google 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def start(self):
        if not self.event_detect_added:
            GPIO.add_event_detect(self.channel, self.polarity, callback=self.debounce)
            self.event_detect_added = True
_button.py 文件源码 项目:aiyprojects-raspbian 作者: google 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def wait_for_press(self):
        """Waits for the button to be pressed.

        This method blocks until the button is pressed.
        """
        GPIO.add_event_detect(self.channel, self.polarity)
        while True:
            if GPIO.event_detected(self.channel) and self._debounce():
                GPIO.remove_event_detect(self.channel)
                return
            time.sleep(0.02)
NewEmailIndicator.py 文件源码 项目:52-Weeks-of-Pi 作者: grantwinney 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def initialize_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(Gmail.PIN, GPIO.OUT)
    GPIO.setup(CHECK_NOW_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.add_event_detect(CHECK_NOW_PIN, GPIO.RISING, callback=check_mail_now, bouncetime=1000)
Transmitter.py 文件源码 项目:52-Weeks-of-Pi 作者: grantwinney 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def initialize_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup([11, 32, 36], GPIO.OUT)  # LEDs: Blue (metronome), Green (ok), Red (error)
    GPIO.setup(31, GPIO.IN)
    GPIO.output([32, 36], GPIO.LOW)
    GPIO.add_event_detect(31, GPIO.BOTH, callback=intercept_morse_code)


# Blink a blue LED on/off (one full cycle per BASE_TIME_SECONDS)
CandleSimulation.py 文件源码 项目:52-Weeks-of-Pi 作者: grantwinney 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def initialize_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup([R,G], GPIO.OUT, initial=GPIO.LOW)
    GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.add_event_detect(BUTTON, GPIO.FALLING, fan_the_flame, 250)
Simon.py 文件源码 项目:52-Weeks-of-Pi 作者: grantwinney 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def initialize_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(LIGHTS, GPIO.OUT, initial=GPIO.LOW)
    GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    for i in range(4):
        GPIO.add_event_detect(BUTTONS[i], GPIO.FALLING, verify_player_selection, 400 if use_sounds else 250)
encoder.py 文件源码 项目:donkey 作者: wroscoe 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def __init__(self, mm_per_tick=0.306096, pin=27, poll_delay=0.0166, debug=False):
        import RPi.GPIO as GPIO
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(pin, GPIO.IN)
        GPIO.add_event_detect(pin, GPIO.RISING, callback=self.isr)

        # initialize the odometer values
        self.m_per_tick = mm_per_tick / 1000.0
        self.poll_delay = poll_delay
        self.meters = 0
        self.last_time = time.time()
        self.meters_per_second = 0
        self.counter = 0
        self.on = True
        self.debug = debug
butler.py 文件源码 项目:garage-butler 作者: gurumitts 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self):
        logging.getLogger('garage').info('Butler is starting...')
        logging.getLogger('garage').info('AWS: region=%s, topic=%s' % (REGION, TOPIC))
        self.camera = Camera()
        self.notify = Notify(self)
        GPIO.add_event_detect(button_pin, GPIO.FALLING, callback=self.door_check, bouncetime=1000)
        scheduler.start()
        scheduler.add_job(self.status_check, 'interval', minutes=1)
        self.last_notification = datetime.datetime.strptime('Jun 1 2005  1:00PM', '%b %d %Y %I:%M%p')
        self.last_status = GPIO.input(button_pin)
controller_rpi.py 文件源码 项目:SX127x_driver_for_MicroPython_on_ESP8266 作者: Wei1234c 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def prepare_irq_pin(self, pin_id): 
        pin = self.prepare_pin(pin_id, GPIO.IN) 
        if pin:       
            pin.set_handler_for_irq_on_rising_edge = \
                lambda handler: GPIO.add_event_detect(pin.pin_id,
                                                      GPIO.RISING,
                                                      callback = handler)  
            pin.detach_irq = lambda : GPIO.remove_event_detect(pin.pin_id) 
            return pin
controller_rpi.py 文件源码 项目:SX127x_driver_for_MicroPython_on_ESP8266 作者: Wei1234c 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def prepare_irq_pin(self, pin_id): 
        pin = self.prepare_pin(pin_id, GPIO.IN) 
        if pin:       
            pin.set_handler_for_irq_on_rising_edge = \
                lambda handler: GPIO.add_event_detect(pin.pin_id,
                                                      GPIO.RISING,
                                                      callback = handler)  
            pin.detach_irq = lambda : GPIO.remove_event_detect(pin.pin_id) 
            return pin
deskcycle_btkclient.py 文件源码 项目:BlogCode 作者: yaptb 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def event_loop(self):


            self.keyDown=False
        self.hitCount=0 


            keys_per_rev=5
            key_press_delay=0.2
            inter_key_delay=0.001

            self.last_hit_time=0
            self.current_hit_time=0
            self.rev_time=0.5

            GPIO.add_event_detect(DeskCycle.PIN, GPIO.FALLING, callback=self.pin_event,bouncetime=250) 


            while True:


                if(self.hitCount >0):

                        if(not self.keyDown):
                            print "On"    
                            self.state[4]=DeskCycle.KEYCODE
                            self.send_key_state()
                            self.keyDown=True

                        self.hitCount=0

                else:
                        if(self.keyDown):

                                if(time.time()-self.last_hit_time > 1):
                                        print "Off"    
                                        self.state[4]=0
                                        self.send_key_state()
                                        self.keyDown=False

                time.sleep(0.001)
deskcycle_test.py 文件源码 项目:BlogCode 作者: yaptb 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self):


            print "setting up GPIO"

            GPIO.setmode(GPIO.BOARD)
            GPIO.setup(DeskCycle.PIN,GPIO.IN,pull_up_down=GPIO.PUD_UP)

            self.hitCount=0

            pin2=38
            GPIO.setup(pin2,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
            GPIO.add_event_detect(pin2, GPIO.FALLING, callback=self.pin_2_event,bouncetime=100)
AIWIBoardContext.py 文件源码 项目:RPiNWR 作者: ke4roh 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def reset_radio(self):
        """
        Reset the Si4707 chip
        """
        # Ref https://github.com/AIWIndustries/Pi_4707/blob/master/firmware/NWRSAME_v2.py
        if self.gpio_started:
            gpio.cleanup()
        self.gpio_started = True
        gpio.setmode(gpio.BCM)  # Use board pin numbering

        gpio.setup(17, gpio.OUT)  # Setup the reset pin
        gpio.output(17, gpio.LOW)  # Reset the Si4707.
        sleep(0.4)
        gpio.output(17, gpio.HIGH)

        gpio.setup(23, gpio.IN, pull_up_down=gpio.PUD_UP)
        gpio.add_event_detect(23, gpio.FALLING)

        # Initialize the onboard relays
        for pin in self.relay_gpio_pins:
            gpio.setup(pin, gpio.OUT)  # setup gpio pin for relay
            gpio.output(pin, gpio.LOW)  # boot to disabled state

        # set up the LED
        # https://www.reddit.com/r/raspberry_pi/comments/3641ug/blinking_an_onboard_led_on_the_pi_2_model_b/
        # http://raspberrypi.stackexchange.com/questions/697/how-do-i-control-the-system-leds-using-my-
        # sudo echo none >/sys/class/leds/led0/trigger
        # GPIO 16 LOW is on, HIGH is off
        gpio.setup(16, gpio.OUT)
        gpio.output(16, gpio.HIGH)

        sleep(1.5)
test.py 文件源码 项目:Pacbot 作者: HarvardURC 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self):

        GPIO.setmode(GPIO.BCM)
        #Setup each hall effect pin for interrupts
        GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        print ("Encoders Ready")

        GPIO.add_event_detect(18, GPIO.FALLING, callback=self.add_right_pulse)
        GPIO.add_event_detect(24, GPIO.FALLING, callback=self.add_left_pulse)

        while 1:
            pass

    # Callback function for Hall Sensor interrupts
pirs.py 文件源码 项目:home-alarm 作者: rdubigny 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self):
        io.setmode(io.BCM)
        self.pir_pin = 4
        io.setup(self.pir_pin, io.IN)
        self.pirStream = Subject()
        io.add_event_detect(self.pir_pin, io.RISING, callback=self.hit_callback)
rf95.py 文件源码 项目:pyRF95 作者: ladecadence 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def init(self):
        # open SPI and initialize RF95
        self.spi.open(0,self.cs)
        self.spi.max_speed_hz = 488000
        self.spi.close()

        # set interrupt pin
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.int_pin, GPIO.IN)
        GPIO.add_event_detect(self.int_pin, GPIO.RISING, callback=self.handle_interrupt)

        # set reset pin
        if self.reset_pin != None:
            GPIO.setup(self.reset_pin, GPIO.OUT)
            GPIO.output(self.reset_pin, GPIO.HIGH)
        # wait for reset
        time.sleep(0.05)

        # set sleep mode and LoRa mode
        self.spi_write(REG_01_OP_MODE, MODE_SLEEP | LONG_RANGE_MODE)

        time.sleep(0.01)        
        # check if we are set
        if self.spi_read(REG_01_OP_MODE) != (MODE_SLEEP | LONG_RANGE_MODE):
            return False

        # set up FIFO
        self.spi_write(REG_0E_FIFO_TX_BASE_ADDR, 0)
        self.spi_write(REG_0F_FIFO_RX_BASE_ADDR, 0)

        # default mode
        self.set_mode_idle()

        self.set_modem_config(Bw125Cr45Sf128)
        self.set_preamble_length(8)

        return True
GPIOInteraction.py 文件源码 项目:auxilia 作者: GHP2017 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
        self.button_callback = None
        self.button_held_callback = None
        self.reset_callback = None
        self.pressed_at = None
        self.time_to_hold = 1
        self.time_to_reset = 5

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.add_event_detect(18, GPIO.BOTH, callback=self.button_state_changed,bouncetime=200)
ButtonEncoder.py 文件源码 项目:RaspberryPi-MPD-CharDisplay 作者: bill6300gp 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def eventBegin(self, callback, object=0, edge='BOTH'):
    # eventBegin(callback)
    # eventBegin(callback, object, edge)
    # ** callback: call function when Interrupt
    # ** object: set Interrupt pin: 1=Button, 2=Encoder  >> default: 0(all)
    # ** edge: set edge detection: RISING, FALLING, BOTH >> default: BOTH
    self.Callback=callback

    if object==0 and ((self.__SWtype==1 and self.__eventStatus&0x03!=0x00) or (self.__SWtype==2 and self.__eventStatus&0x0F!=0x00)):
      self.eventEnd(0)
    elif object==1 and self.__eventStatus&0x03!=0x00:
      self.eventEnd(1)
    elif object==2 and (self.__SWtype==2 and self.__eventStatus&0x0C!=0x00):
      self.eventEnd(2)

    if object==0 or object==1:
      if edge.upper().find('RISING')>=0:
        GPIO.add_event_detect(self.__PinSW, GPIO.RISING, callback=self.eventButton, bouncetime=40)
        self.__eventStatus|=0x01
      elif edge.upper().find('FALLING')>=0:
        GPIO.add_event_detect(self.__PinSW, GPIO.FALLING, callback=self.eventButton, bouncetime=40)
        self.__eventStatus|=0x02
      elif edge.upper().find('BOTH')>=0:
        GPIO.add_event_detect(self.__PinSW, GPIO.BOTH, callback=self.eventButton, bouncetime=40)
        self.__eventStatus|=0x03
    if (object==0 or object==2) and self.__SWtype==2:
      if edge.upper().find('RISING')>=0:
        GPIO.add_event_detect(self.__PinA , GPIO.RISING, callback=self.eventEncoder, bouncetime=20)
        self.__eventStatus|=0x04
      elif edge.upper().find('FALLING')>=0:
        GPIO.add_event_detect(self.__PinA , GPIO.FALLING, callback=self.eventEncoder, bouncetime=20)
        self.__eventStatus|=0x08
      elif edge.upper().find('BOTH')>=0:
        GPIO.add_event_detect(self.__PinA , GPIO.BOTH, callback=self.eventEncoder, bouncetime=20)
        self.__eventStatus|=0x0C
jb-rotary.py 文件源码 项目:JustBoom 作者: PiSupply 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def start(self):
        GPIO.add_event_detect(self.clockPin,
                              GPIO.FALLING,
                              callback=self._clockCallback,
                              bouncetime=50)
        GPIO.add_event_detect(self.buttonPin,
                              GPIO.FALLING,
                              callback=self._switchCallback,
                              bouncetime=300)
touch.py 文件源码 项目:rainbow-hat 作者: pimoroni 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, index, gpio_pin):
        self.pressed = False
        self._on_press_handler = None
        self._on_release_handler = None
        self._gpio_pin = gpio_pin
        self._index = index
        GPIO.setup(self._gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.add_event_detect(self._gpio_pin, GPIO.BOTH, bouncetime=1, callback=self._handle_button)


问题


面经


文章

微信
公众号

扫码关注公众号