Skip to content

Commit 1920616

Browse files
committed
overlay_scale in the example
1 parent 16c7428 commit 1920616

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

examples/overlay/code_select.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
# SPDX-FileCopyrightText: Copyright (c) 2024 Tim Cocks for Adafruit Industries
33
#
44
# SPDX-License-Identifier: MIT
5-
""" simple point-and-shoot camera example, with overly capabilities.
5+
""" simple point-and-shoot camera example, with overly selecting using select button.
66
77
Place all overlay files inside /sd/overlays/ directory.
8-
9-
Usage:
10-
11-
Select Button - Change to the next overlay file
12-
OK Button - Change between position and scale modes
13-
D-Pad - Change the overlay's position or scale depending on which mode
14-
we're currently in.
158
"""
169
import os
1710
import time
1811
import traceback
1912
import adafruit_pycamera # pylint: disable=import-error
2013

14+
MODE_POSITION = 0
15+
MODE_SCALE = 1
16+
CURRENT_MODE = 0
17+
18+
int_scale = 100
19+
2120
pycam = adafruit_pycamera.PyCamera()
2221
pycam.mode = 0 # only mode 0 (JPEG) will work in this example
2322

@@ -56,16 +55,34 @@
5655
print(f"changing overlay to {overlay_files[cur_overlay_idx]}")
5756
pycam.overlay = f"/sd/overlays/{overlay_files[cur_overlay_idx]}"
5857

59-
if not pycam.down.value:
60-
pycam.overlay_position[1] += 1 * (int(pycam.down.current_duration / 0.3) + 1)
61-
if not pycam.up.value:
62-
pycam.overlay_position[1] -= 1 * (int(pycam.up.current_duration / 0.3) + 1)
63-
64-
if not pycam.left.value:
65-
pycam.overlay_position[0] -= 1 * (int(pycam.left.current_duration / 0.3) + 1)
66-
if not pycam.right.value:
67-
pycam.overlay_position[0] += 1 * (int(pycam.right.current_duration / 0.3) + 1)
68-
58+
if CURRENT_MODE == MODE_POSITION:
59+
if not pycam.down.value:
60+
pycam.overlay_position[1] += 1 * (
61+
int(pycam.down.current_duration / 0.3) + 1
62+
)
63+
if not pycam.up.value:
64+
pycam.overlay_position[1] -= 1 * (int(pycam.up.current_duration / 0.3) + 1)
65+
if not pycam.left.value:
66+
pycam.overlay_position[0] -= 1 * (
67+
int(pycam.left.current_duration / 0.3) + 1
68+
)
69+
if not pycam.right.value:
70+
pycam.overlay_position[0] += 1 * (
71+
int(pycam.right.current_duration / 0.3) + 1
72+
)
73+
if CURRENT_MODE == MODE_SCALE:
74+
if pycam.down.fell:
75+
int_scale -= 10
76+
pycam.overlay_scale = int_scale / 100
77+
print(pycam.overlay_scale)
78+
if pycam.up.fell:
79+
int_scale += 10
80+
pycam.overlay_scale = int_scale / 100
81+
print(pycam.overlay_scale)
82+
83+
if pycam.ok.fell:
84+
CURRENT_MODE = MODE_POSITION if CURRENT_MODE == MODE_SCALE else MODE_SCALE
85+
print(f"Changing mode to: {CURRENT_MODE}")
6986
if pycam.shutter.short_count:
7087
print("Shutter released")
7188
pycam.tone(1200, 0.05)

0 commit comments

Comments
 (0)