diff options
author | CritBit <Jakub.Sadowski1@gmail.com> | 2023-12-27 20:05:29 +0100 |
---|---|---|
committer | CritBit <Jakub.Sadowski1@gmail.com> | 2023-12-27 20:05:29 +0100 |
commit | 0eff9f2547b1b3cf6a1da93544fee092293df02c (patch) | |
tree | 7dd0ec881ea743acfb41d7f39660277c22909e07 /src | |
download | cyberbadge_esp_shifters_lib-0eff9f2547b1b3cf6a1da93544fee092293df02c.tar.gz cyberbadge_esp_shifters_lib-0eff9f2547b1b3cf6a1da93544fee092293df02c.zip |
move to separate repo
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
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 | ||