#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <IRremote.h>
// --- DEFINICJE PINÓW ---
// TFT ILI9341
#define TFT_CS 6
#define TFT_DC 7
#define TFT_RST 8
#define TFT_MISO 13
#define TFT_MOSI 10
#define TFT_SCL 11
// MAX7219 LED MATRIX
#define MAX7219_CS 9
#define MAX7219_DIN 10 // MOSI (wspólny z TFT)
#define MAX7219_CLK 11 // SCK (wspólny z TFT)
#define MAX_DEVICES 4 // 4 moduły 8x8
// PRZYCISKI
#define BTN_LEFT 12
#define BTN_RIGHT 18
#define BTN_UP 14
#define BTN_DOWN 15
#define BTN_OK 16
// ODBIORNIK IR
#define IR_RECV_PIN 17
// --- OBIEKTY ---
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
MD_Parola matrix = MD_Parola(MD_MAX72XX::FC16_HW, MAX7219_CS, MAX_DEVICES);
IRrecv irrecv(IR_RECV_PIN);
decode_results results;
// Zmienne testowe
int testStep = 0;
unsigned long lastUpdate = 0;
int buttonPressed = 0;
void setup() {
Serial.begin(115200);
Serial.println("=== TEST DART COUNTER ===");
// Test 1: Inicjalizacja TFT
Serial.println("\n1. Test TFT ILI9341...");
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(50, 100);
tft.println("TFT OK!");
Serial.println(" TFT zainicjalizowany");
delay(1000);
// Test 2: Inicjalizacja Matrix
Serial.println("\n2. Test MAX7219 Matrix...");
matrix.begin();
matrix.setIntensity(5);
matrix.displayClear();
matrix.displayText("TEST", PA_CENTER, 100, 0, PA_PRINT, PA_NO_EFFECT);
Serial.println(" Matrix zainicjalizowany");
delay(1000);
// Test 3: Inicjalizacja przycisków
Serial.println("\n3. Konfiguracja przycisków...");
pinMode(BTN_LEFT, INPUT_PULLUP);
pinMode(BTN_RIGHT, INPUT_PULLUP);
pinMode(BTN_UP, INPUT_PULLUP);
pinMode(BTN_DOWN, INPUT_PULLUP);
pinMode(BTN_OK, INPUT_PULLUP);
Serial.println(" Przyciski skonfigurowane");
// Test 4: Inicjalizacja IR
Serial.println("\n4. Test odbiornika IR...");
irrecv.enableIRIn();
Serial.println(" IR włączony");
Serial.println("\n=== WSZYSTKIE MODUŁY GOTOWE ===");
Serial.println("Naciśnij przyciski lub użyj pilota IR");
// Wyświetl instrukcje na TFT
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.setTextSize(2);
tft.println("TEST MODULOW:");
tft.setTextSize(1);
tft.setCursor(10, 40);
tft.println("1. Nacisnij przyciski - zobaczysz na ekranie");
tft.setCursor(10, 60);
tft.println("2. Uzyj pilota IR - kod w Serial Monitor");
tft.setCursor(10, 80);
tft.println("3. Matrix pokazuje nacisniete przyciski");
// Rysuj prostokąty dla przycisków
tft.drawRect(10, 120, 60, 30, ILI9341_WHITE);
tft.setCursor(20, 130);
tft.println("LEFT");
tft.drawRect(80, 120, 60, 30, ILI9341_WHITE);
tft.setCursor(90, 130);
tft.println("RIGHT");
tft.drawRect(150, 120, 60, 30, ILI9341_WHITE);
tft.setCursor(165, 130);
tft.println("UP");
tft.drawRect(220, 120, 60, 30, ILI9341_WHITE);
tft.setCursor(230, 130);
tft.println("DOWN");
tft.drawRect(120, 170, 60, 30, ILI9341_WHITE);
tft.setCursor(135, 180);
tft.println("OK");
}
void loop() {
// Test przycisków
bool anyButtonPressed = false;
if (digitalRead(BTN_LEFT) == LOW) {
if (buttonPressed != 1) {
Serial.println("Przycisk LEFT");
tft.fillRect(10, 120, 60, 30, ILI9341_GREEN);
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(20, 130);
tft.println("LEFT");
tft.setTextColor(ILI9341_WHITE);
matrix.displayText("LEFT", PA_CENTER, 100, 0, PA_PRINT, PA_NO_EFFECT);
buttonPressed = 1;
}
anyButtonPressed = true;
}
if (digitalRead(BTN_RIGHT) == LOW) {
if (buttonPressed != 2) {
Serial.println("Przycisk RIGHT");
tft.fillRect(80, 120, 60, 30, ILI9341_GREEN);
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(90, 130);
tft.println("RIGHT");
tft.setTextColor(ILI9341_WHITE);
matrix.displayText("RIGHT", PA_CENTER, 100, 0, PA_PRINT, PA_NO_EFFECT);
buttonPressed = 2;
}
anyButtonPressed = true;
}
if (digitalRead(BTN_UP) == LOW) {
if (buttonPressed != 3) {
Serial.println("Przycisk UP");
tft.fillRect(150, 120, 60, 30, ILI9341_GREEN);
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(165, 130);
tft.println("UP");
tft.setTextColor(ILI9341_WHITE);
matrix.displayText("UP", PA_CENTER, 100, 0, PA_PRINT, PA_NO_EFFECT);
buttonPressed = 3;
}
anyButtonPressed = true;
}
if (digitalRead(BTN_DOWN) == LOW) {
if (buttonPressed != 4) {
Serial.println("Przycisk DOWN");
tft.fillRect(220, 120, 60, 30, ILI9341_GREEN);
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(230, 130);
tft.println("DOWN");
tft.setTextColor(ILI9341_WHITE);
matrix.displayText("DOWN", PA_CENTER, 100, 0, PA_PRINT, PA_NO_EFFECT);
buttonPressed = 4;
}
anyButtonPressed = true;
}
if (digitalRead(BTN_OK) == LOW) {
if (buttonPressed != 5) {
Serial.println("Przycisk OK");
tft.fillRect(120, 170, 60, 30, ILI9341_GREEN);
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(135, 180);
tft.println("OK");
tft.setTextColor(ILI9341_WHITE);
matrix.displayText("OK", PA_CENTER, 100, 0, PA_PRINT, PA_NO_EFFECT);
buttonPressed = 5;
}
anyButtonPressed = true;
}
// Resetuj kolory po puszczeniu przycisku
if (!anyButtonPressed && buttonPressed != 0) {
// Przywróć białe obramowania
tft.drawRect(10, 120, 60, 30, ILI9341_WHITE);
tft.fillRect(11, 121, 58, 28, ILI9341_BLACK);
tft.setCursor(20, 130);
tft.println("LEFT");
tft.drawRect(80, 120, 60, 30, ILI9341_WHITE);
tft.fillRect(81, 121, 58, 28, ILI9341_BLACK);
tft.setCursor(90, 130);
tft.println("RIGHT");
tft.drawRect(150, 120, 60, 30, ILI9341_WHITE);
tft.fillRect(151, 121, 58, 28, ILI9341_BLACK);
tft.setCursor(165, 130);
tft.println("UP");
tft.drawRect(220, 120, 60, 30, ILI9341_WHITE);
tft.fillRect(221, 121, 58, 28, ILI9341_BLACK);
tft.setCursor(230, 130);
tft.println("DOWN");
tft.drawRect(120, 170, 60, 30, ILI9341_WHITE);
tft.fillRect(121, 171, 58, 28, ILI9341_BLACK);
tft.setCursor(135, 180);
tft.println("OK");
buttonPressed = 0;
}
// Test IR
if (irrecv.decode(&results)) {
Serial.print("Kod IR: 0x");
Serial.println(results.value, HEX);
// Wyświetl kod na TFT
tft.fillRect(10, 220, 300, 20, ILI9341_BLACK);
tft.setCursor(10, 220);
tft.print("IR: 0x");
tft.print(results.value, HEX);
// Wyświetl na matrycy
char irText[20];
sprintf(irText, "IR:%lX", results.value);
matrix.displayText(irText, PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
irrecv.resume();
}
// Animacja matrycy
if (matrix.displayAnimate()) {
matrix.displayReset();
}
// Co 5 sekund wyświetl "TEST" na matrycy jeśli nic się nie dzieje
if (millis() - lastUpdate > 5000 && !anyButtonPressed) {
matrix.displayText("TEST OK", PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
lastUpdate = millis();
}
}Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1