Skip to content

Commit 00691dd

Browse files
authored
add basic_camera code
For JP per Limor
1 parent 5e9777d commit 00691dd

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

examples/basic_camera/code.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 john park for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
''' simple point-and-shoot camera example. No bells! Zero whistles! '''
5+
6+
import time
7+
import adafruit_pycamera # pylint: disable=import-error
8+
9+
pycam = adafruit_pycamera.PyCamera()
10+
pycam.mode = 0 # only mode 0 (JPEG) will work in this example
11+
12+
# User settings - try changing these:
13+
pycam.resolution = 8 # 0-12 preset resolutions:
14+
# 0: 240x240, 1: 320x240, 2: 640x480, 3: 800x600, 4: 1024x768,
15+
# 5: 1280x720, 6: 1280x1024, 7: 1600x1200, 8: 1920x1080, 9: 2048x1536,
16+
# 10: 2560x1440, 11: 2560x1600, 12: 2560x1920
17+
pycam.led_level = 1 # 0-4 preset brightness levels
18+
pycam.led_color = 0 # 0-7 preset colors: 0: white, 1: green, 2: yellow, 3: red,
19+
# 4: pink, 5: blue, 6: teal, 7: rainbow
20+
pycam.effect = 0 # 0-7 preset FX: 0: normal, 1: invert, 2: b&w, 3: red,
21+
# 4: green, 5: blue, 6: sepia, 7: solarize
22+
23+
print("Simple camera ready.")
24+
pycam.tone(800, 0.1)
25+
pycam.tone(1200, 0.05)
26+
27+
while True:
28+
pycam.blit(pycam.continuous_capture())
29+
pycam.keys_debounce()
30+
31+
if pycam.shutter.short_count:
32+
print("Shutter released")
33+
pycam.tone(1200, 0.05)
34+
pycam.tone(1600, 0.05)
35+
try:
36+
pycam.display_message("snap", color=0x00DD00)
37+
pycam.capture_jpeg()
38+
pycam.live_preview_mode()
39+
except TypeError as exception:
40+
pycam.display_message("Failed", color=0xFF0000)
41+
time.sleep(0.5)
42+
pycam.live_preview_mode()
43+
except RuntimeError as exception:
44+
pycam.display_message("Error\nNo SD Card", color=0xFF0000)
45+
time.sleep(0.5)
46+
47+
if pycam.card_detect.fell:
48+
print("SD card removed")
49+
pycam.unmount_sd_card()
50+
pycam.display.refresh()
51+
52+
if pycam.card_detect.rose:
53+
print("SD card inserted")
54+
pycam.display_message("Mounting\nSD Card", color=0xFFFFFF)
55+
for _ in range(3):
56+
try:
57+
print("Mounting card")
58+
pycam.mount_sd_card()
59+
print("Success!")
60+
break
61+
except OSError as exception:
62+
print("Retrying!", exception)
63+
time.sleep(0.5)
64+
else:
65+
pycam.display_message("SD Card\nFailed!", color=0xFF0000)
66+
time.sleep(0.5)
67+
pycam.display.refresh()

0 commit comments

Comments
 (0)