From 1920616c0c49dbe457003d8e5459bdf86a6ca8e4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 29 Feb 2024 20:23:08 -0600 Subject: [PATCH] overlay_scale in the example --- examples/overlay/code_select.py | 53 ++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/examples/overlay/code_select.py b/examples/overlay/code_select.py index da7ca6f..665d4e2 100644 --- a/examples/overlay/code_select.py +++ b/examples/overlay/code_select.py @@ -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 @@ -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)