Programm 1:
Code: Alles auswählen
import RPi.GPIO as GPIO
import lcddriver
import time
import os
# Use the Broadcom SOC Pin numbers
GPIO.setmode(GPIO.BCM)
# Import LCD driver (lcddriver.py file)
lcd = lcddriver.lcd()
# Setup the pins with internal pullups enabled and pin in reading mode.
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Shutdown button GPIO 21
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Reboot button GPIO 18
# Our functions on what to do when the button is pressed
def Shutdown(channel):
print("Shutting Down") #Show text in terminal
lcd.lcd_display_string("Shutting Down",1) #Display text in LCD
time.sleep(3) #Sleep 3 seconds
os.system("sudo shutdown now") #Write command
def Reboot(channel):
print("Rebooting")
lcd.lcd_display_string("Rebooting",1)
time.sleep(3)
os.system("sudo reboot")
# Add our function to execute when the button pressed event happens
GPIO.add_event_detect(21, GPIO.FALLING, callback=Shutdown, bouncetime=2000)
GPIO.add_event_detect(18, GPIO.FALLING, callback=Reboot, bouncetime=2000)
#Wait!
while 1:
time.sleep(1)
Code: Alles auswählen
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import lcddriver
import signal, sys
import datetime
import time
import mysql
import mysql.connector
import os
#import lcddriver
#from time import*
lcd = lcddriver.lcd()
lcd.lcd_clear()
mydb = mysql.connector.connect(
host="localhost",
user="pi",
password="raspberry",
database="rfid"
)
GPIO.setmode(GPIO.BCM)
LED_BLUE = 12
LED_GREEN = 16
LED_YELLOW = 20
LED_RED = 21
GPIO.setup(LED_BLUE, GPIO.OUT)
GPIO.setup(LED_GREEN, GPIO.OUT)
GPIO.setup(LED_YELLOW, GPIO.OUT)
GPIO.setup(LED_RED, GPIO.OUT)
GPIO.output(LED_BLUE, GPIO.LOW)
GPIO.output(LED_GREEN, GPIO.LOW)
GPIO.output(LED_YELLOW, GPIO.LOW)
GPIO.output(LED_RED, GPIO.LOW)
#Parameter fuer Eintragung
evsb06 = "Training"
evsb08 = "Weisweil"
def abbruch(signal, frame):
lcd.lcd_display_string(" ",1)
lcd.lcd_display_string(" ",2)
GPIO.cleanup()
sys.exit(0)
GPIO.output(LED_BLUE, GPIO.HIGH)
signal.signal(signal.SIGINT, abbruch)
reader=SimpleMFRC522()
print ("Programm gestartet zum Karten scannen!")
lcd.lcd_display_string(" OK Los geht es ",1)
while True:
GPIO.output(LED_GREEN, GPIO.HIGH)
now = datetime.datetime.today()
evsb05 = now.strftime('%Y-%m-%d')
evsb09 = now.strftime('%Y')
evsb10 = time.strftime('%H:%M:%S', time.localtime())
evsb11 = ""
cid, text=reader.read()
lcd.lcd_display_string(" Karte erkannt ",1)
time.sleep(1)
lcd.lcd_display_string(" Daten werden ",1)
lcd.lcd_display_string(" verarbeitet ",2)
GPIO.output(LED_GREEN, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_GREEN, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_GREEN, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_GREEN, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_GREEN, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_GREEN, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_GREEN, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_GREEN, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_GREEN, GPIO.LOW)
GPIO.output(LED_YELLOW, GPIO.HIGH)
time.sleep(0.2)
lcd.lcd_display_string("Daten wurden in ",1)
lcd.lcd_display_string(" DB eingetragen ",2)
ivsb07 = cid
mycursor = mydb.cursor()
sql = f"SELECT * FROM db where db04 = {cid}"
mycursor.execute(sql)
myresult = mycursor.fetchone()
if myresult is not None:
mycursor = mydb.cursor()
sql = f"SELECT * FROM db WHERE db04 = {cid}"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for row in myresult:
ivsb01 = row[1]
ivsb02 = row[2]
ivsb03 = row[3]
ivsb04 = row[4]
ivsb05 = evsb05
ivsb06 = evsb06
ivsb07 = cid
ivsb08 = evsb08
ivsb09 = evsb09
ivsb10 = evsb10
ivsb11 = evsb11
ivsb12 = ""
mycursor = mydb.cursor()
sql = "INSERT INTO iss (vsb01, vsb02, vsb03, vsb04, vsb05, vsb06, vsb07, vsb08, vsb09, vsb10, vsb11, vsb12) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
val = (ivsb01, ivsb02, ivsb03, ivsb04, ivsb05, ivsb06, ivsb07, ivsb08, ivsb09, ivsb10, ivsb11, ivsb12)
mycursor.execute(sql, val)
mydb.commit()
time.sleep(1)
#gogo = str(cid)
print (cid)
print("Nächste Karte.")
GPIO.output(LED_YELLOW, GPIO.LOW)
lcd.lcd_display_string("OK, weitere C/K ",1)
lcd.lcd_display_string(" ",2)
else:
mycursor = mydb.cursor()
sql = f"SELECT * FROM cd where cd01 = {cid}"
mycursor.execute(sql)
myresult = mycursor.fetchone()
if myresult is not None:
lcd.lcd_display_string("C/K ist in DB ",1)
lcd.lcd_display_string("vorhanden ",2)
GPIO.output(LED_YELLOW, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_RED, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_RED, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_RED, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_RED, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_RED, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_RED, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_RED, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_RED, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_RED, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_RED, GPIO.LOW)
print("Karte ist schon vorhanden.")
print("Nächste Karte.")
time.sleep(2)
lcd.lcd_display_string("OK, weitere C/K ",1)
lcd.lcd_display_string(" ",2)
else:
lcd.lcd_display_string("C/K wurde in DB",1)
lcd.lcd_display_string("eingetragen ",2)
GPIO.output(LED_YELLOW, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_YELLOW, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_YELLOW, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_YELLOW, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_YELLOW, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_YELLOW, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_YELLOW, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_YELLOW, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_YELLOW, GPIO.LOW)
time.sleep(0.2)
GPIO.output(LED_YELLOW, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(LED_YELLOW, GPIO.LOW)
time.sleep(0.2)
icd01 = cid
icd02 = "f"
icd03 = "n"
mycursor = mydb.cursor()
sql = "INSERT INTO cd (cd01, cd02, cd03) VALUES (%s, %s, %s)"
val = (icd01, icd02, icd03)
mycursor.execute(sql, val)
mydb.commit()
print (cid)
print (" wurde eingetragen")
print("Nächste Karte.")
time.sleep(2)
lcd.lcd_display_string("OK, weitere C/K ",1)
lcd.lcd_display_string(" ",2)
auch die Teile wo mitgeladen werden sollen ( lcddriver usw sind nicht mein problem )
in beiden habe ich "def " und " xxx ", was ich soweit verstanden habe
Kann ich alles von Programm 1 über nehmen und bei Programm 2 einfügen bis auf das was schon wäre ?