From 0eff9f2547b1b3cf6a1da93544fee092293df02c Mon Sep 17 00:00:00 2001 From: CritBit Date: Wed, 27 Dec 2023 20:05:29 +0100 Subject: move to separate repo --- .gitignore | 3 ++ include/pinDefs.h | 31 ++++++++++++++ platformio.ini | 16 ++++++++ src/main.cpp | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 .gitignore create mode 100644 include/pinDefs.h create mode 100644 platformio.ini create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b6f529 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.pio +.vscode +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 @@ + + +#pragma once + +const int BUTTON_PIN_1 = 0; +const int BUTTON_PIN_2 = 26; +const int BUTTON_PIN_3 = 25; + +const int PIN_WS2812 = 22; + + + + +const int DATA_PIN = 13; +const int CLOCK_PIN = 22; +const int LATCH_PIN = 23; +const int OE_PIN = 19; + +const int ROW1_PIN = 15; +const int ROW2_PIN = 17; +const int ROW3_PIN = 0; +const int ROW4_PIN = 16; +const int ROW5_PIN = 4; +const int ROW6_PIN = 12; +const int ROW7_PIN = 18; +const int ROW8_PIN = 5; + +const int ROW_PINS[8] = { + ROW1_PIN, ROW2_PIN, ROW3_PIN, ROW4_PIN, + ROW5_PIN, ROW6_PIN, ROW7_PIN, ROW8_PIN +}; \ 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 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32dev] +platform = espressif32 +board = esp32dev +framework = arduino + +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 @@ + +#include +#include "pinDefs.h" + + +class BootlegDumbMatrix { +public: + + int oe; + int latch; + int clock; + int data; + + int rowCount; + int *rowPins; + + BootlegDumbMatrix(){}; + + void init(){ + pinMode(oe, OUTPUT); + pinMode(latch, OUTPUT); + pinMode(clock, OUTPUT); + pinMode(data, OUTPUT); + + for (int i = 0; i < rowCount; i++) { + pinMode(rowPins[i], OUTPUT); + digitalWrite(rowPins[i], HIGH); + } + + digitalWrite(oe, LOW); + } + + void setRow(int row) { + for (int i = 0; i < rowCount; i++) { + digitalWrite(rowPins[i], HIGH); + } + if (row > rowCount) { + return; + } + digitalWrite(rowPins[row], LOW); + } + + void shiftOut(uint8_t val) { + uint8_t i; + + for (i = 0; i < 8; i++) { + digitalWrite(data, !!(val & (1 << i))); + + digitalWrite(clock, HIGH); + digitalWrite(clock, LOW); + } + } + + uint8_t lineBuffer[12]; + + void spewBuf(){ + for (int i = 0; i < 12; i++) { + shiftOut(lineBuffer[i]); + } + } + + void drawRow(int rowNum){ + setRow(rowNum); + + + delayMicroseconds(delayVal); + digitalWrite(LATCH_PIN, LOW); + // delay(1); + digitalWrite(LATCH_PIN, HIGH); + } + + void drawFrame(){ + for (int line = 0; line < 8; line++) { + uint8_t *pattern = getPattern(line); + for (int i = 0; i < 12; i++) { + lineBuffer[i] = pattern[i]; + } + spewBuf(); + } + } + + uint8_t getGreenPattern(int i){ + switch (i%3){ + case 0: + return 0b01001001; + case 1: + return 0b10010010; + default: + return 0b00100100; + } + } + +}; + +BootlegDumbMatrix dmatrix = BootlegDumbMatrix(); + +void setup() { + + dmatrix.oe = OE_PIN; + dmatrix.latch = LATCH_PIN; + dmatrix.clock = CLOCK_PIN; + dmatrix.data = DATA_PIN; + dmatrix.rowCount = 8; + dmatrix.rowPins = new int[8]; + memcpy(dmatrix.rowPins, ROW_PINS, 8*sizeof(int)); + // dmatrix.rowPins = ROW_PINS; + dmatrix.init(); + + Serial.begin(115200); +} + +int counter = 0; +int delayVal = 15000; + +void loop() { + dmatrix.drawFrame(); + +} \ No newline at end of file -- cgit v1.2.3