Created
June 26, 2023 17:43
-
-
Save NewProggie/9f90d4830d1f93cb4264f24ea54f3b47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pin assignments from LAWO ESP32 controller by nalx @ section77 | |
const byte DATA = 0; | |
const byte COL1 = 21; | |
const byte COL2 = 19; | |
const byte COL3 = 23; | |
const byte COL4 = 18; | |
const byte COL5 = 5; | |
const byte ROW1 = 17; | |
const byte ROW2 = 16; | |
const byte ROW3 = 4; | |
const byte ROW4 = 22; | |
const byte SET_EN = 2; | |
const byte RST_EN = 15; | |
const byte MOD1 = 13; | |
const byte MOD2 = 12; | |
const byte MOD3 = 14; | |
const byte MOD4 = 27; | |
const byte MOD5 = 26; | |
const byte MODULE_WIDTH = 28; | |
const byte MODULE_HEIGHT = 16; | |
const byte MODULE_PINS[] = { MOD1, MOD2, MOD3, MOD4, MOD5 }; | |
const byte COLUMN_BIT_PINS[] = { COL1, COL2, COL3, COL4, COL5 }; | |
const byte ROW_BIT_PINS[] = { ROW1, ROW2, ROW3, ROW4 }; | |
// Program config | |
const int SERIAL_BAUDRATE = 115200; | |
const int PAUSE_BETWEEN_DOT_FLIPS_MS = 3; | |
const int PAUSE_BETWEEN_ACTIONS_MS = 8000; | |
const int DELAY_HIGH_PULS_US = 750; | |
const int DELAY_FLIP_PULS_US = 100; | |
void setup() { | |
pinMode(DATA, OUTPUT); | |
pinMode(COL1, OUTPUT); | |
pinMode(COL2, OUTPUT); | |
pinMode(COL3, OUTPUT); | |
pinMode(COL4, OUTPUT); | |
pinMode(COL5, OUTPUT); | |
pinMode(ROW1, OUTPUT); | |
pinMode(ROW2, OUTPUT); | |
pinMode(ROW3, OUTPUT); | |
pinMode(ROW4, OUTPUT); | |
pinMode(SET_EN, OUTPUT); | |
pinMode(RST_EN, OUTPUT); | |
pinMode(MOD1, OUTPUT); | |
pinMode(MOD2, OUTPUT); | |
pinMode(MOD3, OUTPUT); | |
pinMode(MOD4, OUTPUT); | |
pinMode(MOD5, OUTPUT); | |
digitalWrite(DATA, LOW); | |
digitalWrite(COL1, LOW); | |
digitalWrite(COL2, LOW); | |
digitalWrite(COL3, LOW); | |
digitalWrite(COL4, LOW); | |
digitalWrite(COL5, LOW); | |
digitalWrite(ROW1, LOW); | |
digitalWrite(ROW2, LOW); | |
digitalWrite(ROW3, LOW); | |
digitalWrite(ROW4, LOW); | |
digitalWrite(SET_EN, LOW); | |
digitalWrite(RST_EN, LOW); | |
digitalWrite(MOD1, LOW); | |
digitalWrite(MOD2, LOW); | |
digitalWrite(MOD3, LOW); | |
digitalWrite(MOD4, LOW); | |
digitalWrite(MOD5, LOW); | |
} | |
void loop() { | |
flipDisplay(false); | |
delay(PAUSE_BETWEEN_ACTIONS_MS); | |
flipDisplay(true); | |
delay(PAUSE_BETWEEN_ACTIONS_MS); | |
} | |
void flipDisplay(boolean show_yellow) { | |
for (int module_idx = 0; module_idx < sizeof(MODULE_PINS); module_idx++) { | |
flipModule(module_idx, show_yellow); | |
} | |
} | |
void flipModule(byte module_idx, boolean show_yellow) { | |
for (int col_idx = 0; col_idx < MODULE_WIDTH; col_idx++) { | |
flipColumn(module_idx, col_idx, show_yellow); | |
} | |
} | |
void flipColumn(byte module_idx, byte col_idx, boolean show_yellow) { | |
for (int row_idx = 0; row_idx < MODULE_HEIGHT; row_idx++) { | |
flipDot(module_idx, row_idx, col_idx, show_yellow); | |
} | |
} | |
void flipDot(byte module_idx, byte row_idx, byte col_idx, boolean show_yellow) { | |
setRowAddress(row_idx); | |
setColumnAddress(col_idx); | |
flipDotAtModule(module_idx, show_yellow); | |
delay(PAUSE_BETWEEN_DOT_FLIPS_MS); | |
} | |
void setRowAddress(byte row_idx) { | |
for (int idx_bit = 0; idx_bit < sizeof(ROW_BIT_PINS); idx_bit++) { | |
boolean is_set = bitRead(row_idx, idx_bit); | |
if (is_set) { | |
digitalWrite(ROW_BIT_PINS[idx_bit], HIGH); | |
} else { | |
digitalWrite(ROW_BIT_PINS[idx_bit], LOW); | |
} | |
} | |
} | |
void setColumnAddress(byte col_idx) { | |
for (int idx_bit = 0; idx_bit < sizeof(COLUMN_BIT_PINS); idx_bit++) { | |
boolean is_set = bitRead(col_idx, idx_bit); | |
if (is_set) { | |
digitalWrite(COLUMN_BIT_PINS[idx_bit], HIGH); | |
} else { | |
digitalWrite(COLUMN_BIT_PINS[idx_bit], LOW); | |
} | |
} | |
} | |
void flipDotAtModule(byte module_idx, boolean show_yellow) { | |
if (show_yellow) { | |
flipDotYellowAtModule(module_idx); | |
} else { | |
flipDotBlackAtModule(module_idx); | |
} | |
} | |
void flipDotYellowAtModule(byte module_idx) { | |
digitalWrite(DATA, HIGH); | |
delayMicroseconds(DELAY_FLIP_PULS_US); | |
digitalWrite(MODULE_PINS[module_idx], HIGH); | |
digitalWrite(SET_EN, HIGH); | |
delayMicroseconds(DELAY_HIGH_PULS_US); | |
digitalWrite(SET_EN, LOW); | |
digitalWrite(MODULE_PINS[module_idx], LOW); | |
delayMicroseconds(DELAY_FLIP_PULS_US); | |
} | |
void flipDotBlackAtModule(byte module) { | |
digitalWrite(DATA, LOW); | |
delayMicroseconds(DELAY_FLIP_PULS_US); | |
digitalWrite(MODULE_PINS[module], HIGH); | |
digitalWrite(RST_EN, HIGH); | |
delayMicroseconds(DELAY_HIGH_PULS_US); | |
digitalWrite(RST_EN, LOW); | |
digitalWrite(MODULE_PINS[module], LOW); | |
delayMicroseconds(DELAY_FLIP_PULS_US); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment