/* Light up all the LED's in the matrix to test them Nathan Clark */ int delayPin = 1; // delay before it turns the LED off int row[] = {10,11,12,13,A5,A4,A3,A0}; // These are the Cathodes - Send LOW to turn on LED int col[] = {2,3,4,5,6,7,8,9}; // These are the Anodes - Send HIGH to turn on LED void (*funcAnimate[2])(); // Sets up an array of functions we can call void setup() { for (int thisPin = 0; thisPin < 8; thisPin++) { pinMode(col[thisPin], OUTPUT); // Set selected pin to be an output rather then an input pin pinMode(row[thisPin], OUTPUT); // this is so we cna provide +5v or GND at any pin digitalWrite(row[thisPin], HIGH); // Set all cathodes to have positive voltage at them. Hence LED will not light up irrespective of what the anode is set to } funcAnimate[0] = MakeSadSmileFace; funcAnimate[1] = MakewinkingFace; Serial.begin(9600); } void loop() { int randnumber = 0; randnumber = random(0,2); Serial.print("Random Number is "); Serial.println(randnumber); for (int x=0;x<2;x++) { (*funcAnimate[randnumber])(); delay(1); } } void resetLEDS() { for (int thisPin = 0; thisPin < 8; thisPin++) { digitalWrite(row[thisPin], HIGH); // Set all cathodes to have positive voltage at them. Hence LED will not light up irrespective of what the anode is set to digitalWrite(col[thisPin], LOW); } } void onLED(int colnum,int rownum) { digitalWrite(col[colnum], HIGH); digitalWrite(row[rownum], LOW); delay(delayPin); digitalWrite(col[colnum], LOW); digitalWrite(row[rownum], HIGH); } void drawSmileyFace() { onLED(0,0); onLED(1,1); onLED(0,1); onLED(1,0); onLED(6,0); onLED(7,1); onLED(6,1); onLED(7,0); onLED(3,3); onLED(4,3); onLED(3,2); onLED(4,2); onLED(0,5); onLED(1,6); onLED(2,7); onLED(3,7); onLED(4,7); onLED(5,7); onLED(6,6); onLED(7,5); } void drawSmileyFaceWink() { onLED(0,0); onLED(1,1); onLED(0,1); onLED(1,0); onLED(3,3); onLED(4,3); onLED(3,2); onLED(4,2); onLED(0,5); onLED(1,6); onLED(2,7); onLED(3,7); onLED(4,7); onLED(5,7); onLED(6,6); onLED(7,5); } void DrawSadFace() { onLED(0,0); onLED(1,1); onLED(0,1); onLED(1,0); onLED(6,0); onLED(7,0); onLED(6,1); onLED(7,1); onLED(3,3); onLED(4,3); onLED(3,2); onLED(4,2); onLED(0,7); onLED(1,6); onLED(2,5); onLED(3,5); onLED(4,5); onLED(5,5); onLED(6,6); onLED(7,7); } void MakewinkingFace() { for (int x=0;x<40;x++) { drawSmileyFace(); delay(1); } for (int x=0;x<40;x++) { drawSmileyFaceWink(); delay(1); } } void MakeSadSmileFace() { for (int x=0;x<40;x++) { drawSmileyFace(); delay(1); } for (int x=0;x<40;x++) { DrawSadFace(); delay(1); } }