// Create 2 frames for the LED matrix // Use a 2D array to hold the frame data for each frame // Use a keyboard key to switch between the frames //Anodes start at p2 and go to p5 int a1 = 2; int a2 = 3; int a3 = 4; int a4 = 5; //Cathodes start at p8 and go to p11 int c1 = 8; int c2 = 9; int c3 = 10; int c4 = 11; int xArray[4][4] = { { 1,0,0,1 } ,{ 0,1,1,0 } ,{ 0,1,1,0 } ,{ 1,0,0,1 } }; int boxArray[4][4] = { { 1,1,1,1 } ,{ 1,0,0,1 } ,{ 1,0,0,1 } ,{ 1,1,1,1 } }; int frame = 2; void setup() { Serial.begin(9600); pinMode(a1,OUTPUT); pinMode(a2,OUTPUT); pinMode(a3,OUTPUT); pinMode(a4,OUTPUT); pinMode(c1,OUTPUT); pinMode(c2,OUTPUT); pinMode(c3,OUTPUT); pinMode(c4,OUTPUT); Serial.println("STARTED"); } void loop() { checkSerial(); if (frame == 1) //SHOW ME THE X!!! { for (int x=0;x<4;x++) { // for loops: create the variable and set it! // check the test condition // if the test is true, INCREMENT for (int y = 0; y<4;y++) { if (xArray[x][y] == 1) { allOff(); digitalWrite(x+2,HIGH); //SET the anode to HIGH! digitalWrite(y+8,LOW); //Set the cathode to LOW! } } } } else if (frame == 2) { //SHOW ME THE BOX!!! for (int i=0;i<4;i++) { for (int j = 0; j<4;j++) { allOff(); if (boxArray[i][j] == 1) { digitalWrite(i+2,HIGH); digitalWrite(j+8,LOW); } } } } } void allOff() { digitalWrite(a1,LOW); digitalWrite(a2,LOW); digitalWrite(a3,LOW); digitalWrite(a4,LOW); digitalWrite(c1,HIGH); digitalWrite(c2,HIGH); digitalWrite(c3,HIGH); digitalWrite(c4,HIGH); } void checkSerial() { byte inByte = 0; if (Serial.available() > 0) { inByte = Serial.read(); Serial.println(inByte); } if (inByte == '1') { frame = 1; } else if (inByte == '2') { frame = 2; } }