Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a34467ccb | ||
|
|
535ecc84f2 | ||
|
|
8f84e04f0b | ||
|
|
f7572e82ea | ||
|
|
a3cfa44d82 | ||
|
|
3eb119f6a2 | ||
|
|
f587dafb15 | ||
|
|
8b1940331e |
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Architektoniczne perełki Lublina - Master
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Addresses:
|
||||||
|
- Slave 1 -> `0x08`
|
||||||
|
- Slave 2 -> `0x09`
|
||||||
|
- Slave 3 -> `0x0A`
|
||||||
|
- Slave 4 -> `0x0B`
|
||||||
|
- Slave 5 -> `0x0C`
|
||||||
|
|
||||||
|
# LED config
|
||||||
|
|
||||||
|
Led Type: WS2812B
|
||||||
|
Pin: 5
|
||||||
|
Count: 29
|
||||||
|
Color Order: GRB
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
// I2C pins
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
// I2C slave addresses
|
||||||
|
#define SLAVE_ONE_ADDRESS 0x08
|
||||||
|
#define SLAVE_TWO_ADDRESS 0x09
|
||||||
|
#define SLAVE_THREE_ADDRESS 0x0A
|
||||||
|
#define SLAVE_FOUR_ADDRESS 0x0B
|
||||||
|
#define SLAVE_FIVE_ADDRESS 0x0C
|
||||||
|
|
||||||
|
// Buttons pins
|
||||||
|
#define PLAYER_ONE_BUTTON_PIN 32
|
||||||
|
#define PLAYER_ONE_A_BUTTON_PIN 33
|
||||||
|
#define PLAYER_ONE_B_BUTTON_PIN 25
|
||||||
|
#define PLAYER_ONE_C_BUTTON_PIN 26
|
||||||
|
|
||||||
|
#define PLAYER_TWO_BUTTON_PIN 27
|
||||||
|
#define PLAYER_TWO_A_BUTTON_PIN 14
|
||||||
|
#define PLAYER_TWO_B_BUTTON_PIN 12
|
||||||
|
#define PLAYER_TWO_C_BUTTON_PIN 13
|
||||||
|
|
||||||
|
// LEDs pins and configuration
|
||||||
|
#define LED_DATA_PIN 5
|
||||||
|
#define LED_COUNT 29
|
||||||
|
#define BRIGHTNESS 64
|
||||||
|
#define LED_TYPE WS2812B
|
||||||
|
#define COLOR_ORDER GRB
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into the executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a separate directory
|
||||||
|
("lib/your_library_name/[Code]").
|
||||||
|
|
||||||
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
Example contents of `src/main.c` using Foo and Bar:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries by scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32dev]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32dev
|
||||||
|
framework = arduino
|
||||||
|
monitor_speed = 115200
|
||||||
|
|
||||||
|
lib_deps = fastled/FastLED@^3.10.3
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <FastLED.h>
|
||||||
|
#include <Conts.h>
|
||||||
|
|
||||||
|
CRGB leds[LED_COUNT];
|
||||||
|
|
||||||
|
const CRGB SUCCESS_COLOR = CRGB::Green;
|
||||||
|
const CRGB ERROR_COLOR = CRGB::Red;
|
||||||
|
|
||||||
|
void testLedStrip();
|
||||||
|
|
||||||
|
void initializeButtonInterrupts();
|
||||||
|
|
||||||
|
void playerOneButtonPressedInterrupt();
|
||||||
|
void playerOneAButtonPressedInterrupt();
|
||||||
|
void playerOneBButtonPressedInterrupt();
|
||||||
|
void playerOneCButtonPressedInterrupt();
|
||||||
|
|
||||||
|
void playerTwoButtonPressedInterrupt();
|
||||||
|
void playerTwoAButtonPressedInterrupt();
|
||||||
|
void playerTwoBButtonPressedInterrupt();
|
||||||
|
void playerTwoCButtonPressedInterrupt();
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN);
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
// Initialize FastLED with the specified LED type, data pin, and LED count
|
||||||
|
FastLED.addLeds<LED_TYPE, LED_DATA_PIN, COLOR_ORDER>(leds, LED_COUNT).setCorrection(TypicalLEDStrip);
|
||||||
|
FastLED.setBrightness(BRIGHTNESS);
|
||||||
|
|
||||||
|
// Initialize button interrupts
|
||||||
|
initializeButtonInterrupts();
|
||||||
|
|
||||||
|
testLedStrip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
// TODO: Implement the main loop logic for I2C communication with slave devices
|
||||||
|
// TODO: Implement the logic to control the LED strip based on the received data from slave devices
|
||||||
|
// TODO: Send informations to PC via Serial communication, needs to be implemented based on the previous code snippets.
|
||||||
|
}
|
||||||
|
|
||||||
|
void testLedStrip()
|
||||||
|
{
|
||||||
|
// Test the LED strip by turning on each LED one by one
|
||||||
|
for (int i = 0; i < LED_COUNT; i++)
|
||||||
|
{
|
||||||
|
leds[i] = SUCCESS_COLOR; // Set the LED to green
|
||||||
|
FastLED.show();
|
||||||
|
delay(100); // Wait for a short duration
|
||||||
|
leds[i] = CRGB::Black; // Turn off the LED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void initializeButtonInterrupts()
|
||||||
|
{
|
||||||
|
pinMode(PLAYER_ONE_BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(PLAYER_ONE_A_BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(PLAYER_ONE_B_BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(PLAYER_ONE_C_BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
|
pinMode(PLAYER_TWO_BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(PLAYER_TWO_A_BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(PLAYER_TWO_B_BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(PLAYER_TWO_C_BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_BUTTON_PIN), playerOneButtonPressedInterrupt, FALLING);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_A_BUTTON_PIN), playerOneAButtonPressedInterrupt, FALLING);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_B_BUTTON_PIN), playerOneBButtonPressedInterrupt, FALLING);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_C_BUTTON_PIN), playerOneCButtonPressedInterrupt, FALLING);
|
||||||
|
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_BUTTON_PIN), playerTwoButtonPressedInterrupt, FALLING);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_A_BUTTON_PIN), playerTwoAButtonPressedInterrupt, FALLING);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_B_BUTTON_PIN), playerTwoBButtonPressedInterrupt, FALLING);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_C_BUTTON_PIN), playerTwoCButtonPressedInterrupt, FALLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void playerOneButtonPressedInterrupt()
|
||||||
|
{
|
||||||
|
// Handle Player One button press interrupt
|
||||||
|
Serial.println("Player One button pressed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void playerOneAButtonPressedInterrupt()
|
||||||
|
{
|
||||||
|
// Handle Player One A button press interrupt
|
||||||
|
Serial.println("Player One A button pressed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void playerOneBButtonPressedInterrupt()
|
||||||
|
{
|
||||||
|
// Handle Player One B button press interrupt
|
||||||
|
Serial.println("Player One B button pressed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void playerOneCButtonPressedInterrupt()
|
||||||
|
{
|
||||||
|
// Handle Player One C button press interrupt
|
||||||
|
Serial.println("Player One C button pressed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void playerTwoButtonPressedInterrupt()
|
||||||
|
{
|
||||||
|
// Handle Player Two button press interrupt
|
||||||
|
Serial.println("Player Two button pressed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void playerTwoAButtonPressedInterrupt()
|
||||||
|
{
|
||||||
|
// Handle Player Two A button press interrupt
|
||||||
|
Serial.println("Player Two A button pressed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void playerTwoBButtonPressedInterrupt()
|
||||||
|
{
|
||||||
|
// Handle Player Two B button press interrupt
|
||||||
|
Serial.println("Player Two B button pressed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void playerTwoCButtonPressedInterrupt()
|
||||||
|
{
|
||||||
|
// Handle Player Two C button press interrupt
|
||||||
|
Serial.println("Player Two C button pressed");
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "APL_Master"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "APL_Slave_1",
|
||||||
|
"path": "APL_Slave_1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "APL_Slave_2",
|
||||||
|
"path": "APL_Slave_2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "APL_Slave_3",
|
||||||
|
"path": "APL_Slave_3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "APL_Slave_4",
|
||||||
|
"path": "APL_Slave_4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "APL_Slave_5",
|
||||||
|
"path": "APL_Slave_5"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Architektoniczne perełki Lublina - Slave 1
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Address: 0x08
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into the executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a separate directory
|
||||||
|
("lib/your_library_name/[Code]").
|
||||||
|
|
||||||
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
Example contents of `src/main.c` using Foo and Bar:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries by scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32dev]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32dev
|
||||||
|
framework = arduino
|
||||||
|
|
||||||
|
monitor_speed = 115200
|
||||||
|
|
||||||
|
lib_deps = miguelbalboa/MFRC522@^1.4.12
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <MFRC522.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
// I2C Pin definitions for ESP32
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ADDRESS 0x08
|
||||||
|
|
||||||
|
// Count of MFRC522 readers connected to the ESP32
|
||||||
|
#define READER_COUNT 6
|
||||||
|
|
||||||
|
// SPI pins for MFRC522 readers
|
||||||
|
#define MISO_PIN 19
|
||||||
|
#define MOSI_PIN 23
|
||||||
|
#define SCK_PIN 18
|
||||||
|
|
||||||
|
// Dedicated Slave Select (SS) pins for each reader
|
||||||
|
#define SS_ONE_PIN 14
|
||||||
|
#define SS_TWO_PIN 32
|
||||||
|
#define SS_THREE_PIN 4
|
||||||
|
#define SS_FOUR_PIN 33
|
||||||
|
#define SS_FIVE_PIN 25
|
||||||
|
#define SS_SIX_PIN 26
|
||||||
|
|
||||||
|
// Dedicated reset pins for each reader
|
||||||
|
#define RST_ONE_PIN 27
|
||||||
|
#define RST_TWO_PIN 13
|
||||||
|
#define RST_THREE_PIN 2
|
||||||
|
#define RST_FOUR_PIN 15
|
||||||
|
#define RST_FIVE_PIN 12
|
||||||
|
#define RST_SIX_PIN 17
|
||||||
|
|
||||||
|
// Definitions for card statuses
|
||||||
|
#define CARD_NOT_DETECTED 0
|
||||||
|
#define CARD_OK 1
|
||||||
|
#define CARD_WRONG 2
|
||||||
|
|
||||||
|
// Arrays for SS and RST pins for each reader
|
||||||
|
const byte SS_PINS[READER_COUNT] = {SS_ONE_PIN, SS_TWO_PIN, SS_THREE_PIN, SS_FOUR_PIN, SS_FIVE_PIN, SS_SIX_PIN};
|
||||||
|
const byte RST_PINS[READER_COUNT] = {RST_ONE_PIN, RST_TWO_PIN, RST_THREE_PIN, RST_FOUR_PIN, RST_FIVE_PIN, RST_SIX_PIN};
|
||||||
|
|
||||||
|
// Addresses for each reader (for I2C communication)
|
||||||
|
const byte READER_ADDRESSES[READER_COUNT] = {
|
||||||
|
0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
|
||||||
|
|
||||||
|
// List of correct UIDs for each reader (4 bytes each)
|
||||||
|
const byte CORRECT_UIDS[READER_COUNT][4] = {
|
||||||
|
{0xDE, 0xAD, 0xBE, 0xEF}, // Reader 1
|
||||||
|
{0xCA, 0xFE, 0xBA, 0xBE}, // Reader 2
|
||||||
|
{0xFA, 0xCE, 0xB0, 0x0C}, // Reader 3
|
||||||
|
{0xBA, 0xAD, 0xF0, 0x0D}, // Reader 4
|
||||||
|
{0xFE, 0xED, 0xFA, 0xCE}, // Reader 5
|
||||||
|
{0xC0, 0xFF, 0xEE, 0x00} // Reader 6
|
||||||
|
};
|
||||||
|
|
||||||
|
// Reader statuses: 0 - card not detected, 1 - OK, 2 - wrong card
|
||||||
|
volatile byte readerStatus[READER_COUNT] = {
|
||||||
|
CARD_NOT_DETECTED,
|
||||||
|
CARD_NOT_DETECTED,
|
||||||
|
CARD_NOT_DETECTED,
|
||||||
|
CARD_NOT_DETECTED,
|
||||||
|
CARD_NOT_DETECTED,
|
||||||
|
CARD_NOT_DETECTED};
|
||||||
|
|
||||||
|
MFRC522 mfrc522[READER_COUNT];
|
||||||
|
|
||||||
|
void requestEvent();
|
||||||
|
void initializeReaders();
|
||||||
|
bool compareUID(byte *readUID, const byte *correctUID, byte size);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
delay(1000); // Daj czas na zainicjalizowanie portu USB w komputerze
|
||||||
|
Serial.println("Starting ESP32...");
|
||||||
|
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS);
|
||||||
|
Wire.onRequest(requestEvent);
|
||||||
|
|
||||||
|
SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, -1);
|
||||||
|
Serial.println("SPI initialized successfully.");
|
||||||
|
|
||||||
|
// SPI.setFrequency(1000000); // Set 1 MHz for whole SPI bus, but MFRC522 can handle up to 10 MHz. Adjust as needed.
|
||||||
|
// Serial.println("SPI set to 1 MHz");
|
||||||
|
|
||||||
|
initializeReaders();
|
||||||
|
Serial.println("System initialized successfully. Waiting for card detection...");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
for (byte i = 0; i < READER_COUNT; i++)
|
||||||
|
{
|
||||||
|
// Check if a new card is present and read its UID
|
||||||
|
if (!mfrc522[i].PICC_IsNewCardPresent() || !mfrc522[i].PICC_ReadCardSerial())
|
||||||
|
{
|
||||||
|
readerStatus[i] = CARD_NOT_DETECTED; // Reset reader status if no card is present
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Card is detected, print its UID
|
||||||
|
Serial.print("Reader ");
|
||||||
|
Serial.print(i + 1);
|
||||||
|
Serial.print(" detected card with UID: ");
|
||||||
|
for (byte j = 0; j < mfrc522[i].uid.size; j++)
|
||||||
|
{
|
||||||
|
Serial.print(mfrc522[i].uid.uidByte[j], HEX);
|
||||||
|
if (j < mfrc522[i].uid.size - 1)
|
||||||
|
{
|
||||||
|
Serial.print(":");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
// Check if the read UID matches the correct UID for this reader
|
||||||
|
if (compareUID(mfrc522[i].uid.uidByte, CORRECT_UIDS[i], mfrc522[i].uid.size))
|
||||||
|
{
|
||||||
|
readerStatus[i] = CARD_OK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
readerStatus[i] = CARD_WRONG;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close communication with the card and stop encryption on PCD
|
||||||
|
mfrc522[i].PICC_HaltA();
|
||||||
|
mfrc522[i].PCD_StopCrypto1();
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void initializeReaders()
|
||||||
|
{
|
||||||
|
for (byte i = 0; i < READER_COUNT; i++)
|
||||||
|
{
|
||||||
|
pinMode(SS_PINS[i], OUTPUT);
|
||||||
|
digitalWrite(SS_PINS[i], HIGH);
|
||||||
|
|
||||||
|
// Usage of the constructor with both SS and RST pins
|
||||||
|
mfrc522[i].PCD_Init(SS_PINS[i], RST_PINS[i]);
|
||||||
|
|
||||||
|
Serial.print("Reader ");
|
||||||
|
Serial.print(i + 1);
|
||||||
|
Serial.print(" firmware version: ");
|
||||||
|
mfrc522[i].PCD_DumpVersionToSerial();
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool compareUID(byte *readUID, const byte *correctUID, byte size)
|
||||||
|
{
|
||||||
|
for (byte i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
if (readUID[i] != correctUID[i])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void requestEvent()
|
||||||
|
{
|
||||||
|
byte outputData[READER_COUNT];
|
||||||
|
|
||||||
|
for (byte i = 0; i < READER_COUNT; i++)
|
||||||
|
{
|
||||||
|
outputData[i] = READER_ADDRESSES[i] + readerStatus[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
Wire.write(outputData, READER_COUNT);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Architektoniczne perełki Lublina - Slave 2
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Address: 0x09
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into the executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a separate directory
|
||||||
|
("lib/your_library_name/[Code]").
|
||||||
|
|
||||||
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
Example contents of `src/main.c` using Foo and Bar:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries by scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32dev]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32dev
|
||||||
|
framework = arduino
|
||||||
|
|
||||||
|
monitor_speed = 115200
|
||||||
|
|
||||||
|
lib_deps = miguelbalboa/MFRC522@^1.4.12
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ADDRESS 0x09
|
||||||
|
|
||||||
|
void requestEvent();
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins
|
||||||
|
|
||||||
|
Wire.onRequest(requestEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void requestEvent()
|
||||||
|
{
|
||||||
|
// TODO: Send data to the master when requested
|
||||||
|
Serial.println("Master requested data from Slave.");
|
||||||
|
Wire.write("Hello from Slave!");
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Architektoniczne perełki Lublina - Slave 3
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Address: 0x0A
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into the executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a separate directory
|
||||||
|
("lib/your_library_name/[Code]").
|
||||||
|
|
||||||
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
Example contents of `src/main.c` using Foo and Bar:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries by scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32dev]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32dev
|
||||||
|
framework = arduino
|
||||||
|
|
||||||
|
monitor_speed = 115200
|
||||||
|
|
||||||
|
lib_deps = miguelbalboa/MFRC522@^1.4.12
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ADDRESS 0x0A
|
||||||
|
|
||||||
|
void requestEvent();
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins
|
||||||
|
|
||||||
|
Wire.onRequest(requestEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void requestEvent()
|
||||||
|
{
|
||||||
|
// TODO: Send data to the master when requested
|
||||||
|
Serial.println("Master requested data from Slave.");
|
||||||
|
Wire.write("Hello from Slave!");
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Architektoniczne perełki Lublina - Slave 4
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Address: 0x0B
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into the executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a separate directory
|
||||||
|
("lib/your_library_name/[Code]").
|
||||||
|
|
||||||
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
Example contents of `src/main.c` using Foo and Bar:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries by scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32dev]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32dev
|
||||||
|
framework = arduino
|
||||||
|
|
||||||
|
monitor_speed = 115200
|
||||||
|
|
||||||
|
lib_deps = miguelbalboa/MFRC522@^1.4.12
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ADDRESS 0x0B
|
||||||
|
|
||||||
|
void requestEvent();
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins
|
||||||
|
|
||||||
|
Wire.onRequest(requestEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void requestEvent()
|
||||||
|
{
|
||||||
|
// TODO: Send data to the master when requested
|
||||||
|
Serial.println("Master requested data from Slave.");
|
||||||
|
Wire.write("Hello from Slave!");
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Architektoniczne perełki Lublina - Slave 5
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Address: 0x0C
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into the executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a separate directory
|
||||||
|
("lib/your_library_name/[Code]").
|
||||||
|
|
||||||
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
Example contents of `src/main.c` using Foo and Bar:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries by scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32dev]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32dev
|
||||||
|
framework = arduino
|
||||||
|
|
||||||
|
monitor_speed = 115200
|
||||||
|
|
||||||
|
lib_deps = miguelbalboa/MFRC522@^1.4.12
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ADDRESS 0x0C
|
||||||
|
|
||||||
|
void requestEvent();
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins
|
||||||
|
|
||||||
|
Wire.onRequest(requestEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void requestEvent()
|
||||||
|
{
|
||||||
|
// TODO: Send data to the master when requested
|
||||||
|
Serial.println("Master requested data from Slave.");
|
||||||
|
Wire.write("Hello from Slave!");
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
Reference in New Issue
Block a user