Hallo Leute,
ich habe bei einem Programm, das zu einer Art RFID-Musikbox werden soll, am Ende mit einer try-Schleife ein Problem.
Der Code:
Python: main.py
import buzzer
import time
import random
import RPi.GPIO as gpio
import sys
from mfrc522 import SimpleMFRC522
gpio.setwarnings(False)
reader = SimpleMFRC522()
def ton(x, y):
buzzer.tone(x, y)
def login():
x = 1000
l=x-700
while x > l:
ton(x, 0.1)
x=x-100
time.sleep(0.05)
e = 2
while e > 0:
ton(500, 0.1)
time.sleep(0.2)
e= e-1
allowed = 0
print("Die Karte/Den Chip scannen lassen.")
try:
id, text = reader.read()
print("Deine ID: ", id)
f = open(".allowed.txt", "r")
f1 = f.readlines()
for e in f1:
with open (".allowed.txt", "r") as myfile:
data = myfile.read().splitlines()
for i in data:
if int(i) == id:
allowed = 1
if allowed == 1:
print("Authentifizierung erfolgreich")
login()
print("1 = Neue Karte hinzufuegen")
# print("2 = Alte Karte loeschen")
action = int(input("Was willst du tun? "))
# if action == 2:
# print("Zu loeschende Karte scannen.")
# try:
# id, text = reader.read()
# print("Zu loeschende ID: ", id)
if action == 1:
print("Zu hinzufuegende Karte scannen.")
try:
id, text = reader.read()
print("Zu hinzufuegende ID: ", id)
f = open(".allowed.txt", "a+")
f.write(id + "/n")
f.close()
print(id, " wurde erfolgreich hinzugefuegt.")
finally:
buzzer.end()
gpio.cleanup()
Alles anzeigen
Als Error kommt mir:
File "rfid_musik.py", line 64
finally:
^
IndentationError: unexpected unindent\
Im Voraus schonmal Danke fuer Hilfe.
PS: Ich verwende eine Englische Tastatur, deshalb keine Umlaute.