Commit c6a7c16e authored by matteo perini's avatar matteo perini

aggiunti led e servo

parent db29311c
......@@ -4,7 +4,7 @@ import RPi.GPIO as GPIO
#from mfrc522 import SimpleMFRC522
#import sqlite3
from termcolor import colored
from my_lib import registra_cliente, registra_prodotto, cerca_cliente_per_prodotto, scarica_prodotto, lista_clienti, scarica_cliente, lista_prodotti, cerca_cliente_per_tessera
from my_lib import registra_cliente, registra_prodotto, cerca_cliente_per_prodotto, scarica_prodotto, lista_clienti, cancella_cliente, lista_prodotti, cerca_cliente_per_tessera
#from my_lib import NFC
def mostra_menu():
......@@ -49,7 +49,7 @@ def mostra_menu():
input()
mostra_menu()
elif int(n) == 6:
scarica_cliente()
cancella_cliente()
input()
mostra_menu()
elif int(n) == 7:
......
from gpiozero import LED
from time import sleep
led = LED("BOARD40")
led1 = LED(13)
led2 = LED(19)
led3 = LED(26)
while True:
led.on()
led2.off()
led1.on()
sleep(0.1)
led1.off()#accendo il primo led
sleep(1)
sleep(0.1)
led.off()#accendo il primo led
led2.on()
sleep(1)
sleep(0.1)
led2.off()
sleep(0.1)
led3.on()
sleep(0.1)
led3.off()
sleep(0.1)
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522, MFRC522
from mfrc522 import SimpleMFRC522
import sqlite3
import time
from gpiozero import LED
#import RPi.GPIO as GPIO
#from mfrc522 import SimpleMFRC522
import spidev
class NFC():
def __init__(self, bus=0, device=0, spd=1000000):
self.reader = SimpleMFRC522()
self.close()
#self.bus = bus
self.boards = {}
self.bus = bus
self.device = device
self.spd = spd
def reinit(self):
self.reader.READER.spi = spidev.SpiDev()
self.reader.READER.spi.open(self.bus, self.device)
self.reader.READER.spi.max_speed_hz = self.spd
self.reader.READER.MFRC522_Init()
def close(self):
self.reader.READER.spi.close()
def addBoard(self, rid, pin):
self.rid = rid
self.boards[rid] = pin
def selectBoard(self, rid):
if not rid in self.boards:
print("readerid " + rid + " not found")
return False
for loop_id in self.boards:
GPIO.output(self.boards[loop_id], loop_id == rid)
return True
def read(self, rid):
if not self.selectBoard(rid):
return None
self.reinit()
cid, val = self.reader.read_no_block()
self.close()
return cid, val
def readd(self):
if not self.selectBoard(self.rid):
return None
self.reinit()
cid, val = self.reader.read_no_block()
self.close()
return cid, val
def write(self, rid, value):
if not self.selectBoard(rid):
return False
self.reinit()
self.reader.write_no_block(value)
self.close()
return True
# if __name__ == "__main__":
# nfc = NFC()
# nfc.addBoard("reader1",5)
# nfc.addBoard("reader2",6)
# data = nfc.read("reader1")
# nfc.write("reader2",data)
def cerca_cliente_per_prodotto():
reader = SimpleMFRC522()
con = sqlite3.connect("mydb.db")
cur = con.cursor()
def leggi_prodotto():
try:
print("Ciao, avvicina il prodotto al ricevitore!")
id,text = reader.read()
print(id)
#print(text)
except:
pass
finally:
GPIO.cleanup()
return int(id)
n = leggi_prodotto()
database = cur.execute('SELECT n_cliente FROM prodotti WHERE n_rfid=?;',(n,))
yy = database.fetchall()
if len(yy) > 0:
for row in yy:
xx=row[0]
print(xx)
cliente = cur.execute('SELECT * FROM persone WHERE n_card=?;',(xx,))
#for i in cliente:
print(cliente.fetchone())
else:
print("Prodotto non associato a nessun cliente")
class PatchedSimpleMFRC522(SimpleMFRC522):
def __init__(self, **kwargs):
self.READER = MFRC522(**kwargs)
def leggi_rfid(testo,pin):
if pin==5:
lettore = LED(5)
......@@ -130,32 +20,41 @@ def leggi_rfid(testo,pin):
return 1
reader = SimpleMFRC522()
#reader = PatchedSimpleMFRC522(bus=1, pin_rst=pin)
print()
try:
print(testo)
#id,text = reader.read()
data = None
#led_verde.on()
while data == None:
id,data = reader.read()
#id, data = nfc.read()
sleep(0.2)
#print(id)
#print(text)
time.sleep(0.2)
except:
pass
finally:
GPIO.cleanup()
return int(id)
def cerca_cliente_per_tessera():
return int(id),data
def cerca_cliente_per_prodotto():
reader = SimpleMFRC522()
con = sqlite3.connect("mydb.db")
cur = con.cursor()
n = leggi_rfid("Ciao, avvicina il tag del cliente al ricevitore!",5)
n,d = leggi_rfid("Ciao, avvicina il prodotto al ricevitore!",6)
database = cur.execute('SELECT n_cliente FROM prodotti WHERE n_rfid=?;',(n,))
yy = database.fetchall()
if len(yy) > 0:
for row in yy:
xx=row[0]
print(xx)
cliente = cur.execute('SELECT * FROM persone WHERE n_card=?;',(xx,))
print(cliente.fetchone())
else:
print("Prodotto non associato a nessun cliente")
def cerca_cliente_per_tessera():
con = sqlite3.connect("mydb.db")
cur = con.cursor()
n,data = leggi_rfid("Ciao, avvicina la tessera del cliente al ricevitore!",6)
database = cur.execute('SELECT * FROM persone WHERE n_card=?;',(n,))
yy = database.fetchall()
if len(yy) > 0:
......@@ -163,11 +62,10 @@ def cerca_cliente_per_tessera():
xx=row[0]
print(row)
print("La tessera numero ",row[3]," è intestata a : ",row[1], " ", row[2] )
#cliente = cur.execute('SELECT * FROM persone WHERE n_card=?;',(xx,))
#for i in cliente:
#print(cliente.fetchone())
return n
else:
print("Tag non associato a nessun cliente")
print("Tessera non associata a nessun cliente")
return None
def registra_prodotto():
reader = SimpleMFRC522()
......@@ -179,108 +77,43 @@ def registra_prodotto():
n_rfid TEXT NOT NULL UNIQUE,
n_cliente TEXT NOT NULL);""")
def leggi_cliente():
try:
print("Ciao, avvicina il tag del cliente al ricevitore!")
id,text = reader.read()
print(id)
#print(text)
except:
pass
finally:
GPIO.cleanup()
return int(id)
def leggi_prodotto():
try:
print("Ciao, avvicina il prodotto al ricevitore!")
id,text = reader.read()
print(id)
#print(text)
except:
pass
finally:
GPIO.cleanup()
return int(id)
#n = input("Quale e il tuo nome?")
#c = input("Quale e il tuo cognome?")
codice_cliente = leggi_cliente()
codice_cliente = cerca_cliente_per_tessera()
if codice_cliente != None:
time.sleep(2)
codice_prodotto = leggi_prodotto()
codice_prodotto, d = leggi_rfid("Ciao, avvicina il prodotto al ricevitore!",6)
try:
cur.execute("INSERT INTO prodotti(n_rfid, n_cliente) VALUES(?, ?)",(codice_prodotto,codice_cliente))
#print("ciao")
print("Ciao ", codice_cliente , " abbiamo registrato il prodotto numero : ", codice_prodotto)
print("Il prodotto numero : ", codice_prodotto, " è stato attribuito al cliente : ", codice_cliente)
con.commit()
cur.close()
except:
print("Codice non corretto")
print("Codice prodotto non corretto o prodotto già registrato")
else:
print("Registra il cliente prima di riprovare.")
def scarica_prodotto():
#reader = SimpleMFRC522()
con = sqlite3.connect("mydb.db")
cur = con.cursor()
#cur.execute("""CREATE TABLE IF NOT EXISTS prodotti (
#id INTEGER PRIMARY KEY,
#n_rfid TEXT NOT NULL UNIQUE,
#n_cliente TEXT NOT NULL);""")
# def leggi_cliente():
# try:
# print("Ciao, avvicina il tag del cliente al ricevitore!")
# id,text = reader.read()
# print(id)
# #print(text)
# except:
# pass
# finally:
# GPIO.cleanup()
# return int(id)
def leggi_prodotto():
try:
print("Ciao, avvicina il prodotto al ricevitore!")
id,text = reader.read()
print(id)
#print(text)
except:
pass
finally:
GPIO.cleanup()
return int(id)
#n = input("Quale e il tuo nome?")
#c = input("Quale e il tuo cognome?")
#codice_cliente = leggi_cliente()
#time.sleep(2)
codice_prodotto = leggi_rfid("Ciao, avvicina il prodotto al ricevitore!",6)
codice_prodotto = leggi_rfid("Ciao, avvicina il prodotto al ricevitore!",5)
try:
cur.execute("DELETE FROM prodotti WHERE n_rfid=?;",(codice_prodotto,))
print("Il prodotto col codice : ", codice_prodotto, " è stato correttamente smaltito.")
#print("Ciao ", codice_cliente , " abbiamo registrato il prodotto numero : ", codice_prodotto)
con.commit()
cur.close()
except:
print("Codice non corretto")
def scarica_cliente():
def cancella_cliente():
reader = SimpleMFRC522()
con = sqlite3.connect("mydb.db")
cur = con.cursor()
#cur.execute("""CREATE TABLE IF NOT EXISTS prodotti (
#id INTEGER PRIMARY KEY,
#n_rfid TEXT NOT NULL UNIQUE,
#n_cliente TEXT NOT NULL);""")
def leggi_cliente():
try:
print("Ciao, avvicina il tag del cliente al ricevitore!")
......
from gpiozero import Servo
from gpiozero import AngularServo
from time import sleep
s = Servo(4)
s = AngularServo(4, min_angle=-90, max_angle=0)
while True:
s.min()
sleep(2)
s.mid()
sleep(2)
s.max()
sleep(2)
s.angle = 0
sleep(3)
s.angle = -90
sleep(1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment