Created
May 5, 2014 19:54
-
-
Save HerrSpace/39a8dd080c0f4b951863 to your computer and use it in GitHub Desktop.
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 A 3 | |
#define B 4 | |
#define C 5 | |
#define D 6 | |
#define E 7 | |
int matrix[4][4][2] = | |
{ | |
{ {A, B}, {C, B}, {D, B}, {E, B} }, | |
{ {A, C}, {B, C}, {D, C}, {E, C} }, | |
{ {A, D}, {B, D}, {C, D}, {E, D} }, | |
{ {A, E}, {B, E}, {C, E}, {D, E} } | |
}; | |
int frameBuffer[4][4]; | |
int charlieIdxX = 0; | |
int charlieIdxY = 0; | |
void setup() | |
{ | |
for( int yIdx = 0; yIdx < 4; yIdx++ ) | |
{ for( int xIdx = 0; xIdx < 4; xIdx++ ) | |
{ | |
frameBuffer[yIdx][xIdx] = 0; | |
} | |
} | |
frameBuffer[1][0] = 1; // test | |
frameBuffer[3][2] = 1; | |
// initialize timer1 | |
noInterrupts(); // disable all interrupts | |
TCCR1A = 0; | |
TCCR1B = 0; | |
TCNT1 = 0; | |
OCR1A = 4000; // compare match register 16MHz/256/2Hz | |
TCCR1B |= (1 << WGM12); // CTC mode | |
TCCR1B |= (1 << CS10); | |
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt | |
interrupts(); // enable all interrupts | |
} | |
void modGlobalCharlieIdx() { | |
charlieIdxX++; | |
if(charlieIdxX == 4) { | |
charlieIdxX = 0; | |
charlieIdxY++; | |
} | |
if(charlieIdxY == 4) { | |
charlieIdxX = 0; | |
charlieIdxY = 0; | |
} | |
} | |
void resetCherliplexing() { | |
pinMode( A, INPUT ); | |
pinMode( B, INPUT ); | |
pinMode( C, INPUT ); | |
pinMode( D, INPUT ); | |
pinMode( E, INPUT ); | |
} | |
void light( int pins[2] ) | |
{ | |
pinMode( pins[0], OUTPUT ); | |
digitalWrite( pins[0], HIGH ); | |
pinMode( pins[1], OUTPUT ); | |
digitalWrite( pins[1], LOW ); | |
} | |
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine | |
{ | |
resetCherliplexing(); | |
if( frameBuffer[charlieIdxY][charlieIdxX]) | |
{ light( matrix[charlieIdxY][charlieIdxX] ); } | |
modGlobalCharlieIdx(); | |
} | |
void loop() | |
{ | |
; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment