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


Python Button.wait_for_press方法代码示例

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


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

示例1: shutdownButton

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
def shutdownButton():
    button_2 = Button(23, pull_up=True)
    button_2.wait_for_press()
    speak("Herrunterfahren...")
    time.sleep(3)
    quitThread()
    call("mpg123 -q snd/Robot_dying.mp3", shell=True)
    call("/sbin/poweroff &", shell=True)
开发者ID:buxit,项目名称:mot2bot,代码行数:10,代码来源:http-pi2kf.py

示例2: main

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
def main():
    """
    Main method.

    :return:
    """
    api = init_tweepy_api()
    photo_path = ""
    count = 1
    #while count > 0:
    
    button = Button(17)
    camera = PiCamera()
    camera.start_preview()
    while True:
	count -= 1
        try:
            #curtime, photo_name = click_camera_cli()
	    curtime = datetime.now()
            now = curtime.strftime('%Y%m%d-%H%M%S')
            photo_name = now + '.jpg'

            # Take a picture upon button press
	    print "Starting camera preview"
	    print "Is button pressed: " + str(button.is_pressed)
            button.wait_for_press()
	    print "Button pressed"
            photo_path = '/home/pi/' + photo_name
            camera.capture(photo_path)
	    print "Photo taken " + photo_path
            #camera.stop_preview()

            # Send the tweet with photo
	    print "Tweeting pic at : " + photo_path
            status = 'Photo auto-tweet from Smart Tree: ' + curtime.strftime('%Y/%m/%d %H:%M:%S')
            api.update_with_media(photo_path, status=status)
            sleep(10)
            # Delete pic after successful upload
            cleanup_pic(photo_path)
        except:
            # Catch all errors and continue looping
            print "Unexpected error:", sys.exc_info()
            cleanup_pic(photo_path)
开发者ID:shruti514,项目名称:SmartStreetUserApp-Commons,代码行数:45,代码来源:pressure_sensor_handler.py

示例3: main

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

    FLASH = flash.Flash(3)
    BUTTON = Button(14)

    while True:

        BUTTON.wait_for_press()

        print('Capturing...')

        fileName = 'image ' + datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') + '.png'

        FLASH.on()

        raspEYE.takePicture(fileName, sec=0, res=(1000, 750))

        FLASH.off()

        print('Finished')
开发者ID:oodeagleoo,项目名称:raspEYE,代码行数:22,代码来源:buttonCamera.py

示例4: main

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
def main():
    button = Button(5)

    red=LED(2)
    amber=LED(17)
    green=LED(11)

    button.wait_for_press()

    red.on()
    amber.on()
    green.on()

    with PiCamera() as camera:  
        timestamp = datetime.now().isoformat()
        photo_path = '/home/pi/push-button-photo/photos/%s.jpg' % timestamp
        camera.start_preview()
        sleep(1)
        red.off()
        amber.on()
        green.on()
        sleep(1)
        red.off()
        amber.off()
        green.on()
        sleep(1)
        red.off()
        amber.off()
        green.off()
        camera.capture(photo_path)
        camera.stop_preview()

    message = "I have been taking photos with code..."
    with open(photo_path, 'rb') as photo:
        twitter.update_status_with_media(status=message, media=photo)
    print("Tweeted: %s" % message)
开发者ID:LornaLynch,项目名称:Push-Button-Photo,代码行数:38,代码来源:push-button-photo.py

示例5: PiCamera

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
with PiCamera() as camera:
        #camera.start_preview()
        path, dirs, files = os.walk('/home/pi/photo_output').next()
	file_count = len(files)
	print (file_count)
	frame = 1 + file_count
        while True:
                if stop.is_pressed:
			draw.rectangle((0,0,LCD.LCDWIDTH,LCD.LCDHEIGHT), outline=255, fill=255)
        		draw.text((3,20), 'Safe stop', font=font)
        		disp.image(image)
        		disp.display()
        		time.sleep(2)
        		subprocess.call('sudo halt', shell=True)
		button.wait_for_press()
                yellow.source = button.values
                draw.rectangle((0,0,LCD.LCDWIDTH,LCD.LCDHEIGHT), outline=255, fill=255)
		#disp.image(image)
                disp.display()
		draw.text((3,0),'Taking ....', font=font)
		disp.image(image)
                disp.display()
		print ("About to capture photo")
                camera.capture('/home/pi/photo_output/frame%03d.jpg' % frame)
                print (frame)
		draw.text((3,10),'Frames taken:', font=font)
		draw.text((10,20), str(frame), font=font)
                draw.text((0,30), str(startup), font=font)
		disp.image(image)
		disp.display()
开发者ID:uktechreviews,项目名称:motion_cam,代码行数:32,代码来源:drop_cam2.py

示例6: StrikeZone

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
        # Create instance of StrikeZone
        detectZone = StrikeZone()

        #Now initialize sensors
        for index, horizPin in enumerate(HORIZ_GPIO_PINS):
            horizSensors.append(LightSensor(horizPin, 
                                            queue_len = QUEUE_LEN,
                                            charge_time_limit = CHARGE_TIME))
            horizSensors[index].when_dark = detectZone.horizDark 
            horizSensors[index].when_light = detectZone.horizLight 
        for index, vertPin in enumerate(VERT_GPIO_PINS):
            vertSensors.append(LightSensor(vertPin, 
                                           queue_len = QUEUE_LEN,
                                           charge_time_limit = CHARGE_TIME))
            vertSensors[index].when_dark = detectZone.vertDark
            vertSensors[index].when_light = detectZone.vertLight

        while True:
            if pitchButton.wait_for_press(10):
                #Button was pressed
                detectZone.start()
                sleep(1)
            elif detectZone.waitForPitch:
                # If ready for pitch but got timeout
                # Tell strikezone it was a ball an reset
                detectZone.ball()

    except KeyboardInterrupt:
        print("Thanks for playing...")

开发者ID:Lennster,项目名称:baseball-strikezone-detector,代码行数:31,代码来源:XxY_LDR_strikezone.py

示例7: Button

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
quizfilename = "quiz.txt"

start_button = Button(23)
true_button = Button(22)
false_button = Button(4)

# Initialise display
lcd_init()

# Send some test
lcd_string("Raspberry Pi",LCD_LINE_1)
lcd_string("True or False quiz",LCD_LINE_2)
lcd_string("",LCD_LINE_3)
lcd_string("Press start",LCD_LINE_4)

start_button.wait_for_press()

# Note that there is no error handling of file not exist 
# Consider using a try except block
# Open the file
file = open(quizfilename)

questions = 0
score = 0
answer = ''

while True:
    # print 4 lines as the questions
    thisline = file.readline().rstrip("\n")
    if thisline == "" : break
    lcd_string(thisline,LCD_LINE_1)
开发者ID:penguintutor,项目名称:learnelectronics,代码行数:33,代码来源:quiz.py

示例8: life_counter

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
        life2.off()
        life3.off()

lives = 3
life_counter(lives)

while True:
    time.sleep(0.01)
    for i in range(2):
        buzzer.on()
        time.sleep(0.5)
        buzzer.off()
        time.sleep(0.5)
    while lives > 0:
        time.sleep(0.01)
        tool.wait_for_press()
        for i in range(3):
            buzzer.on()
            time.sleep(0.2)
            buzzer.off()
            time.sleep(0.2)
        time.sleep(0.1)
        print("You lost a life")
        lives = lives - 1
        life_counter(lives)
    if lives == 0:
        print("Game Over")
        time.sleep(3)
        lives=3
        life_counter(lives)
开发者ID:lesp,项目名称:LV24-Dr-Robot,代码行数:32,代码来源:Dr-Robot-GPIO-Zero.py

示例9: tweet

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
    global last_capture
    dt = datetime.now().isoformat()
    filename = '/home/pi/photobooth/{}.jpg'.format(dt)
    camera.capture(filename)
    last_capture = filename

def tweet(message, img):
    with open(img, 'rb') as photo:
        twitter.update_status_with_media(status=message, media=photo)

left.when_pressed = change_effect

while True:
    camera.start_preview()
    camera.annotate_text = "Press left button to change the effect"
    sleep(2)
    camera.annotate_text = "Press right button to take a picture"
    sleep(2)
    camera.annotate_text = None
    right.wait_for_press()
    capture()
    camera.annotate_text = "Press right button to tweet the photo"
    right.wait_for_press()
    camera.stop_preview()
    handle = input("Enter your Twitter handle: @")
    message = "Welcome to @Raspberry_Pi Towers, @{}".format(handle)
    tweet(message, last_capture)
    camera.start_preview()
    camera.annotate_text = "Tweeted!"
    sleep(2)
开发者ID:bennuttall,项目名称:photobooth,代码行数:32,代码来源:camera.py

示例10: sleep

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
        sleep(n)
        for i in range(150):
            strip.setPixelColor(i,Color(0,0,0))
        strip.show()
        sleep(n)



if __name__ == '__main__':
    strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
    strip.begin()
    try:
        lights = ['pink','yellow','blue','green']

        while True:
            green.wait_for_press()
            for i in range(16):
                for light in lights:
                    neo(light,0.1)
            random.shuffle(lights)
            print(lights)
            sleep(0.5)
            player = []
            for light in lights:
                neo(light,0.3)    
            for i in range(150):
                strip.setPixelColor(i,Color(0,0,0))
                strip.show()
            while len(player) <4:
                sleep(0.3)
                if green.is_pressed:
开发者ID:lesp,项目名称:Pymon,代码行数:33,代码来源:pymon.py

示例11: Button

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
# wait for button event before continuing....

from gpiozero import Button

btn = Button(4)

btn.wait_for_press()
print("Button was pressed")
开发者ID:hardikrathod4,项目名称:Raspberry_Pi_and_Arduino,代码行数:10,代码来源:Button2.py

示例12: photo_tweet

# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import wait_for_press [as 别名]
        camera.start_preview()
        camera.annotate_text = "Press red button to post to Twitter"
        rightbutton.wait_for_press()
        camera.annotate_text = ""
        camera.capture(photo_path)
        camera.stop_preview()
        
    photo_tweet(photo_path)

    sleep(5)
        
while True:
    #replace with you video, always needs to reestablish variable or won't loop video
    player = OMXPlayer("test.mov")
    print("Press the left button to play")
    rightbutton.when_pressed = player.pause
    leftbutton.wait_for_press()
    player.play()
    print(player.playback_status())
    try:
        while player.playback_status():
            if player.playback_status() == "Paused":
                terrorcam()
    except:
        pass
    print("Waiting for motion")
    pir.wait_for_motion()
    tweetpic()
    
            
开发者ID:YasminC,项目名称:RPCT-Project,代码行数:30,代码来源:init.py


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