Initial commit

This commit is contained in:
Martin Bauer
2021-10-27 16:40:18 +02:00
commit 6a5d4c463c
20 changed files with 155393 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
#include <Arduino.h>
#include "rc522.h"
#include "SPI.h"
#include <MFRC522.h>
#include "LedControl.h"
#include "rotary_encoder.h"
MFRC522 rfid(5); // Instance of the class
MFRC522::MIFARE_Key key;
LedStrip led(144, 13);
void tag_handler(uint8_t *sn)
{
// serial number is always 5 bytes long
if (sn != nullptr)
{
Serial.printf("Tag: %#x %#x %#x %#x %#x\n",
sn[0], sn[1], sn[2], sn[3], sn[4]);
if (sn[4] == 0x30)
{
Serial.println("Fuchs");
////////////////////////////////////////////////////////////////////////////////////led.setAll(0, 0, 254, 0);
led.setRange(led.numLeds() - 40, led.numLeds(), 0, 0, 243, 0);
}
if (sn[4] == 0xf0)
{
Serial.println("Eule");
//led.setAll(0, 0, 0, 254);
led.setRange(led.numLeds() - 40, led.numLeds(), 0, 0, 0, 254);
}
}
else
{
led.clear();
Serial.println("Nichts");
}
led.transmit();
}
QueueHandle_t event_queue;
rotary_encoder_info_t info;
void setup()
{
Serial.begin(115200);
led.begin();
digitalWrite(5, 1);
const rc522_start_args_t start_args = {
19, // MISO
18, // MOSI
22, // SCK
23, // SDA
VSPI_HOST,
&tag_handler,
125, // scan_interval_ms
8 * 1024, // stacksize
4 // task priority
};
rc522_start(start_args);
ESP_ERROR_CHECK(gpio_install_isr_service(0));
ESP_ERROR_CHECK(rotary_encoder_init(&info, GPIO_NUM_12, GPIO_NUM_14));
ESP_ERROR_CHECK(rotary_encoder_enable_half_steps(&info, false));
event_queue = rotary_encoder_create_queue();
ESP_ERROR_CHECK(rotary_encoder_set_queue(&info, event_queue));
pinMode (2, OUTPUT);
digitalWrite(2, HIGH);
}
void loop()
{
/*
rotary_encoder_event_t event = {0};
if (xQueueReceive(event_queue, &event, 1000 / portTICK_PERIOD_MS) == pdTRUE)
{
Serial.printf("Event: position %d, direction %s\n", event.state.position,
event.state.direction ? (event.state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW" : "CCW") : "NOT_SET");
}
*/
Serial.println(touchRead(15)); // get value of Touch 0 pin = GPIO 4
delay(500);
//digitalWrite(2, HIGH);
}

View File

@@ -0,0 +1,64 @@
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 5 // Configurable, see typical pin layout above
#define SS_PIN 23 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
//*****************************************************************************************//
void setup() {
Serial.begin(115200);
SPI.begin(22, 19, 18, 23); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void PrintHex(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
//*****************************************************************************************//
void loop() {
// Look for new cards
if ( !mfrc522.PICC_IsNewCardPresent()) {
return;
}
if ( !mfrc522.PICC_ReadCardSerial()) {
return;
}
//mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card
Serial.print("NewCard");
PrintHex(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println("");
// Check if Card was removed
bool cardRemoved = false;
int counter = 0;
bool current, previous;
previous = !mfrc522.PICC_IsNewCardPresent();
while(!cardRemoved){
current =!mfrc522.PICC_IsNewCardPresent();
if (current && previous) counter++;
previous = current;
cardRemoved = (counter>2);
delay(50);
}
Serial.println("Card was removed");
delay(500); //change value if you want to read cards faster
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}