当前位置: 首页>>代码示例>>Python>>正文


Python gpiozero.Button方法代码示例

本文整理汇总了Python中gpiozero.Button方法的典型用法代码示例。如果您正苦于以下问题:Python gpiozero.Button方法的具体用法?Python gpiozero.Button怎么用?Python gpiozero.Button使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gpiozero的用法示例。


在下文中一共展示了gpiozero.Button方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def __init__(self):
        self.led_queue = mp.Queue()
        self.demo_mode = mp.Lock()

        self.led_process = mp.Process(target=led_control, args=(self.led_queue, self.demo_mode,))

        self.shutting_down = False
        self.last_button_release = 0
        self.show_end_of_lines = False

        # The button has multiple functions:
        # Turn the device on when off, single press to show the end of long lines on the display,
        # double press to start demo mode, single press to stay at one animation in demo mode,
        # long press to shut down
        self.button = Button(3, hold_time=2, bounce_time=0.05)
        self.button.when_held = self.shutdown
        self.button.when_released = self.button_pressed

        self.tft = SattrackerTFT()

        self.tle_updated_time = None

        self.tracker = None  # load in start because it takes quite a long time

        self.led_array = led_array_from_constants() 
开发者ID:PaulKlinger,项目名称:satellite_tracker,代码行数:27,代码来源:main.py

示例2: ReadProperty

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def ReadProperty(self, obj, arrayIndex=None):
        if _debug:
            BIPresentValue._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex)

        # access an array
        if arrayIndex is not None:
            raise ExecutionError(
                errorClass="property", errorCode="propertyIsNotAnArray"
            )
        

        ###TODO: obj._button is the Button object
        
        if _debug:
            BIPresentValue._debug("    - read button: %r", obj._button)

        if obj._button.is_pressed:
            return "active"
        
        else:
            return "inactive" 
开发者ID:JoelBender,项目名称:bacpypes,代码行数:23,代码来源:binaryio.py

示例3: index

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def index(led_number="n"):
    if led_number != "n":
        leds[int(led_number)].toggle()
    response = "<script>"
    response += "function changed(led)"
    response += "{"
    response += "  window.location.href='/' + led"
    response += "}"
    response += "</script>"
    
    response += '<h1>GPIO Control</h1>'
    response += '<h2>Button=' + switch_status() + '</h2>'
    response += '<h2>LEDs</h2>'
    response += html_for_led(0) 
    response += html_for_led(1) 
    response += html_for_led(2) 
    return response 
开发者ID:simonmonk,项目名称:raspberrypi_cookbook_ed3,代码行数:19,代码来源:ch_16_web_control.py

示例4: listen

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def listen(gpio_num, log_path, *args):
    button = Button(gpio_num)

    def pressed():
         #print( " Button Pressed " )
         listen.press_start = time.time()

    def released():
        #print( " Button released " )
        listen.press_end = time.time()

    button.wait_for_press()
    pressed()
    button.wait_for_release()
    released()
    duration = listen.press_end - listen.press_start
    print(duration)
    log_button_presss(log_path, duration) 
开发者ID:Pragmatismo,项目名称:Pigrow,代码行数:20,代码来源:watcher_button.py

示例5: pressed

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def pressed(button):
    button_name = button_map[button.pin.number]
    print(f"Button {button_name} pressed!") 
开发者ID:pimoroni,项目名称:scroll-phat-hd,代码行数:5,代码来源:buttons.py

示例6: pressed

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def pressed(button):
    global splash_origin, splash_time
    button_name, x, y = button_map[button.pin.number]
    splash_origin = (x, y)
    splash_time = time.time()
    print(f"Button {button_name} pressed!") 
开发者ID:pimoroni,项目名称:scroll-phat-hd,代码行数:8,代码来源:button-splash.py

示例7: __init__

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def __init__(self, button_id, **kwargs):
        if _debug:
            RPiBinaryInput._debug("__init__ %r %r", button_id, kwargs)
        BinaryInputObject.__init__(self, **kwargs)

        # create a button object
        self._button = Button(button_id)


#
#   BOPresentValue
# 
开发者ID:JoelBender,项目名称:bacpypes,代码行数:14,代码来源:binaryio.py

示例8: WriteProperty

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False):
        if _debug:
            BOPresentValue._debug(
                "WriteProperty %r %r arrayIndex=%r priority=%r direct=%r",
                obj,
                value,
                arrayIndex,
                priority,
                direct,
            )

        # access an array
        if arrayIndex is not None:
            raise ExecutionError(
                errorClass="property", errorCode="propertyIsNotAnArray"
            )

        ###TODO: obj._button is the Button object
        if _debug:
            BOPresentValue._debug("    - write led: %r", obj._led)

        #raise ExecutionError(errorClass="property", errorCode="writeAccessDenied")

        if value == "active":
            obj._led.on()
        elif value == "inactive":
            obj._led.off()
        else:
            ### TODO: insert correct value error. Below is a placeholder.
            print("invalid value for led. Use 'active' to turn on or 'inactive' to turn off.")


#
#   RPiBinaryOutput
# 
开发者ID:JoelBender,项目名称:bacpypes,代码行数:37,代码来源:binaryio.py

示例9: __init__

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def __init__(self):

        super().__init__()

        import gpiozero
        self.LED = gpiozero.LED
        self.RGBLED = gpiozero.RGBLED
        self.Button = gpiozero.Button
        self.GPIOPinInUse = gpiozero.GPIOPinInUse

        self._buttons = []
        self._lamps = []
        self._rgb = [] 
开发者ID:reuterbal,项目名称:photobooth,代码行数:15,代码来源:__init__.py

示例10: setButton

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def setButton(self, bcm_pin, handler):

        try:
            self._buttons.append(self.Button(bcm_pin))
            self._buttons[-1].when_pressed = handler
        except self.GPIOPinInUse:
            logging.error('Pin {} already in use!'.format(bcm_pin)) 
开发者ID:reuterbal,项目名称:photobooth,代码行数:9,代码来源:__init__.py

示例11: do_stuff

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def do_stuff():
    print("Button Pressed") 
开发者ID:simonmonk,项目名称:raspberrypi_cookbook_ed3,代码行数:4,代码来源:ch_12_switch_2.py

示例12: accept_button_callback

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def accept_button_callback():
	global button_input_received

	accept_button_callback_logger = logging.getLogger('button_utils.accept_button_callback')

	accept_button_callback_logger.info("$$$$$$$$$$$$$$ Accept Button was pushed! $$$$$$$$$$$$$$")
	button_input_received = config.__ACCEPT_INPUT__
	accept_button_callback_logger.info("All done with the button callback!")

	return 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:12,代码来源:button_utils.py

示例13: choice_button_callback

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def choice_button_callback():
	global button_input_received

	choice_button_callback_logger = logging.getLogger('button_utils.choice_button_callback')

	choice_button_callback_logger.info("############### Choice Button was pushed! #################")
	button_input_received = config.__CHOOSE_AGAIN__

	choice_button_callback_logger.info("All done with the button callback!")

	return 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:13,代码来源:button_utils.py

示例14: main

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def main():
    # parse the command line arguments
    args = ConfigArgumentParser(description=__doc__).parse_args()

    if _debug:
        _log.debug("initialization")
    if _debug:
        _log.debug("    - args: %r", args)

    # make a device object
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=("device", int(args.ini.objectidentifier)),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # make the buttons
    for button_id, bio_id in button_list:
        bio = RPiBinaryInput(
            button_id,
            objectIdentifier=("binaryInput", bio_id),
            objectName="Button-%d" % (button_id,),
        )
        _log.debug("    - bio: %r", bio)
        this_application.add_object(bio)

    # make the LEDs
    for led_id, boo_id in led_list:
        boo = RPiBinaryOutput(
            led_id,
            objectIdentifier=("binaryOutput", boo_id),
            objectName="LED-%d" % (led_id,),
        )
        _log.debug("    - boo: %r", boo)
        this_application.add_object(boo)

    _log.debug("running")

    run()

    _log.debug("fini") 
开发者ID:JoelBender,项目名称:bacpypes,代码行数:48,代码来源:binaryio.py

示例15: startgreen

# 需要导入模块: import gpiozero [as 别名]
# 或者: from gpiozero import Button [as 别名]
def startgreen():
    # Remember all code in the function is indented

# Turn the green off and the amber on for 3 seconds
# ('Pedestrian' red LED stays lit)
def steadyamber():
    # Remember all code in the function is indented

# Turn the amber off, and then the red on for 1 second
def steadyred():
    # Remember all code in the function is indented

# Sound the buzzer for 4 seconds
# (If you have the 'pedestrian' LEDs, turn the red off and green on)
def startwalking():
    # Make the buzzer buzz on and off, half a second of
    # sound followed by half a second of silence

# Turn the buzzer off and wait for 2 seconds
# (If you have a second green 'pedestrian' LED, make it flash on and
# off for the two seconds)
def dontwalk():
    # Remember all code in the function is indented

# Flash the amber on and off for 6 seconds
# (And the green 'pedestrian' LED too)
def flashingambergreen():
    # Remember all code in the function is indented

# Flash the amber for one more second
# (Turn the green 'pedestrian' LED off and the red on)
def flashingamber():
    # Remember all code in the function is indented

# Go through the traffic light sequence by calling each function
# one after the other.
def trafficlightqequence():
    # Remember all code in the function is indented

os.system('clear')  # Clears the terminal
print("Traffic Lights")
# Initialise the traffic lights
startgreen()

# Here is the loop that waits at lease 20 seconds before
# stopping the cars if the button has been pressed
while True:  # Loop around forever
    buttonnotpressed = True  # Button has not been pressed
    start = time.time()  # Records the current time
    while buttonnotpressed:  # While the button has not been pressed
        time.sleep(0.1)  # Wait for 0.1s
        if button.ispressed:  # If the button is pressed
            now = time.time()
            buttonnotpressed = False  # Button has been pressed
            if (now - start) <= 20:  # If under 20 seconds
                time.sleep(20 - (now - start))  # Wait until 20s is up
                trafficlightqequence()  # Run the traffic light sequence 
开发者ID:CamJam-EduKit,项目名称:EduKit1,代码行数:59,代码来源:7-TrafficLights.py


注:本文中的gpiozero.Button方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。