on high signal send to telegram
This commit is contained in:
42
local_code/animated_gif.py
Normal file
42
local_code/animated_gif.py
Normal file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2017-2020 Richard Hull and contributors
|
||||
# See LICENSE.rst for details.
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
|
||||
"""
|
||||
Displays an animated gif.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from demo_opts import get_device
|
||||
from PIL import Image, ImageSequence, ImageOps
|
||||
from luma.core.sprite_system import framerate_regulator
|
||||
|
||||
|
||||
def main():
|
||||
regulator = framerate_regulator(fps=45)
|
||||
img_path = str(Path(__file__).resolve().parent.joinpath('images', 'inverted_cat_s.gif'))
|
||||
banana = Image.open(img_path)
|
||||
size = [min(*device.size)] * 2
|
||||
posn = ((device.width - size[0]) // 2, device.height - size[1])
|
||||
|
||||
while True:
|
||||
for frame in ImageSequence.Iterator(banana):
|
||||
with regulator:
|
||||
#background = Image.new("RGBA", device.size, "black")
|
||||
#background.paste(frame.resize(size, resample=Image.LANCZOS), posn)
|
||||
#device.mode = "1"
|
||||
#device.display(background.convert(device.mode))
|
||||
|
||||
|
||||
device.display(frame.convert(device.mode))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
device = get_device()
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
@ -1,24 +1,34 @@
|
||||
from RPi import GPIO
|
||||
import RPi.GPIO as GPIO
|
||||
import requests
|
||||
import time
|
||||
|
||||
# Set up GPIO pin (example using BCM pin 14)
|
||||
GPIO_PIN = 26
|
||||
|
||||
def setup():
|
||||
# Set up GPIO
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(GPIO_PIN, GPIO.IN)
|
||||
GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
def loop():
|
||||
Messwert = GPIO.input(GPIO_PIN) # Read analog value from the pin
|
||||
Spannung = ((Messwert * 250) / 1023) / 10 # Map and scale to desired range (0-2.5V)
|
||||
print(f"Spannung: {Spannung:.2f} V") # Print with two decimal places
|
||||
|
||||
time.sleep(1)
|
||||
def send_message():
|
||||
try:
|
||||
response = requests.post(
|
||||
'http://beere5:5020/send',
|
||||
json={'message': 'klingel geht'},
|
||||
headers={'Content-Type': 'application/json'}
|
||||
)
|
||||
return f"Message sent with status code {response.status_code}"
|
||||
except Exception as e:
|
||||
return f"Error sending message: {str(e)}"
|
||||
|
||||
# Main loop
|
||||
if __name__ == "__main__":
|
||||
setup()
|
||||
try:
|
||||
while True:
|
||||
loop()
|
||||
current_state = GPIO.input(19)
|
||||
if current_state == 1:
|
||||
print("GPIO Pin 19 is HIGH")
|
||||
result = send_message()
|
||||
print(result)
|
||||
time.sleep(5)
|
||||
time.sleep(0.5) # Check pin every 5 seconds
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup() # Clean up when Ctrl+C is pressed
|
||||
print("\nProgram stopped by user")
|
||||
finally:
|
||||
GPIO.cleanup()
|
||||
|
66
local_code/demo_opts.py
Normal file
66
local_code/demo_opts.py
Normal file
@ -0,0 +1,66 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2014-2022 Richard Hull and contributors
|
||||
# See LICENSE.rst for details.
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
from luma.core import cmdline, error
|
||||
|
||||
|
||||
# logging
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format='%(asctime)-15s - %(message)s'
|
||||
)
|
||||
# ignore PIL debug messages
|
||||
logging.getLogger('PIL').setLevel(logging.ERROR)
|
||||
|
||||
|
||||
def display_settings(device, args):
|
||||
"""
|
||||
Display a short summary of the settings.
|
||||
|
||||
:rtype: str
|
||||
"""
|
||||
iface = ''
|
||||
display_types = cmdline.get_display_types()
|
||||
if args.display not in display_types['emulator']:
|
||||
iface = f'Interface: {args.interface}\n'
|
||||
|
||||
lib_name = cmdline.get_library_for_display_type(args.display)
|
||||
if lib_name is not None:
|
||||
lib_version = cmdline.get_library_version(lib_name)
|
||||
else:
|
||||
lib_name = lib_version = 'unknown'
|
||||
|
||||
import luma.core
|
||||
version = f'luma.{lib_name} {lib_version} (luma.core {luma.core.__version__})'
|
||||
|
||||
return f'Version: {version}\nDisplay: {args.display}\n{iface}Dimensions: {device.width} x {device.height}\n{"-" * 60}'
|
||||
|
||||
|
||||
def get_device(actual_args=None):
|
||||
"""
|
||||
Create device from command-line arguments and return it.
|
||||
"""
|
||||
if actual_args is None:
|
||||
actual_args = sys.argv[1:]
|
||||
parser = cmdline.create_parser(description='luma.examples arguments')
|
||||
args = parser.parse_args(actual_args)
|
||||
|
||||
if args.config:
|
||||
# load config from file
|
||||
config = cmdline.load_config(args.config)
|
||||
args = parser.parse_args(config + actual_args)
|
||||
|
||||
# create device
|
||||
try:
|
||||
device = cmdline.create_device(args)
|
||||
print(display_settings(device, args))
|
||||
return device
|
||||
|
||||
except error.Error as e:
|
||||
parser.error(e)
|
||||
return None
|
||||
|
@ -15,10 +15,10 @@ from luma.core.sprite_system import framerate_regulator
|
||||
|
||||
|
||||
def main():
|
||||
regulator = framerate_regulator(fps=60)
|
||||
regulator = framerate_regulator(fps=45)
|
||||
img_path = str(Path(__file__).resolve().parent.joinpath('images', 'cat.gif'))
|
||||
banana = Image.open(img_path)
|
||||
size = [min(*device.size)] * 2
|
||||
size = [min(*device.size)] * 3
|
||||
posn = ((device.width - size[0]) // 2, device.height - size[1])
|
||||
|
||||
while True:
|
||||
|
BIN
local_code/images/inverted_cat_s.gif
Normal file
BIN
local_code/images/inverted_cat_s.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Reference in New Issue
Block a user