本文整理汇总了Python中gpiozero.Button.when_released方法的典型用法代码示例。如果您正苦于以下问题:Python Button.when_released方法的具体用法?Python Button.when_released怎么用?Python Button.when_released使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gpiozero.Button
的用法示例。
在下文中一共展示了Button.when_released方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LED
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
from gpiozero import Button, LED
from time import sleep
led = LED(17)
button = Button(3)
delay = 1.0
def blink_fast():
global delay
delay = 0.1
def blink_slow():
global delay
delay = 1.0
button.when_pressed = blink_fast
button.when_released = blink_slow
while True:
sleep(delay)
led.on()
sleep(delay)
led.off()
示例2: Button
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
from gpiozero import Button
from signal import pause
from time import sleep
btn = Button(21)
btn.when_pressed = lambda: print("aaa")
btn.when_released = lambda: print("bbbb")
pause()
示例3: water_high
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
from gpiozero import Button
from signal import pause
import arrow
def water_high():
print("Water High!")
utc = arrow.utcnow()
utc_local = utc.to('local')
print("UTC time - Water lever changed HIGH - at: {}".format(utc))
print("Local time - Water level changed HIGH - at: {}".format(utc_local))
def water_low():
print("Water Low!")
utc = arrow.utcnow()
utc_local = utc.to('local')
print("UTC time - Water lever changed LOW - at: {}".format(utc))
print("Local time - Water level changed LOW - at: {}".format(utc_local))
button = Button(2)
button.when_pressed = water_high
button.when_released = water_low
print('*** Water Level Sensor Started ***')
pause()
print('..Running..')
示例4: set_note_additor
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
set_note_additor()
# Play a tone so we know that we've started
startup()
# Set-up main loop watchers
main_loop_stopped = 0
stop_main_loop = 0
print("Initialising rear buttons")
button_reset.when_pressed = reset
button_shutdown.when_pressed = shutdown
# Assign actions to when_pressed for each button
thumb_bottom.when_pressed = thumb_bottom_start
thumb_bottom.when_released = thumb_bottom_stop
thumb_right.when_pressed = thumb_right_start
thumb_right.when_released = thumb_right_stop
thumb_top.when_pressed = thumb_top_start
thumb_top.when_released = thumb_top_stop
index_finger.when_pressed = index_finger_start
index_finger.when_released = index_finger_stop
middle_finger.when_pressed = middle_finger_start
middle_finger.when_released = middle_finger_stop
ring_finger.when_pressed = ring_finger_start
ring_finger.when_released = ring_finger_stop
pinky_finger.when_pressed = pinky_finger_start
pinky_finger.when_released = pinky_finger_stop
print("Starting main loop")
示例5: Button
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
from gpiozero import Button
from picamera import PiCamera
from datetime import datetime
from signal import pause
left_button = Button(2)
right_button = Button(3)
camera = PiCamera()
def capture():
datetime = datetime.now().isoformat()
camera.capture('/home/pi/%s.jpg' % datetime)
left_button.when_pressed = camera.start_preview
left_button.when_released = camera.stop_preview
right_button.when_pressed = capture
pause()
示例6: btn_clicked
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
from gpiozero import Button, LED, TrafficLights
from time import sleep
from sys import exit
def btn_clicked():
lights.off()
quit()
button = Button(21)
lights = TrafficLights(17, 27, 22)
button.when_released = btn_clicked
def main():
print('Ready to use!')
while True:
# button.wait_for_press()
# print('Button pressed')
lights.green.on()
sleep(1)
lights.green.off()
lights.amber.on()
sleep(1)
lights.amber.off()
lights.red.on()
sleep(2)
lights.amber.on()
sleep(1)
示例7: time
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
global beep_start
global pause_start
global pause_stop
beep_start = time()
pause_stop = time()
pause_length = pause_stop - pause_start
print("Start: %.1f" % (beep_start))
print("Pause length: %.3f" % (pause_length))
buzzer.on()
def stop_buzzing():
global beep_start
global pause_start
beep_stop = time()
pause_start = time()
beep_length = beep_stop - beep_start
print("Length: %.1f" % (beep_length))
if beep_length > 0 and beep_length < 0.3:
print(".")
#urllib2.urlopen("http://morsecode.local/send.php?symbol=dot").read()
elif beep_length >= 0.3:
print("-")
#urllib2.urlopen("http://morsecode.local/send.php?symbol=dash").read()
buzzer.off()
while True:
button.when_pressed = start_buzzing
button.when_released = stop_buzzing
示例8: setClosed
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
global lastStatus
if lastStatus[0] != 'open':
lastStatus = ('open', time.time())
def setClosed():
global lastStatus
if lastStatus[0] != 'closed':
lastStatus = ('closed', time.time())
relay = LED(17, initial_value = True)
sensor = Button(27)
app = Flask(__name__)
lock = Lock()
sensor.when_pressed = setClosed
sensor.when_released = setOpen
def isOpen():
opened = not sensor.is_pressed
return opened
def elapsedTime():
return str(timedelta(seconds=time.time() - lastStatus[1]))
@app.route('/')
def index():
return render_template('index.html', open=isOpen(), elapsed=elapsedTime())
@app.route('/door', methods=['GET'])
def doorStatus():
return jsonify(open=not sensor.is_pressed, elapsed=elapsedTime())
示例9: int
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
#!/usr/bin/env python3
from gpiozero import Button, LED
from signal import pause
import os, sys
offGPIO = int(sys.argv[1]) if len(sys.argv) >= 2 else 21
holdTime = int(sys.argv[2]) if len(sys.argv) >= 3 else 6
ledGPIO = int(sys.argv[3]) if len(sys.argv) >= 4 else 2
def when_pressed():
# start blinking with 1/2 second rate
led.blink(on_time=0.5, off_time=0.5)
def when_released():
# be sure to turn the LEDs off if we release early
led.off()
def shutdown():
os.system("sudo poweroff")
led = LED(ledGPIO)
btn = Button(offGPIO, hold_time=holdTime)
btn.when_held = shutdown
btn.when_pressed = when_pressed
btn.when_released = when_released
pause()
示例10: Button
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from pyomxplayer import OMXPlayer
from gpiozero import LED, Button
import time
import sys
# we'll use a button to advance the slide show
yButton = Button(6, pull_up=False, bounce_time=0.05)
# and an LED to make sure the button is working properly
yLed = LED(20)
yButton.when_pressed = yLed.on
yButton.when_released = yLed.off
# we'll use another button for quitting the program (since it runs fullscreen)
rButton = Button(19, pull_up=False, bounce_time=0.05)
# sets up the video player
omx = OMXPlayer('../movs/MechanicalPrinciples.mov')
try:
# run this next section forever, until user stops the programme by pressing button
while True:
# play video if button is pressed and video player is currently paused
if yButton.is_pressed and omx.paused:
omx.toggle_pause()
# pause video if button is not pressed and player is not paused
if (not yButton.is_pressed) and (not omx.paused):
omx.toggle_pause()
示例11: topic
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("-e", "--endpoint", help="AWS IoT endpoint")
parser.add_argument("-i", "--clientID", help="Client ID", default='')
parser.add_argument("-r", "--rootCA", help="Root CA file path")
parser.add_argument("-c", "--cert", help="Certificate file path")
parser.add_argument("-k", "--key", help="Private key file path")
parser.add_argument("-s", "--source", help="Source", default="Sensor")
parser.add_argument("-n", "--name", help="Thing name", default=platform.node().split('.')[0])
parser.add_argument("-t", "--topic", help="MQTT topic(s)", nargs='+', required=False)
parser.add_argument("-p", "--pin", help="gpio pin (BCM)", type=int, required=True)
parser.add_argument("-y", "--high_value", help="high value", default="high")
parser.add_argument("-z", "--low_value", help="low value", default="low")
parser.add_argument("-a", "--high_alert", help="high alert", type=int, default=2)
parser.add_argument("-b", "--low_alert", help="low alert", type=int, default=1)
parser.add_argument("-w", "--cushion", help="seconds of cushion for twitchy sensor", type=float, default=0.0)
parser.add_argument("-l", "--log_level", help="Log Level", default=logging.INFO)
args = parser.parse_args()
logging.basicConfig(filename=LOG_FILE, level=args.log_level)
sensor = Button(args.pin)
sensor.when_pressed = high
sensor.when_released = low
pause()
示例12: trigger_function
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
import time
from gpiozero import Button, OutputDevice
CLIENT_ID = "KEY"
CLIENT_KEY = "KEY"
def trigger_function():
os.system("aplay -D plughw:1,0 /home/pi/beep.wav")
os.system("arecord -D plughw:2,0 -f S16_LE -d 5 /home/pi/query.wav")
os.system("aplay -D plughw:1,0 /home/pi/beep.wav")
call_houndify()
button = Button(4)
light = OutputDevice(3, active_high=False)
button.when_released = trigger_function
def call_houndify():
# We'll accept WAV files but it should be straightforward to
# use samples from a microphone or other source
BUFFER_SIZE = 512
client = houndify.StreamingHoundClient(CLIENT_ID, CLIENT_KEY, "test_user")
# Pretend we're at SoundHound HQ. Set other fields as appropriate
client.setLocation(37.778724, -122.414778)
fname = "/home/pi/query.wav"
示例13: say_hello
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
from gpiozero import Button
from signal import pause
def say_hello():
print("Hello!")
def say_goodbye():
print("Goodbye!")
button = Button(26)
button.when_pressed = say_hello
button.when_released = say_goodbye
pause()
示例14: LED
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
from gpiozero import LED, Button, Buzzer
from signal import pause
# Setup our LED, Button, and Buzzer
led = LED(19)
button = Button(6)
buzzer = Buzzer(17)
# Function we'll call on when_pressed event
def pressed(arg=None):
led.on()
buzzer.on()
# Function we'll call on when_released event
def released(arg=None):
led.off()
buzzer.off()
# Handle when_pressed event
button.when_pressed = pressed
# Handle when_released event
button.when_released = released
# Tell the user how to quit
print "Press Ctrl-C to exit"
# Pause and wait for butten events
pause()
示例15: PiGPIOFactory
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_released [as 别名]
from gpiozero import Button, Robot
from gpiozero.pins.pigpio import PiGPIOFactory
from signal import pause
factory = PiGPIOFactory(host='192.168.1.17')
robot = Robot(left=(4, 14), right=(17, 18), pin_factory=factory) # remote pins
# local buttons
left = Button(26)
right = Button(16)
fw = Button(21)
bw = Button(20)
fw.when_pressed = robot.forward
fw.when_released = robot.stop
left.when_pressed = robot.left
left.when_released = robot.stop
right.when_pressed = robot.right
right.when_released = robot.stop
bw.when_pressed = robot.backward
bw.when_released = robot.stop
pause()