diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | include/pinDefs.h | 31 | ||||
-rw-r--r-- | platformio.ini | 16 | ||||
-rw-r--r-- | src/main.cpp | 118 |
4 files changed, 168 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b6f529 --- /dev/null +++ b/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | .pio | ||
2 | .vscode | ||
3 | secrets.h | ||
diff --git a/include/pinDefs.h b/include/pinDefs.h new file mode 100644 index 0000000..25d951c --- /dev/null +++ b/include/pinDefs.h | |||
@@ -0,0 +1,31 @@ | |||
1 | |||
2 | |||
3 | #pragma once | ||
4 | |||
5 | const int BUTTON_PIN_1 = 0; | ||
6 | const int BUTTON_PIN_2 = 26; | ||
7 | const int BUTTON_PIN_3 = 25; | ||
8 | |||
9 | const int PIN_WS2812 = 22; | ||
10 | |||
11 | |||
12 | |||
13 | |||
14 | const int DATA_PIN = 13; | ||
15 | const int CLOCK_PIN = 22; | ||
16 | const int LATCH_PIN = 23; | ||
17 | const int OE_PIN = 19; | ||
18 | |||
19 | const int ROW1_PIN = 15; | ||
20 | const int ROW2_PIN = 17; | ||
21 | const int ROW3_PIN = 0; | ||
22 | const int ROW4_PIN = 16; | ||
23 | const int ROW5_PIN = 4; | ||
24 | const int ROW6_PIN = 12; | ||
25 | const int ROW7_PIN = 18; | ||
26 | const int ROW8_PIN = 5; | ||
27 | |||
28 | const int ROW_PINS[8] = { | ||
29 | ROW1_PIN, ROW2_PIN, ROW3_PIN, ROW4_PIN, | ||
30 | ROW5_PIN, ROW6_PIN, ROW7_PIN, ROW8_PIN | ||
31 | }; \ No newline at end of file | ||
diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..86818e0 --- /dev/null +++ b/platformio.ini | |||
@@ -0,0 +1,16 @@ | |||
1 | ; PlatformIO Project Configuration File | ||
2 | ; | ||
3 | ; Build options: build flags, source filter | ||
4 | ; Upload options: custom upload port, speed and extra flags | ||
5 | ; Library options: dependencies, extra library storages | ||
6 | ; Advanced options: extra scripting | ||
7 | ; | ||
8 | ; Please visit documentation for the other options and examples | ||
9 | ; https://docs.platformio.org/page/projectconf.html | ||
10 | |||
11 | [env:esp32dev] | ||
12 | platform = espressif32 | ||
13 | board = esp32dev | ||
14 | framework = arduino | ||
15 | |||
16 | monitor_speed = 115200 | ||
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..af9911c --- /dev/null +++ b/src/main.cpp | |||
@@ -0,0 +1,118 @@ | |||
1 | |||
2 | #include <Arduino.h> | ||
3 | #include "pinDefs.h" | ||
4 | |||
5 | |||
6 | class BootlegDumbMatrix { | ||
7 | public: | ||
8 | |||
9 | int oe; | ||
10 | int latch; | ||
11 | int clock; | ||
12 | int data; | ||
13 | |||
14 | int rowCount; | ||
15 | int *rowPins; | ||
16 | |||
17 | BootlegDumbMatrix(){}; | ||
18 | |||
19 | void init(){ | ||
20 | pinMode(oe, OUTPUT); | ||
21 | pinMode(latch, OUTPUT); | ||
22 | pinMode(clock, OUTPUT); | ||
23 | pinMode(data, OUTPUT); | ||
24 | |||
25 | for (int i = 0; i < rowCount; i++) { | ||
26 | pinMode(rowPins[i], OUTPUT); | ||
27 | digitalWrite(rowPins[i], HIGH); | ||
28 | } | ||
29 | |||
30 | digitalWrite(oe, LOW); | ||
31 | } | ||
32 | |||
33 | void setRow(int row) { | ||
34 | for (int i = 0; i < rowCount; i++) { | ||
35 | digitalWrite(rowPins[i], HIGH); | ||
36 | } | ||
37 | if (row > rowCount) { | ||
38 | return; | ||
39 | } | ||
40 | digitalWrite(rowPins[row], LOW); | ||
41 | } | ||
42 | |||
43 | void shiftOut(uint8_t val) { | ||
44 | uint8_t i; | ||
45 | |||
46 | for (i = 0; i < 8; i++) { | ||
47 | digitalWrite(data, !!(val & (1 << i))); | ||
48 | |||
49 | digitalWrite(clock, HIGH); | ||
50 | digitalWrite(clock, LOW); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | uint8_t lineBuffer[12]; | ||
55 | |||
56 | void spewBuf(){ | ||
57 | for (int i = 0; i < 12; i++) { | ||
58 | shiftOut(lineBuffer[i]); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | void drawRow(int rowNum){ | ||
63 | setRow(rowNum); | ||
64 | |||
65 | |||
66 | delayMicroseconds(delayVal); | ||
67 | digitalWrite(LATCH_PIN, LOW); | ||
68 | // delay(1); | ||
69 | digitalWrite(LATCH_PIN, HIGH); | ||
70 | } | ||
71 | |||
72 | void drawFrame(){ | ||
73 | for (int line = 0; line < 8; line++) { | ||
74 | uint8_t *pattern = getPattern(line); | ||
75 | for (int i = 0; i < 12; i++) { | ||
76 | lineBuffer[i] = pattern[i]; | ||
77 | } | ||
78 | spewBuf(); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | uint8_t getGreenPattern(int i){ | ||
83 | switch (i%3){ | ||
84 | case 0: | ||
85 | return 0b01001001; | ||
86 | case 1: | ||
87 | return 0b10010010; | ||
88 | default: | ||
89 | return 0b00100100; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | }; | ||
94 | |||
95 | BootlegDumbMatrix dmatrix = BootlegDumbMatrix(); | ||
96 | |||
97 | void setup() { | ||
98 | |||
99 | dmatrix.oe = OE_PIN; | ||
100 | dmatrix.latch = LATCH_PIN; | ||
101 | dmatrix.clock = CLOCK_PIN; | ||
102 | dmatrix.data = DATA_PIN; | ||
103 | dmatrix.rowCount = 8; | ||
104 | dmatrix.rowPins = new int[8]; | ||
105 | memcpy(dmatrix.rowPins, ROW_PINS, 8*sizeof(int)); | ||
106 | // dmatrix.rowPins = ROW_PINS; | ||
107 | dmatrix.init(); | ||
108 | |||
109 | Serial.begin(115200); | ||
110 | } | ||
111 | |||
112 | int counter = 0; | ||
113 | int delayVal = 15000; | ||
114 | |||
115 | void loop() { | ||
116 | dmatrix.drawFrame(); | ||
117 | |||
118 | } \ No newline at end of file | ||