ich muss am Donnerstag meine Projektarbeit abgeben und dazu muss ich dieses Script object orientiert programmieren, wobei ich keine Ahnung habe.
Kann mir hierzu jemand jhelfen?
Vielen Dank im Voraus
Phillip
Code: Alles auswählen
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 12 11:25:37 2018
@author: pi
"""
import time, datetime
import RPi.GPIO as GPIO
import telepot
from telepot.loop import MessageLoop
from picamera import PiCamera
from time import sleep
camera = PiCamera()
#benutze Pins
other = 4
yellow = 13
red = 5
green = 26
taster = 21
#Import fǬr GPIO
now = datetime.datetime.now()
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#beschreibung der GPIO
#other
GPIO.setup(other, GPIO.OUT)
GPIO.output(other, 0) #Off initially
#LED Yellow
GPIO.setup(yellow, GPIO.OUT)
GPIO.output(yellow, 0) #Off initially
#LED Red
GPIO.setup(red, GPIO.OUT)
GPIO.output(red, 0) #Off initially
#LED green
GPIO.setup(green, GPIO.OUT)
GPIO.output(green, 0) #Off initially
#taster
GPIO.setup(taster, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)#Signal HIGH bis 'Taster' dann LOW
class RemotePi:# klÇÏglicher definitions Versuch bzgl. OOP
pass
#Interaktion mit Telegram App
def action(msg):
chat_id = msg['chat']['id']
command = msg['text']
print ('Received: %s') % command
if 'on' in command:
message = "Turned on "
if 'other' in command:
message = message + "other "
GPIO.output(other, 1)
if 'yellow' in command:
message = message + "yellow "
GPIO.output(yellow, 1)
if 'red' in command:
message = message + "red "
GPIO.output(red, 1)
if 'green' in command:
message = message + "green "
GPIO.output(green, 1)
if 'all' in command:
message = message + "all "
GPIO.output(other, 1)
GPIO.output(yellow, 1)
GPIO.output(red, 1)
GPIO.output(green, 1)
message = message + "light(s)"
telegram_bot.sendMessage (chat_id, message)
if 'off' in command:
message = "Turned off "
if 'other' in command:
message = message + "other "
GPIO.output(other, 0)
if 'yellow' in command:
message = message + "yellow "
GPIO.output(yellow, 0)
if 'red' in command:
message = message + "red "
GPIO.output(red, 0)
if 'green' in command:
message = message + "green "
GPIO.output(green, 0)
if 'all' in command:
message = message + "all "
GPIO.output(other, 0)
GPIO.output(yellow, 0)
GPIO.output(red, 0)
GPIO.output(green, 0)
message = message + "light(s)"
telegram_bot.sendMessage (chat_id, message)
#beginn CAM
if 'picture' in command:
message = "Picture"
if 'send' in command:
message = " waiting for last "+ message + "..."
message = message
telegram_bot.sendMessage (chat_id, message)
telegram_bot.sendDocument(chat_id, document=open('/home/pi/PiCam.jpg'))
if 'take' in command:
message = message + " taken ..."
message = message
telegram_bot.sendMessage (chat_id, message)
camera.capture ('PiCam.jpg')
sleep(1)
telegram_bot.sendDocument(chat_id, document=open('/home/pi/PiCam.jpg'))
#Ende CAM
#Remote Funktioniert bis hier her-->Messenger kommunikation.
#Taster einbinden, funktioniert NICHT!"
def doIfHigh(channel):
chat_id = channel ['chat']['id']
# Wenn Eingang HIGH ist, Ausgabe im Terminal erzeugen
print ("Eingang HIGH ")
message = "New Move"
telegram_bot.sendMessage (chat_id, message)
camera.capture ('PiCam.jpg')
sleep(1)
telegram_bot.sendDocument(chat_id, document=open('/home/pi/PiCam.jpg'))
# Ereignis deklarieren
GPIO.add_event_detect(taster, GPIO.RISING, callback = doIfHigh, bouncetime = 200)
#Ende Taster einbinden
telegram_bot = telepot.Bot('******')
print (telegram_bot.getMe())
MessageLoop(telegram_bot, action).run_as_thread()
print ('Up and Running....')
while 1:
time.sleep(10)