commit b89e7087569d3ed0075d3fe1636dd1e09dacfc35 Author: Emil Miler Date: Wed Dec 13 17:30:14 2023 +0100 Commit local files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66fc7a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.pio/ diff --git a/makefile b/makefile new file mode 100644 index 0000000..b57208c --- /dev/null +++ b/makefile @@ -0,0 +1,18 @@ +PROJECT_DIR = $(CURDIR) +PLATFORMIO_BIN = /bin/pio + +all: build upload + +build: + $(PLATFORMIO_BIN) run -d $(PROJECT_DIR) + +upload: + $(PLATFORMIO_BIN) run -d $(PROJECT_DIR) -t upload + +clean: + $(PLATFORMIO_BIN) run -d $(PROJECT_DIR) -t clean + +monitor: + $(PLATFORMIO_BIN) device monitor + +.PHONY: all build upload clean monitor diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..4e17fac --- /dev/null +++ b/platformio.ini @@ -0,0 +1,10 @@ +[env:uno] +platform = atmelavr +board = uno +framework = arduino +upload_port = /dev/ttyUSB0 +monitor_speed = 9600 + +lib_deps = + SPI + miguelbalboa/MFRC522@^1.4.10 diff --git a/src/main.ino b/src/main.ino new file mode 100644 index 0000000..235a817 --- /dev/null +++ b/src/main.ino @@ -0,0 +1,35 @@ +#include +#include + +#define SS_PIN 10 +#define RST_PIN 5 +#define LED_PIN_Y 3 +#define LED_PIN_N 2 +const byte uid[4] = {0xF9, 0x7E, 0x9D, 0x2B}; + +MFRC522 rfid(SS_PIN, RST_PIN); + +void setup() { + SPI.begin(); + rfid.PCD_Init(); + pinMode(LED_PIN_Y, OUTPUT); + pinMode(LED_PIN_N, OUTPUT); +} + +void loop() { + if (rfid.PICC_IsNewCardPresent()) { + if (rfid.PICC_ReadCardSerial()) { + for (int i = 0; i < rfid.uid.size; i++) { + if (rfid.uid.uidByte[i] == uid[i]) { + digitalWrite(LED_PIN_Y, HIGH); + delay(500); + digitalWrite(LED_PIN_Y, LOW); + } else { + digitalWrite(LED_PIN_N, HIGH); + delay(500); + digitalWrite(LED_PIN_N, LOW); + } + } + } + } +}