Skip to content

Instantly share code, notes, and snippets.

@Bouni
Last active August 29, 2015 14:13
Show Gist options
  • Save Bouni/83dad22b25006fc736ab to your computer and use it in GitHub Desktop.
Save Bouni/83dad22b25006fc736ab to your computer and use it in GitHub Desktop.
A dot matrix test
int column[8] = {A0,A1,A2,A3,A4,A5,A6,A7};
int row[8] = {A8,A9,A10,A11,A12,A13,A14,A15};
int pattern[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
/*
void writeByte(int byte, int *port) {
for(int i=0; i<8; i++){
if(byte & (1<<i)) {
digitalWrite(port[i], LOW);
} else {
digitalWrite(port[i], HIGH);
}
}
}
*/
void setup()
{
for(int i=0; i<8; i++) {
pinMode(column[i], OUTPUT);
digitalWrite(column[i], HIGH);
pinMode(row[i], OUTPUT);
digitalWrite(row[i], LOW);
}
}
void loop()
{
// for every row of the matrix
for(int r=0; r<8; r++) {
// switch on the current row pin
digitalWrite(row[r], LOW);
// for every column of the matrix
for(int c=0; c<8; c++) {
// if the coresponding bit in the pattern for this row is a 1,
// set the column pin
if(pattern[r] & (1 << c)) {
digitalWrite(column[c], HIGH);
delay(5);
digitalWrite(column[c], LOW);
// if not make sure the pin is off
} else {
delay(5);
digitalWrite(column[c], LOW);
}
}
// switch off the row when we finished it, procceed to the next one
digitalWrite(row[r], HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment