Skip to content

Instantly share code, notes, and snippets.

@paramaggarwal
Created September 17, 2012 11:47
Show Gist options
  • Save paramaggarwal/3736871 to your computer and use it in GitHub Desktop.
Save paramaggarwal/3736871 to your computer and use it in GitHub Desktop.
Arrow Snippet - Multiple LED Matrix control from Arduino
const int clockPin = 12;
const int latchPin = 11;
const int dataPin1 = 7;
const int dataPin2 = 6;
const int dataPin3 = 5;
byte displayBuffer[24]= {0x18,0x3C,0x66,0xDB,0x18,0x18,0x18,0x18, 0x18,0x3C,0x66,0xDB,0x18,0x18,0x18,0x18, 0x18,0x3C,0x66,0xDB,0x18,0x18,0x18,0x18};
void setup() {
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(dataPin1, OUTPUT);
pinMode(dataPin2, OUTPUT);
pinMode(dataPin3, OUTPUT);
}
void loop() {
drawImage(displayBuffer);
}
void drawImage(byte * matrix) {
// Draw each column of the buffer, one by one.
for(int i=0; i<8; i++) {
// Shift out the position of the column, active high values.
for(int j=0; j<8; j++) {
digitalWrite(clockPin, LOW);
digitalWrite(dataPin1, (1<<i) & (1<<j) );
digitalWrite(dataPin2, (1<<i) & (1<<j) );
digitalWrite(dataPin3, (1<<i) & (1<<j) );
digitalWrite(clockPin, HIGH);
}
// Shift out the position of the column, active low values.
for(int j=0; j<8; j++) {
digitalWrite(clockPin, LOW);
digitalWrite(dataPin1, (~(matrix[i+16])) & (1<<j) );
digitalWrite(dataPin2, (~(matrix[i+8])) & (1<<j) );
digitalWrite(dataPin3, (~(matrix[i])) & (1<<j) );
digitalWrite(clockPin, HIGH);
}
// Toggle latch pin to display sent data.
digitalWrite(latchPin,LOW);
digitalWrite(latchPin,HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment