Created
August 2, 2023 10:34
-
-
Save ahmedeshaan/4c9f7a6ee9e6a79394418d9109d2ac98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mfrc522 import MFRC522 | |
from utime import sleep | |
from machine import Pin,I2C | |
from pico_i2c_lcd import I2cLcd | |
red = [0, "mather"] | |
pink = [0, "shlomit"] | |
blu = [0, "yoval"] | |
yellow = [0, "magen"] | |
# CONSTANTS | |
KEY_UP = const(0) | |
KEY_DOWN = const(1) | |
keys = [['1', '2', '3', 'add'], ['4', '5', '6', 'sub'], ['del', '0', 'clear', 'trans'], ['7', '8', '9', 'set']] | |
# Pin names for Pico | |
rows = [16, 17, 19, 18] | |
cols = [20, 21, 22, 26] | |
# set pins for rows as outputs | |
row_pins = [Pin(pin_name, mode=Pin.OUT) for pin_name in rows] | |
# set pins for cols as inputs | |
col_pins = [Pin(pin_name, mode=Pin.IN, pull=Pin.PULL_DOWN) for pin_name in cols] | |
def init(): | |
for row_pin in row_pins: | |
row_pin.low() | |
def scan(row, col): | |
"""Scan the keypad""" | |
# Set the current column to high | |
row_pins[row].high() | |
key = None | |
# Check for keypressed events | |
if col_pins[col].value() == KEY_DOWN: | |
key = KEY_DOWN | |
if col_pins[col].value() == KEY_UP: | |
key = KEY_UP | |
row_pins[row].low() | |
# Return the key state | |
return key | |
def dig(): | |
print("Starting") | |
# Set all the columns to low | |
init() | |
cunt = 0 | |
while True: | |
for row in range(4): | |
for col in range(4): | |
key = scan(row, col) | |
if key == KEY_DOWN: | |
print("Key Pressed:", keys[row][col]) | |
sleep(0.3) | |
cunt = cunt + 1 | |
return keys[row][col] | |
def shamen(card): | |
global red | |
global pink | |
global blu | |
global yellow | |
if card == '510d0b0c': | |
card = red | |
if card == "512c080c": | |
card = pink | |
if card == "514a230c": | |
card = blu | |
if card == "61570a0c": | |
card = yellow | |
comb = "" | |
x = "" | |
mlcd("{}s' money \n {}$".format(card[1], card[0])) | |
print(card) | |
x = dig() | |
while len(x) > 1: | |
mlcd("Start with \n a number") | |
x = dig() | |
while len(x) < 2 or x == "del" or x == "clear": | |
if len(x)< 2: | |
comb = comb + x | |
if x == "del": | |
comb = comb[0:-1] | |
if x == "clear": | |
comb = "" | |
mlcd(comb) | |
x = dig() | |
print(comb) | |
comb = int(comb) | |
if x == "add": | |
card[0] = card[0] + comb | |
mlcd("new balance is\n {}$".format(card[0])) | |
elif x == "sub": | |
card[0] = card[0] - comb | |
mlcd("new balance is\n {}$".format(card[0])) | |
elif x == "set": | |
card[0] = comb | |
mlcd("new balance is\n {}$".format(card[0])) | |
elif x == "trans": | |
card2 = frfid() | |
if card2 == '510d0b0c': | |
card2 = red | |
if card2 == "512c080c": | |
card2 = pink | |
if card2 == "514a230c": | |
card2 = blu | |
if card2 == "61570a0c": | |
card2 = yellow | |
card[0] = card[0] - comb | |
card2[0] = card2[0] + comb | |
mlcd("{}:{}\n{}:{}".format(card[1], card[0], card2[1], card2[0])) | |
def mlcd(x): | |
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000) | |
I2C_ADDR = i2c.scan()[0] | |
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16) | |
lcd.clear() | |
print(I2C_ADDR) | |
lcd.blink_cursor_on() | |
lcd.putstr(x) | |
def uidToString(uid): | |
mystring = "" | |
for i in uid: | |
mystring = "%02X" % i + mystring | |
return mystring | |
def frfid(): | |
rc522 = MFRC522(spi_id=1,sck=14,miso=8,mosi=11,cs=9,rst=3) | |
print("") | |
print("Place the card") | |
print("") | |
mlcd("Place a card wuw") | |
while True: | |
(stat, tag_type) = rc522.request(rc522.REQALL) | |
global rfid_data | |
if stat == rc522.OK: | |
(status, raw_uid) = rc522.SelectTagSN() | |
if stat == rc522.OK: | |
rfid_data = "{:02x}{:02x}{:02x}{:02x}".format(raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3]) | |
print("Card detected! UID: {}".format(rfid_data)) | |
return rfid_data | |
sleep(0.5) | |
while True: | |
shamen(frfid()) | |
sleep(1.5) | |
print(red, pink, blu, yellow) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment