Last active
October 1, 2021 14:08
-
-
Save HerrZatacke/fabb49b5f6a420baea5f8fb4e1f8adee to your computer and use it in GitHub Desktop.
Adress a SLx2016 LED Matrix display using two 74HC595 8-bit shift registers
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
#define LATCH 14 | |
#define DATA 15 | |
#define CLOCK 16 | |
#define CHAR_DELAY 100 | |
// https://www.mouser.de/datasheet/2/311/XY%20Stackable%200.180%20%20%20%20%204-Digit%205x7%20Dot%20Matrix_%20Alp-335281.pdf | |
// https://www.arduino.cc/en/Tutorial/Foundations/ShiftOut | |
// https://imgur.com/a/Fjh7rst | |
/* | |
This sketch adresses one SLx2016 LED Matrix display | |
using two 8-bit shift registers (74HC595) | |
The two shift registers are wired as in the ShiftOut example | |
3 bits of the first shift register and 7 bits of the second shift register are being used: | |
First shift register: | |
Bit No(Q) | register pin | Used as | Display pin | |
------------------------------------------------ | |
0 | 15 | Addr A0 | 3 | |
1 | 1 | Addr A1 | 2 | |
2 | 2 | Write | 1 | |
3 | 3 | - | unused | |
4 | 4 | - | unused | |
5 | 5 | - | unused | |
6 | 6 | - | unused | |
7 | 7 | - | unused | |
Second shift register: | |
Bit No(Q) | register pin | Used as | Display pin | |
------------------------------------------------ | |
0 | 15 | Data D0 | 5 | |
1 | 1 | Data D1 | 6 | |
2 | 2 | Data D2 | 7 | |
3 | 3 | Data D3 | 8 | |
4 | 4 | Data D4 | 9 | |
5 | 5 | Data D5 | 10 | |
6 | 6 | Data D6 | 11 | |
7 | 7 | - | unused | |
*/ | |
void setup() { | |
pinMode(LATCH, OUTPUT); | |
pinMode(CLOCK, OUTPUT); | |
pinMode(DATA, OUTPUT); | |
// Serial.begin(115200); | |
} | |
void loop() { | |
writeText("Hello world!"); | |
// randomChar(); | |
} | |
void randomChar() { | |
sendChar((byte)random(255), (byte)random(4)); | |
delay(CHAR_DELAY); | |
} | |
void writeText(String chars) { | |
String padded = " " + chars + " "; | |
for (int i = 0; i < padded.length() - 4; i++) { | |
// Serial.println(padded.substring(i, i + 4)); | |
writeChars(padded.substring(i, i + 4)); | |
delay(CHAR_DELAY); | |
} | |
} | |
void writeChars(String chars) { | |
for (byte addr = 0; addr <= 3; addr++) { | |
byte chr = chars[addr]; | |
// invert both adress bits to "reverse" character index | |
byte digitSelect = ( | |
0 | | |
!bitRead(addr, 0) << 0 | | |
!bitRead(addr, 1) << 1 | |
); | |
sendChar(chr, digitSelect); | |
} | |
} | |
void sendChar(byte charByte, byte addrByte) { | |
sendData(charByte, addrByte); | |
// Set write bit. | |
bitSet(addrByte, 2); | |
sendData(charByte, addrByte); | |
} | |
void sendData(byte charByte, byte addrByte) { | |
digitalWrite(LATCH, LOW); //Pull latch HIGH to send data | |
shiftOut(DATA, CLOCK, MSBFIRST, charByte); | |
shiftOut(DATA, CLOCK, MSBFIRST, addrByte); | |
digitalWrite(LATCH, HIGH); // Pull latch LOW to stop sending data | |
} |
Author
HerrZatacke
commented
Oct 1, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment