brookhouser
Posts: 4
Joined: Mon Mar 21, 2016 5:08 am

Button controlled effects with picam

Thu Jan 18, 2018 5:02 pm

Hey all! I am working with some students to create a camera display that triggers effects on the push of a few buttons. I can get the preview to work with effects using the raspberrypi.org getting started with picam tutorial. I can also get the button to trigger the preview using the gpiozero documentation. I cannot get the button to trigger an effect by attempting to combine the two.

Here is the code that isn't working.

Code: Select all

from gpiozero import Button
from picamera import PiCamera
from time import sleep
left_button = Button(3)
camera = PiCamera()
camera.start_preview()
left_button.when_pressed = camera.image_effect = 'colorswap'
sleep(10)
camera.stop_preview()
I assume there is a problem with line 7 using two equal signs. Anyone see a fix for me?

THanks,

Kevin Brookhouser

brookhouser
Posts: 4
Joined: Mon Mar 21, 2016 5:08 am

Re: Button controlled effects with picam

Thu Jan 18, 2018 5:35 pm

File this under, "let's wait and see if he figures this out on his own."

This code seems to work exactly how I want.

Code: Select all

from gpiozero import Button
from picamera import PiCamera
from time import sleep
negativeButton = Button(2)
resetButton = Button(3)
sketchButton = Button(4)
camera = PiCamera()
camera.start_preview()
while True:
    if sketchButton.is_pressed:
        camera.image_effect = 'sketch'
        sleep(5)

    elif negativeButton.is_pressed:
        camera.image_effect = 'negative'
        sleep(5)
    elif resetButton.is_pressed:
        camera.stop_preview()
    else:
        camera.image_effect = 'none'

Return to “Staffroom, classroom and projects”

Who is online

Users browsing this forum: No registered users and 3 guests