Created
January 22, 2022 16:35
-
-
Save AndyQ/6bf57790e63e3f47965678971c463226 to your computer and use it in GitHub Desktop.
Simple image display for YFRobot 8x8 Dot Matrix display (controller with dual serial 74HC595 chips)
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
/* | |
Simple image display for YFRobot 8x8 Dot Matrix display (controller with dual serial 74HC595 chips) | |
Author: Andy Qua | |
Date: 22nd Jan 2022 | |
*/ | |
int dataPin = 10; // The Serial Data Pin to the Shift Register (SER on board) | |
int latchPin = 8; // The Latch Pin to the Shift Register (RCK on board) | |
int clockPin = 7; // The Clock Pin to the Shift Register (SRCK on board) | |
// Our images | |
byte images[][8] = {{ | |
// Smile | |
B00000000, | |
B11100111, | |
B10100101, | |
B11100111, | |
B00000000, | |
B10000001, | |
B01111110, | |
B00000000 | |
}, | |
{ | |
B00011000, | |
B00100100, | |
B01000010, | |
B11111111, | |
B10000001, | |
B10011001, | |
B10011001, | |
B11111111, | |
}}; | |
int columnPositions[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; | |
int counter = 0; | |
int imageNr = 0; | |
void setup() | |
{ | |
pinMode(dataPin, OUTPUT); // Configure Digital Pins | |
pinMode(latchPin, OUTPUT); | |
pinMode(clockPin, OUTPUT); | |
} | |
void loop() { | |
// Every 1000 iterations round the loop switch images | |
if ( counter == 1000 ) { | |
counter = 0; | |
imageNr = imageNr == 1 ? 0 : 1; | |
} | |
counter += 1; | |
// Pointer to the image we want to draw | |
byte *image = images[imageNr]; | |
// Draw image | |
for ( int row = 0 ; row < 8 ; ++row ) | |
{ | |
int rowVal = image[row]; | |
// We invert the rowVal as 0 is on and 1 is off! | |
writeOutput(~rowVal, columnPositions[row]); | |
} | |
} | |
void writeOutput( int rowVal, int col ) | |
{ | |
digitalWrite(latchPin, LOW); // Pull latch LOW to send data | |
shiftOut(dataPin, clockPin, MSBFIRST, rowVal); // Send the row data byte | |
shiftOut(dataPin, clockPin, MSBFIRST, col); // Send the column data byte | |
digitalWrite(latchPin, HIGH); // Pull latch HIGH to finish sending data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment