Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sc137
Created September 11, 2018 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sc137/52e66de94322395f4fe9fe07af5d5594 to your computer and use it in GitHub Desktop.
Save sc137/52e66de94322395f4fe9fe07af5d5594 to your computer and use it in GitHub Desktop.
Push button camera for the AIY Vision kit
#!/usr/bin/env python3
#
# camera-button.py
#
# run this in the terminal
# push the button to take pics
# for the aiy vision kit
from gpiozero import Button
from picamera import PiCamera
from datetime import datetime
import time
from aiy.vision.leds import Leds
from aiy.vision.leds import RgbLeds
from aiy.vision.leds import PrivacyLed
# led colors
RED = (0xFF, 0x00, 0x00)
GREEN = (0x00, 0xFF, 0x00)
YELLOW = (0xFF, 0xFF, 0x00)
BLUE = (0x00, 0x00, 0xFF)
PURPLE = (0xFF, 0x00, 0xFF)
CYAN = (0x00, 0xFF, 0xFF)
WHITE = (0xFF, 0xFF, 0xFF)
button = Button(23)
camera = PiCamera()
leds = Leds()
# turn privacy light on
leds.update(Leds.privacy_on())
def capture():
#print('button pressed')
leds.update(Leds.rgb_on(GREEN))
time.sleep(1)
camera.resolution = (1920, 1080)
timestamp = datetime.now().isoformat()
camera.capture('/home/pi/Pictures/{}.jpg'.format(timestamp))
print('captured {}.jpg'.format(timestamp))
leds.update(Leds.rgb_off())
while True:
button.when_pressed = capture
n = input('push the button to capture. press any key to exit\n')
if n:
break
leds.update(Leds.privacy_off())
camera.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment