Created
July 5, 2013 21:40
-
-
Save thomo/5937431 to your computer and use it in GitHub Desktop.
LED Matrix Arduino program (TLMM501B connected to Pollin AVR NET IO with AVR-NETIO Arduino clone)
This file contains hidden or 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
int redPin = 0; | |
int greenPin = 1; | |
int resetPin = 4; | |
int selectPin = 5; | |
int brightPin = 3; | |
int clockPin = 2; | |
int offset = 0; | |
int bufferCol = 0; | |
byte leddata[17][4] = { {B0,B0,B0,B0} }; | |
void setup() { | |
pinMode(resetPin, OUTPUT); | |
pinMode(selectPin, OUTPUT); | |
pinMode(greenPin, OUTPUT); | |
pinMode(redPin, OUTPUT); | |
pinMode(brightPin, OUTPUT); | |
pinMode(clockPin, OUTPUT); | |
digitalWrite(resetPin, LOW); | |
digitalWrite(resetPin, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(resetPin, LOW); | |
digitalWrite(selectPin, HIGH); | |
Serial.begin(14400); | |
while (!Serial) { | |
; // wait for serial port to connect. Needed for Leonardo only | |
} | |
Serial.println("Let's rock!"); | |
} | |
void loop() { | |
for(int idx = 1; idx < 17; ++idx) { | |
int col = (offset + idx) % 17; | |
outputColumn(leddata[col][0],leddata[col][1],leddata[col][2],leddata[col][3]); | |
} | |
int data = Serial.read(); | |
if (data != -1) { | |
leddata[offset][bufferCol] = data; | |
++bufferCol; | |
if (bufferCol == 4) { | |
bufferCol = 0; | |
offset = (offset + 1) % 17; | |
} | |
} | |
} | |
void outputHalfColumn(byte green, byte red) { | |
byte bitmask = 0x01; | |
for(int row = 0; row < 8; ++row) { | |
if (green & bitmask) digitalWrite(greenPin, HIGH); | |
else digitalWrite(greenPin, LOW); | |
if (red & bitmask) digitalWrite(redPin, HIGH); | |
else digitalWrite(redPin, LOW); | |
bitmask = bitmask << 1; | |
ledClock(); | |
} | |
} | |
void outputColumn(byte lowgreen, byte highgreen, byte lowred, byte highred) { | |
digitalWrite(brightPin, HIGH); | |
outputHalfColumn(lowgreen, lowred); | |
outputHalfColumn(highgreen, highred); | |
digitalWrite(brightPin, LOW); | |
delayMicroseconds(500); | |
} | |
void ledClock() { | |
delayMicroseconds(1); | |
digitalWrite(clockPin, HIGH); | |
delayMicroseconds(1); | |
digitalWrite(clockPin, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment