|
2 | 2 | # SPDX-FileCopyrightText: Copyright (c) 2024 Tim Cocks for Adafruit Industries
|
3 | 3 | #
|
4 | 4 | # 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. |
6 | 6 |
|
7 | 7 | 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. |
15 | 8 | """
|
16 | 9 | import os
|
17 | 10 | import time
|
18 | 11 | import traceback
|
19 | 12 | import adafruit_pycamera # pylint: disable=import-error
|
20 | 13 |
|
| 14 | +MODE_POSITION = 0 |
| 15 | +MODE_SCALE = 1 |
| 16 | +CURRENT_MODE = 0 |
| 17 | + |
| 18 | +int_scale = 100 |
| 19 | + |
21 | 20 | pycam = adafruit_pycamera.PyCamera()
|
22 | 21 | pycam.mode = 0 # only mode 0 (JPEG) will work in this example
|
23 | 22 |
|
|
56 | 55 | print(f"changing overlay to {overlay_files[cur_overlay_idx]}")
|
57 | 56 | pycam.overlay = f"/sd/overlays/{overlay_files[cur_overlay_idx]}"
|
58 | 57 |
|
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}") |
69 | 86 | if pycam.shutter.short_count:
|
70 | 87 | print("Shutter released")
|
71 | 88 | pycam.tone(1200, 0.05)
|
|
0 commit comments