/* Word Clock By Tech Kiwi 11th October 2014 WC Light Test is used to progressively turn on each row of LEDs Use this to test the operation of the LED Array ---------- An 13x13 Array LEDs have been attach to Mega Digital Pins 53 and below Columns are the anodes Rows are the cathodes --------- Pin numbers: Matrix: * 26 x Digital pins 28 through 53 are used to drive the 13x13 display * Columns X = 52,50,48,46,44,42,40,38,36,34,32,30,28 * Rows Y = 29,31,33,35,37,39,41,43,45,47,49,51,53 * * 1k ohm resister used to protect LEDs on each of the 13 Rows Yaxis */ #include #include #include // a basic DS1307 library that returns time as a time_t // 2-dimensional array of column pin numbers: const int col[13] = { 52,50,48,46,44,42,40,38,36,34,32,30,28 }; // Arduino MEGA 2560 Digital Pin allocation // 2-dimensional array of row pin numbers: const int row[13] = { 29,31,33,35,37,39,41,43,45,47,49,51,53 }; // Arduino MEGA 2560 Digital Pin allocation // 2-dimensional array of pixels: int pixels[13][13]; // Dimmer is the delay in microseconds impacting LED brightness // LDR is across A7 and has an input range of 150 to 900 from Dark to Light respectively int LDR; // The variable dimmer is the duration in Millseconds that each LED is left on before being turned off in the LED array int dimmer = 150; // 300 seems to be the brightest before flicker detected // Refresh variable for RTC // cursor position: int x = 5; int y = 5; void setup() { //Initialize RTC Serial.begin(9600); // while (!Serial) ; // wait until Arduino Serial Monitor opens delay(200); setSyncProvider(RTC.get); // the function to get the time from the RTC setSyncInterval(60); // sync the time every 60 seconds (1 minutes) if(timeStatus()!= timeSet){ Serial.println("Unable to sync with the RTC"); RTC.set(1408278800); // set the RTC to Aug 25 2014 9:00 am setTime(1408278800); } else{ Serial.println("RTC has set the system time"); } // initialize the LED I/O pins as outputs // iterate over the pins: for (int thisPin = 0; thisPin < 13; thisPin++) { // initialize the output pins: pinMode(col[thisPin], OUTPUT); pinMode(row[thisPin], OUTPUT); // take the col pins (i.e. the cathodes) high to ensure that // the LEDS are off: digitalWrite(col[thisPin], LOW); } // initialize the pixel matrix by setting all LED Anodes and Cathodes to LOW: for (int x = 0; x < 13; x++) { for (int y = 0; y < 13; y++) { pixels[x][y] = LOW; } } // initialize the Button I/O pins as Digital Inputs for Increment and Decrement time for manual adjustment of time pinMode(8, INPUT); // Increment time pinMode(9, INPUT); // Decrement time } void loop() { // draw the screen: refreshScreen(); delay(200); row0(); refreshScreen(); delay(200); drow0(); refreshScreen(); delay(200); row1(); refreshScreen(); delay(200); drow1(); refreshScreen(); delay(200); row2(); refreshScreen(); delay(200); drow2(); refreshScreen(); delay(200); row3(); refreshScreen(); delay(200); drow3(); refreshScreen(); delay(200); row4(); refreshScreen(); delay(200); drow4(); refreshScreen(); delay(200); row5(); refreshScreen(); delay(200); drow5(); refreshScreen(); delay(200); row6(); refreshScreen(); delay(200); drow6(); refreshScreen(); delay(200); row7(); refreshScreen(); delay(200); drow7(); refreshScreen(); delay(200); row8(); refreshScreen(); delay(200); drow8(); refreshScreen(); delay(200); row9(); refreshScreen(); delay(200); drow9(); refreshScreen(); delay(200); row10(); refreshScreen(); delay(200); drow10(); refreshScreen(); delay(200); row11(); refreshScreen(); delay(200); drow11(); refreshScreen(); delay(200); row12(); refreshScreen(); delay(200); drow12(); } /* routines */ void blankscreen() { // initialize the pixel matrix by setting all LED Anodes and Cathodes to LOW: for (int x = 0; x < 13; x++) { for (int y = 0; y < 13; y++) { pixels[x][y] = LOW; } } } void row0() { // Personalised Name Text Block pixels[0][0]=HIGH; pixels[0][1]=HIGH; pixels[0][2]=HIGH; pixels[0][3]=HIGH; pixels[0][4]=HIGH; pixels[0][5]=HIGH; pixels[0][6]=HIGH; pixels[0][7]=HIGH; pixels[0][8]=HIGH; pixels[0][9]=HIGH; pixels[0][10]=HIGH; pixels[0][11]=HIGH; pixels[0][12]=HIGH; } void drow0() { // Personalised Name Text Block pixels[0][0]=LOW; pixels[0][1]=LOW; pixels[0][2]=LOW; pixels[0][3]=LOW; pixels[0][4]=LOW; pixels[0][5]=LOW; pixels[0][6]=LOW; pixels[0][7]=LOW; pixels[0][8]=LOW; pixels[0][9]=LOW; pixels[0][10]=LOW; pixels[0][11]=LOW; pixels[0][12]=LOW; } void row1() { // Personalised Name Text Block pixels[1][0]=HIGH; pixels[1][1]=HIGH; pixels[1][2]=HIGH; pixels[1][3]=HIGH; pixels[1][4]=HIGH; pixels[1][5]=HIGH; pixels[1][6]=HIGH; pixels[1][7]=HIGH; pixels[1][8]=HIGH; pixels[1][9]=HIGH; pixels[1][10]=HIGH; pixels[1][11]=HIGH; pixels[1][12]=HIGH; } void drow1() { // Personalised Name Text Block pixels[1][0]=LOW; pixels[1][1]=LOW; pixels[1][2]=LOW; pixels[1][3]=LOW; pixels[1][4]=LOW; pixels[1][5]=LOW; pixels[1][6]=LOW; pixels[1][7]=LOW; pixels[1][8]=LOW; pixels[1][9]=LOW; pixels[1][10]=LOW; pixels[1][11]=LOW; pixels[1][12]=LOW; } void row2() { // Personalised Name Text Block pixels[2][0]=HIGH; pixels[2][1]=HIGH; pixels[2][2]=HIGH; pixels[2][3]=HIGH; pixels[2][4]=HIGH; pixels[2][5]=HIGH; pixels[2][6]=HIGH; pixels[2][7]=HIGH; pixels[2][8]=HIGH; pixels[2][9]=HIGH; pixels[2][10]=HIGH; pixels[2][11]=HIGH; pixels[2][12]=HIGH; } void drow2() { // Personalised Name Text Block pixels[2][0]=LOW; pixels[2][1]=LOW; pixels[2][2]=LOW; pixels[2][3]=LOW; pixels[2][4]=LOW; pixels[2][5]=LOW; pixels[2][6]=LOW; pixels[2][7]=LOW; pixels[2][8]=LOW; pixels[2][9]=LOW; pixels[2][10]=LOW; pixels[2][11]=LOW; pixels[2][12]=LOW; } void row3() { // Personalised Name Text Block pixels[3][0]=HIGH; pixels[3][1]=HIGH; pixels[3][2]=HIGH; pixels[3][3]=HIGH; pixels[3][4]=HIGH; pixels[3][5]=HIGH; pixels[3][6]=HIGH; pixels[3][7]=HIGH; pixels[3][8]=HIGH; pixels[3][9]=HIGH; pixels[3][10]=HIGH; pixels[3][11]=HIGH; pixels[3][12]=HIGH; } void drow3() { // Personalised Name Text Block pixels[3][0]=LOW; pixels[3][1]=LOW; pixels[3][2]=LOW; pixels[3][3]=LOW; pixels[3][4]=LOW; pixels[3][5]=LOW; pixels[3][6]=LOW; pixels[3][7]=LOW; pixels[3][8]=LOW; pixels[3][9]=LOW; pixels[3][10]=LOW; pixels[3][11]=LOW; pixels[3][12]=LOW; } void row4() { // Personalised Name Text Block pixels[4][0]=HIGH; pixels[4][1]=HIGH; pixels[4][2]=HIGH; pixels[4][3]=HIGH; pixels[4][4]=HIGH; pixels[4][5]=HIGH; pixels[4][6]=HIGH; pixels[4][7]=HIGH; pixels[4][8]=HIGH; pixels[4][9]=HIGH; pixels[4][10]=HIGH; pixels[4][11]=HIGH; pixels[4][12]=HIGH; } void drow4() { // Personalised Name Text Block pixels[4][0]=LOW; pixels[4][1]=LOW; pixels[4][2]=LOW; pixels[4][3]=LOW; pixels[4][4]=LOW; pixels[4][5]=LOW; pixels[4][6]=LOW; pixels[4][7]=LOW; pixels[4][8]=LOW; pixels[4][9]=LOW; pixels[4][10]=LOW; pixels[4][11]=LOW; pixels[4][12]=LOW; } void row5() { // Personalised Name Text Block pixels[5][0]=HIGH; pixels[5][1]=HIGH; pixels[5][2]=HIGH; pixels[5][3]=HIGH; pixels[5][4]=HIGH; pixels[5][5]=HIGH; pixels[5][6]=HIGH; pixels[5][7]=HIGH; pixels[5][8]=HIGH; pixels[5][9]=HIGH; pixels[5][10]=HIGH; pixels[5][11]=HIGH; pixels[5][12]=HIGH; } void drow5() { // Personalised Name Text Block pixels[5][0]=LOW; pixels[5][1]=LOW; pixels[5][2]=LOW; pixels[5][3]=LOW; pixels[5][4]=LOW; pixels[5][5]=LOW; pixels[5][6]=LOW; pixels[5][7]=LOW; pixels[5][8]=LOW; pixels[5][9]=LOW; pixels[5][10]=LOW; pixels[5][11]=LOW; pixels[5][12]=LOW; } void row6() { // Personalised Name Text Block pixels[6][0]=HIGH; pixels[6][1]=HIGH; pixels[6][2]=HIGH; pixels[6][3]=HIGH; pixels[6][4]=HIGH; pixels[6][5]=HIGH; pixels[6][6]=HIGH; pixels[6][7]=HIGH; pixels[6][8]=HIGH; pixels[6][9]=HIGH; pixels[6][10]=HIGH; pixels[6][11]=HIGH; pixels[6][12]=HIGH; } void drow6() { // Personalised Name Text Block pixels[6][0]=LOW; pixels[6][1]=LOW; pixels[6][2]=LOW; pixels[6][3]=LOW; pixels[6][4]=LOW; pixels[6][5]=LOW; pixels[6][6]=LOW; pixels[6][7]=LOW; pixels[6][8]=LOW; pixels[6][9]=LOW; pixels[6][10]=LOW; pixels[6][11]=LOW; pixels[6][12]=LOW; } void row7() { // Personalised Name Text Block pixels[7][0]=HIGH; pixels[7][1]=HIGH; pixels[7][2]=HIGH; pixels[7][3]=HIGH; pixels[7][4]=HIGH; pixels[7][5]=HIGH; pixels[7][6]=HIGH; pixels[7][7]=HIGH; pixels[7][8]=HIGH; pixels[7][9]=HIGH; pixels[7][10]=HIGH; pixels[7][11]=HIGH; pixels[7][12]=HIGH; } void drow7() { // Personalised Name Text Block pixels[7][0]=LOW; pixels[7][1]=LOW; pixels[7][2]=LOW; pixels[7][3]=LOW; pixels[7][4]=LOW; pixels[7][5]=LOW; pixels[7][6]=LOW; pixels[7][7]=LOW; pixels[7][8]=LOW; pixels[7][9]=LOW; pixels[7][10]=LOW; pixels[7][11]=LOW; pixels[7][12]=LOW; } void row8() { // Personalised Name Text Block pixels[8][0]=HIGH; pixels[8][1]=HIGH; pixels[8][2]=HIGH; pixels[8][3]=HIGH; pixels[8][4]=HIGH; pixels[8][5]=HIGH; pixels[8][6]=HIGH; pixels[8][7]=HIGH; pixels[8][8]=HIGH; pixels[8][9]=HIGH; pixels[8][10]=HIGH; pixels[8][11]=HIGH; pixels[8][12]=HIGH; } void drow8() { // Personalised Name Text Block pixels[8][0]=LOW; pixels[8][1]=LOW; pixels[8][2]=LOW; pixels[8][3]=LOW; pixels[8][4]=LOW; pixels[8][5]=LOW; pixels[8][6]=LOW; pixels[8][7]=LOW; pixels[8][8]=LOW; pixels[8][9]=LOW; pixels[8][10]=LOW; pixels[8][11]=LOW; pixels[8][12]=LOW; } void row9() { // Personalised Name Text Block pixels[9][0]=HIGH; pixels[9][1]=HIGH; pixels[9][2]=HIGH; pixels[9][3]=HIGH; pixels[9][4]=HIGH; pixels[9][5]=HIGH; pixels[9][6]=HIGH; pixels[9][7]=HIGH; pixels[9][8]=HIGH; pixels[9][9]=HIGH; pixels[9][10]=HIGH; pixels[9][11]=HIGH; pixels[9][12]=HIGH; } void drow9() { // Personalised Name Text Block pixels[9][0]=LOW; pixels[9][1]=LOW; pixels[9][2]=LOW; pixels[9][3]=LOW; pixels[9][4]=LOW; pixels[9][5]=LOW; pixels[9][6]=LOW; pixels[9][7]=LOW; pixels[9][8]=LOW; pixels[9][9]=LOW; pixels[9][10]=LOW; pixels[9][11]=LOW; pixels[9][12]=LOW; } void row10() { // Personalised Name Text Block pixels[10][0]=HIGH; pixels[10][1]=HIGH; pixels[10][2]=HIGH; pixels[10][3]=HIGH; pixels[10][4]=HIGH; pixels[10][5]=HIGH; pixels[10][6]=HIGH; pixels[10][7]=HIGH; pixels[10][8]=HIGH; pixels[10][9]=HIGH; pixels[10][10]=HIGH; pixels[10][11]=HIGH; pixels[10][12]=HIGH; } void drow10() { // Personalised Name Text Block pixels[10][0]=LOW; pixels[10][1]=LOW; pixels[10][2]=LOW; pixels[10][3]=LOW; pixels[10][4]=LOW; pixels[10][5]=LOW; pixels[10][6]=LOW; pixels[10][7]=LOW; pixels[10][8]=LOW; pixels[10][9]=LOW; pixels[10][10]=LOW; pixels[10][11]=LOW; pixels[10][12]=LOW; } void row11() { // Personalised Name Text Block pixels[11][0]=HIGH; pixels[11][1]=HIGH; pixels[11][2]=HIGH; pixels[11][3]=HIGH; pixels[11][4]=HIGH; pixels[11][5]=HIGH; pixels[11][6]=HIGH; pixels[11][7]=HIGH; pixels[11][8]=HIGH; pixels[11][9]=HIGH; pixels[11][10]=HIGH; pixels[11][11]=HIGH; pixels[11][12]=HIGH; } void drow11() { // Personalised Name Text Block pixels[11][0]=LOW; pixels[11][1]=LOW; pixels[11][2]=LOW; pixels[11][3]=LOW; pixels[11][4]=LOW; pixels[11][5]=LOW; pixels[11][6]=LOW; pixels[11][7]=LOW; pixels[11][8]=LOW; pixels[11][9]=LOW; pixels[11][10]=LOW; pixels[11][11]=LOW; pixels[11][12]=LOW; } void row12() { // Personalised Name Text Block pixels[12][0]=HIGH; pixels[12][1]=HIGH; pixels[12][2]=HIGH; pixels[12][3]=HIGH; pixels[12][4]=HIGH; pixels[12][5]=HIGH; pixels[12][6]=HIGH; pixels[12][7]=HIGH; pixels[12][8]=HIGH; pixels[12][9]=HIGH; pixels[12][10]=HIGH; pixels[12][11]=HIGH; pixels[12][12]=HIGH; } void drow12() { // Personalised Name Text Block pixels[12][0]=LOW; pixels[12][1]=LOW; pixels[12][2]=LOW; pixels[12][3]=LOW; pixels[12][4]=LOW; pixels[12][5]=LOW; pixels[12][6]=LOW; pixels[12][7]=LOW; pixels[12][8]=LOW; pixels[12][9]=LOW; pixels[12][10]=LOW; pixels[12][11]=LOW; pixels[12][12]=LOW; } // Function to display each pixel systematically in array void refreshScreen() { // iterate over the rows (Cathodes): for (int thisRow = 0; thisRow < 13; thisRow++) { // take the row pin (Cathode) low: digitalWrite(row[thisRow], LOW); // iterate over the cols (Anodes): for (int thisCol = 0; thisCol < 13; thisCol++) { // get the state of the current pixel; int thisPixel = pixels[thisRow][thisCol]; // when the row is Low and the col is High, // the LED where they meet turns on: digitalWrite(col[thisCol], thisPixel); if (thisPixel == HIGH) { // Delay to make LEDs Brighter delayMicroseconds(dimmer); // Delay to make LEDs Brighter // turn the pixel off: digitalWrite(col[thisCol], LOW); delay(10); } } // take the row pin high to turn off the whole row: digitalWrite(row[thisRow], HIGH); // delay (1); } }