forked from Concept-Bytes/Open-Chess
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboard_driver.h
More file actions
71 lines (58 loc) · 1.95 KB
/
Copy pathboard_driver.h
File metadata and controls
71 lines (58 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef BOARD_DRIVER_H
#define BOARD_DRIVER_H
#include <Adafruit_NeoPixel.h>
// ---------------------------
// Hardware Configuration
// ---------------------------
// if ESP32 use pin D8, otherwise 17
#if defined(ESP32)
#define LED_PIN D8
#else
#define LED_PIN 17 // Pin for NeoPixels
#endif
#define NUM_ROWS 8
#define NUM_COLS 8
#define LED_COUNT (NUM_ROWS * NUM_COLS)
#define BRIGHTNESS 255 // LED brightness: 0-255 (0=off, 255=max). Current: 255 (100% max brightness)
// Shift Register (74HC594) Pins
#define SER_PIN 2 // Serial data input (74HC594 pin 14)
#define SRCLK_PIN 3 // Shift register clock (pin 11)
#define RCLK_PIN 4 // Latch clock (pin 12)
// Column Input Pins (D6..D13)
#define COL_PINS {6, 7, 8, 9, 10, 11, 12, 13}
// ---------------------------
// Board Driver Class
// ---------------------------
class BoardDriver {
private:
Adafruit_NeoPixel strip;
int colPins[NUM_COLS];
byte rowPatterns[8];
bool sensorState[8][8];
bool sensorPrev[8][8];
void loadShiftRegister(byte data);
int getPixelIndex(int row, int col);
public:
BoardDriver();
void begin();
void readSensors();
bool getSensorState(int row, int col);
bool getSensorPrev(int row, int col);
void updateSensorPrev();
// LED Control
void clearAllLEDs();
void setSquareLED(int row, int col, uint32_t color);
void setSquareLED(int row, int col, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0);
void showLEDs();
// Animation Functions
void fireworkAnimation();
void captureAnimation();
void promotionAnimation(int col);
void blinkSquare(int row, int col, int times = 3);
void highlightSquare(int row, int col, uint32_t color);
// Setup Functions
bool checkInitialBoard(const char initialBoard[8][8]);
void updateSetupDisplay(const char initialBoard[8][8]);
void printBoardState(const char initialBoard[8][8]);
};
#endif // BOARD_DRIVER_H