Skip to content

Commit

Permalink
overlay_scale in the example
Browse files Browse the repository at this point in the history
  • Loading branch information
FoamyGuy committed Mar 1, 2024
1 parent 16c7428 commit 1920616
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions examples/overlay/code_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 Tim Cocks for Adafruit Industries
#
# SPDX-License-Identifier: MIT
""" simple point-and-shoot camera example, with overly capabilities.
""" simple point-and-shoot camera example, with overly selecting using select button.
Place all overlay files inside /sd/overlays/ directory.
Usage:
Select Button - Change to the next overlay file
OK Button - Change between position and scale modes
D-Pad - Change the overlay's position or scale depending on which mode
we're currently in.
"""
import os
import time
import traceback
import adafruit_pycamera # pylint: disable=import-error

MODE_POSITION = 0
MODE_SCALE = 1
CURRENT_MODE = 0

int_scale = 100

pycam = adafruit_pycamera.PyCamera()
pycam.mode = 0 # only mode 0 (JPEG) will work in this example

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

if not pycam.down.value:
pycam.overlay_position[1] += 1 * (int(pycam.down.current_duration / 0.3) + 1)
if not pycam.up.value:
pycam.overlay_position[1] -= 1 * (int(pycam.up.current_duration / 0.3) + 1)

if not pycam.left.value:
pycam.overlay_position[0] -= 1 * (int(pycam.left.current_duration / 0.3) + 1)
if not pycam.right.value:
pycam.overlay_position[0] += 1 * (int(pycam.right.current_duration / 0.3) + 1)

if CURRENT_MODE == MODE_POSITION:
if not pycam.down.value:
pycam.overlay_position[1] += 1 * (
int(pycam.down.current_duration / 0.3) + 1
)
if not pycam.up.value:
pycam.overlay_position[1] -= 1 * (int(pycam.up.current_duration / 0.3) + 1)
if not pycam.left.value:
pycam.overlay_position[0] -= 1 * (
int(pycam.left.current_duration / 0.3) + 1
)
if not pycam.right.value:
pycam.overlay_position[0] += 1 * (
int(pycam.right.current_duration / 0.3) + 1
)
if CURRENT_MODE == MODE_SCALE:
if pycam.down.fell:
int_scale -= 10
pycam.overlay_scale = int_scale / 100
print(pycam.overlay_scale)
if pycam.up.fell:
int_scale += 10
pycam.overlay_scale = int_scale / 100
print(pycam.overlay_scale)

if pycam.ok.fell:
CURRENT_MODE = MODE_POSITION if CURRENT_MODE == MODE_SCALE else MODE_SCALE
print(f"Changing mode to: {CURRENT_MODE}")
if pycam.shutter.short_count:
print("Shutter released")
pycam.tone(1200, 0.05)
Expand Down

0 comments on commit 1920616

Please sign in to comment.