Pan/Tilt

Setting position


In [0]:
import time
from gpiozero import PWMOutputDevice

with PWMOutputDevice(20) as h, PWMOutputDevice(21) as v:
    h.value = .11
    v.value = .25
    time.sleep(2)
    
    h.value = .2
    v.value = .11
    time.sleep(2)
    
    h.value = .14
    v.value = 0.18
    time.sleep(1)

Rotating


In [0]:
import time
from gpiozero import PWMOutputDevice

with PWMOutputDevice(20) as h, PWMOutputDevice(21) as v:
    for i in range(10, 20, 1):
        h.value = i/100.0
        time.sleep(.5)
    for i in range(1, 30, 2):
        v.value = i / 100.0
        time.sleep(.5)
    for i in range(20, 10, -1):
        h.value = i / 100.0
        time.sleep(.5)
    for i in range(30, 10, -2):
        v.value = i / 100.0
        time.sleep(.5)

    h.value = .14
    v.value = 0.18
    time.sleep(1)

Photo (again)


In [0]:
from gpiozero import Button
from gpiozero import PWMOutputDevice
import picamera
import time


with picamera.PiCamera() as camera, Button(23) as white, Button(22) as blue, \
       PWMOutputDevice(20) as h, PWMOutputDevice(21) as v:
    camera.hflip = True
    camera.vflip = True
    current = .18
    h.value = .14
    v.value = .18
    while True:
        if white.is_pressed and blue.is_pressed:
            camera.start_preview()
            time.sleep(2)
            camera.capture('image.jpg')
            camera.stop_preview() 
            h.value = .14
            v.value = .18
            time.sleep(1)
            break
        if white.is_pressed and not blue.is_pressed:
            if current < 1:
                current += .01
        elif not white.is_pressed and blue.is_pressed:
            if current > 0:
                current -= .01
        v.value = current
        time.sleep(0.5)

# preview
from IPython.display import Image
Image(filename='image.jpg')

In [0]: