summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjdlugosz963 <jdlugosz963@gmail.com>2023-12-27 20:51:12 +0100
committerjdlugosz963 <jdlugosz963@gmail.com>2023-12-27 20:51:12 +0100
commitf943beff003dfeed11e3d4820ea17e74349d9070 (patch)
tree6f9135ff92d4b829f18e4db2e6ac6ac14cc17d83 /src
parent0eff9f2547b1b3cf6a1da93544fee092293df02c (diff)
downloadcyberbadge_esp_shifters_lib-f943beff003dfeed11e3d4820ea17e74349d9070.tar.gz
cyberbadge_esp_shifters_lib-f943beff003dfeed11e3d4820ea17e74349d9070.zip
Repair bug.HEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp202
1 files changed, 103 insertions, 99 deletions
diff --git a/src/main.cpp b/src/main.cpp
index af9911c..baaf3da 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,94 +1,101 @@
1
2#include <Arduino.h> 1#include <Arduino.h>
3#include "pinDefs.h" 2#include "pinDefs.h"
4 3
5 4
5int counter = 0;
6int delayVal = 15000;
7
8
9
6class BootlegDumbMatrix { 10class BootlegDumbMatrix {
7public: 11public:
8 12
9 int oe; 13 int oe;
10 int latch; 14 int latch;
11 int clock; 15 int clock;
12 int data; 16 int data;
13 17
14 int rowCount; 18 int rowCount;
15 int *rowPins; 19 int *rowPins;
16 20
17 BootlegDumbMatrix(){}; 21 BootlegDumbMatrix(){};
18 22
19 void init(){ 23 void init(){
20 pinMode(oe, OUTPUT); 24 pinMode(oe, OUTPUT);
21 pinMode(latch, OUTPUT); 25 pinMode(latch, OUTPUT);
22 pinMode(clock, OUTPUT); 26 pinMode(clock, OUTPUT);
23 pinMode(data, OUTPUT); 27 pinMode(data, OUTPUT);
24 28
25 for (int i = 0; i < rowCount; i++) { 29 for (int i = 0; i < rowCount; i++) {
26 pinMode(rowPins[i], OUTPUT); 30 pinMode(rowPins[i], OUTPUT);
27 digitalWrite(rowPins[i], HIGH); 31 digitalWrite(rowPins[i], HIGH);
28 } 32 }
29 33
30 digitalWrite(oe, LOW); 34 digitalWrite(oe, LOW);
31 } 35 }
32 36
33 void setRow(int row) { 37 void setRow(int row) {
34 for (int i = 0; i < rowCount; i++) { 38 for (int i = 0; i < rowCount; i++) {
35 digitalWrite(rowPins[i], HIGH); 39 digitalWrite(rowPins[i], HIGH);
36 } 40 }
37 if (row > rowCount) { 41 if (row > rowCount) {
38 return; 42 return;
39 } 43 }
40 digitalWrite(rowPins[row], LOW); 44 digitalWrite(rowPins[row], LOW);
41 } 45 }
42 46
43 void shiftOut(uint8_t val) { 47 void shiftOut(uint8_t val) {
44 uint8_t i; 48 uint8_t i;
45 49
46 for (i = 0; i < 8; i++) { 50 for (i = 0; i < 8; i++) {
47 digitalWrite(data, !!(val & (1 << i))); 51 digitalWrite(data, !!(val & (1 << i)));
48 52
49 digitalWrite(clock, HIGH); 53 digitalWrite(clock, HIGH);
50 digitalWrite(clock, LOW); 54 digitalWrite(clock, LOW);
51 } 55 }
52 } 56 }
53 57
54 uint8_t lineBuffer[12]; 58 uint8_t lineBuffer[12];
55 59
56 void spewBuf(){ 60 void spewBuf(){
57 for (int i = 0; i < 12; i++) { 61 for (int i = 0; i < 12; i++) {
58 shiftOut(lineBuffer[i]); 62 shiftOut(lineBuffer[i]);
59 } 63 }
60 } 64 }
61 65
62 void drawRow(int rowNum){ 66 void drawRow(int rowNum){
63 setRow(rowNum); 67 setRow(rowNum);
64 68
65 69
66 delayMicroseconds(delayVal); 70 delayMicroseconds(delayVal);
67 digitalWrite(LATCH_PIN, LOW); 71 digitalWrite(LATCH_PIN, LOW);
68 // delay(1); 72 // delay(1);
69 digitalWrite(LATCH_PIN, HIGH); 73 digitalWrite(LATCH_PIN, HIGH);
70 } 74 }
71 75
72 void drawFrame(){ 76 void drawFrame(){
73 for (int line = 0; line < 8; line++) { 77 for (int line = 0; line < 12; line++) {
74 uint8_t *pattern = getPattern(line); 78 uint8_t pattern = getPattern(line);
75 for (int i = 0; i < 12; i++) { 79 for (int i = 0; i < 8; i++) {
76 lineBuffer[i] = pattern[i]; 80 lineBuffer[i] = (pattern > i) & 0x1;
77 } 81 }
78 spewBuf(); 82 spewBuf();
79 } 83 }
80 } 84 }
81 85
82 uint8_t getGreenPattern(int i){ 86 uint8_t getPattern(int i) {
83 switch (i%3){ 87 switch (i%3){
84 case 0: 88 case 0:
85 return 0b01001001; 89 return 0b01001001;
86 case 1: 90 case 1:
87 return 0b10010010; 91
88 default: 92 return 0b10010010;
89 return 0b00100100; 93 default:
90 } 94
91 } 95 return 0b00100100;
96 }
97
98 }
92 99
93}; 100};
94 101
@@ -96,23 +103,20 @@ BootlegDumbMatrix dmatrix = BootlegDumbMatrix();
96 103
97void setup() { 104void setup() {
98 105
99 dmatrix.oe = OE_PIN; 106 dmatrix.oe = OE_PIN;
100 dmatrix.latch = LATCH_PIN; 107 dmatrix.latch = LATCH_PIN;
101 dmatrix.clock = CLOCK_PIN; 108 dmatrix.clock = CLOCK_PIN;
102 dmatrix.data = DATA_PIN; 109 dmatrix.data = DATA_PIN;
103 dmatrix.rowCount = 8; 110 dmatrix.rowCount = 8;
104 dmatrix.rowPins = new int[8]; 111 dmatrix.rowPins = new int[8];
105 memcpy(dmatrix.rowPins, ROW_PINS, 8*sizeof(int)); 112 memcpy(dmatrix.rowPins, ROW_PINS, 8*sizeof(int));
106 // dmatrix.rowPins = ROW_PINS; 113 // dmatrix.rowPins = ROW_PINS;
107 dmatrix.init(); 114 dmatrix.init();
108 115
109 Serial.begin(115200); 116 Serial.begin(115200);
110} 117}
111 118
112int counter = 0;
113int delayVal = 15000;
114
115void loop() { 119void loop() {
116 dmatrix.drawFrame(); 120 dmatrix.drawFrame();
117 121
118} \ No newline at end of file 122}