/* Word Clock By Tech Kiwi May 2015 The goal of this project is to build a bedside word clock that is personalised with an Alarm V2 0.7 Add Alarm Tone, Save Alarm time to EEPROM when Set to ON so will be retained when power removed ---------- 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 * * 100 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 #include // 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 = 10; // 300 seems to be the brightest before flicker detected // Refresh variable for RTC // cursor position: int x = 5; int y = 5; // Alarm Variables int clockmode = 0; // Flag where 0 = time mode, 1 = set time, 2 = set alarm int alarmstatus = 0; // flag where 0 is off and 1 is on int alarmhour = 0; // hour of alarm setting int alarmminute = 0; // Minute of alarm setting byte ahour; //Byte variable for hour byte amin; //Byte variable for minute 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(7, INPUT); // Set time pinMode(8, INPUT); // Increment alarm/clock time pinMode(9, INPUT); // Decrement alarm/clock time // Read previously Stored Alarm From EEPROM } void loop() { // Read the current date and time from the RTC if ((clockmode != 2)) { if ((timeStatus() == timeSet) ) { UpdateDisp(); // hmdmDisplay(); } else { Serial.println("The time has not been set. Please run the Time"); Serial.println("TimeRTCSet example, or DS1307RTC SetTime example."); Serial.println(); delay(4000); } } // Check the ambient light and adjust LED brightness to suit LDR = analogRead(A7); if (LDR <= 100) { dimmer = 1; // Take LDR output and use as basis for dimming display } else { dimmer = LDR/4; // Take LDR output and use as basis for dimming display } // Read Buttons to determine ClockMode // 0 = Time Mode // - This is the normal operating mode for the clock and denoted by full normal display of time // // 1 = Set Time // - From Time Mode, enter this mode by pushing and holding the black button - the current time will appear however the AM and PM indicator will appear and only word "TIME" displayed // - Use Red up and down arrows to increment & decrement time // - Exit to Time Mode by pushing the black button // 2 = Set Alarm // - From Time Mode, enter this mode by pushing and holding both Red Buttons - the current Alarm time will appear however the AM and PM indicator will appear and only word "AL" displayed // - Use Red up and down arrows to increment & decrement Alarm Time // - To enable the Alarm press both Red Buttons - the word "ON" will appear on the screen // - Exit to Time Mode by pushing the black Button // Resturn to Main Menue // - In the event the user gets lost if all three buttons are pushed together for 3 seconds they are returned to Time Mode // First Step is to read all buttons and determine what mode is being selected then call the appropriate Mode Routine // Use clockmode varialble to represent this 0 = time mode, 1 = set time, 2 = set alarm if((digitalRead(7) == LOW) || (digitalRead(8) == LOW) || (digitalRead(9) == LOW)){ delay(100); // Debounce by waiting then checking again // Disarm Alarm if any button pushed while alarm is sounding if ( alarmhour == hour() && alarmminute == minute() && alarmstatus == 1) { alarmstatus = 0; // Disarm the alarm } // Enter Time Set Mode :::::: Test for Time Mode clockmode == 0 then if((digitalRead(7) == LOW) && (digitalRead(8) == HIGH) && (digitalRead(9) == HIGH) && (clockmode == 0)){ delay(50); // Debounce by waiting then checking again if((digitalRead(7) == LOW) && (digitalRead(8) == HIGH) && (digitalRead(9) == HIGH) && (clockmode == 0)){ clockmode = 1; // Set the clock into Time Set Mode blankscreen(); // Blank the screen // Draw TIME SET on screen for 0.5 seconds for (int r = 0; r < 800; r++) { timeset(); // Display Time to indicate the time setmode sett(); refreshScreen(); } } delay(1000); // Ensure time delay to detect switch off between depressions dsett(); } // Exit Time Set Mode ::::: Test for Time Mode clockmode == 1 then if((digitalRead(7) == LOW) && (digitalRead(8) == HIGH) && (digitalRead(9) == HIGH) && (clockmode == 1)){ delay(50); // Debounce by waiting then checking again if((digitalRead(7) == LOW) && (digitalRead(8) == HIGH) && (digitalRead(9) == HIGH) && (clockmode == 1)){ clockmode = 0; // Set the clock into Set Alarm Mode blankscreen(); // Blank the screen } delay(1000); // Ensure time delay to detect switch off between depressions } // Enter Alarm Set Mode :::::: Test for Time Mode clockmode == 0 then if((digitalRead(7) == HIGH) && (digitalRead(8) == LOW) && (digitalRead(9) == LOW) && (clockmode == 0)){ delay(50); // Debounce by waiting then checking again if((digitalRead(7) == HIGH) && (digitalRead(8) == LOW) && (digitalRead(9) == LOW) && (clockmode == 0)){ clockmode = 2; // Set the clock into Set Alarm Mode blankscreen(); // Blank the screen // Draw AL SET on screen for 0.5 seconds for (int r = 0; r < 800; r++) { al(); // Display Time to indicate the time setmode sett(); // read a byte from the current address of the EEPROM ahour = EEPROM.read(100); alarmhour = (int)ahour; if (alarmhour >24 ) { alarmhour = 0; } amin = EEPROM.read(101); alarmminute = (int)amin; if (alarmminute >60 ) { alarmminute = 0; } // Display ON if Alarm Armed if ( alarmstatus == 1) { armed(); } else{ darmed(); } refreshScreen(); } } delay(1000); // Ensure time delay to detect switch off between depressions dsett(); } // Exit Alarm Set Mode ::::: Test for Time Mode clockmode == 2 then if((digitalRead(7) == LOW) && (digitalRead(8) == HIGH) && (digitalRead(9) == HIGH) && (clockmode == 2)){ delay(50); // Debounce by waiting then checking again if((digitalRead(7) == LOW) && (digitalRead(8) == HIGH) && (digitalRead(9) == HIGH) && (clockmode == 2)){ clockmode = 0; // Set the clock into Set Alarm Mode blankscreen(); // Blank the screen } delay(1000); // Ensure time delay to detect switch off between depressions } // Increment Alarm Time ::::: Test for Time Mode clockmode == 2 then if((digitalRead(7) == HIGH) && (digitalRead(8) == LOW) && (digitalRead(9) == HIGH) && (clockmode == 2)){ delay(50); // Debounce by waiting then checking again if((digitalRead(7) == HIGH) && (digitalRead(8) == LOW) && (digitalRead(9) == HIGH) && (clockmode == 2)){ alarmminute = alarmminute + 5; if ( alarmminute > 60) { alarmhour = alarmhour + 1; // Increment alarmhour alarmminute = 0; // and reset minute to zero if ( alarmhour == 24 ) { alarmhour = 0; // } } delay(50); // Ensure time delay to detect switch off between depressions } } // Decrement Alarm Time ::::: Test for Time Mode clockmode == 2 then if((digitalRead(7) == HIGH) && (digitalRead(8) == HIGH) && (digitalRead(9) == LOW) && (clockmode == 2)){ delay(50); // Debounce by waiting then checking again if((digitalRead(7) == HIGH) && (digitalRead(8) == HIGH) && (digitalRead(9) == LOW) && (clockmode == 2)){ alarmminute = alarmminute - 5; if ( alarmminute < 0) { alarmhour = alarmhour - 1; // Increment alarmhour alarmminute = 55; // and reset minute to zero } if ( alarmhour < 0 ) { alarmhour = 23; } } delay(50); // Ensure time delay to detect switch off between depressions } } // Decrement Clock Time if((digitalRead(7) == HIGH) && (digitalRead(8) == HIGH) && (digitalRead(9) == LOW) && (clockmode == 1)){ delay(50); // Debounce by waiting then checking again if((digitalRead(7) == HIGH) && (digitalRead(8) == HIGH) && (digitalRead(9) == LOW) && (clockmode == 1)){ if(timeStatus() == timeSet){ adjustTime(-60); RTC.set(now() -60); blankscreen(); // Blank out all LEDs } } delay(50); // Ensure time delay to detect switch off between depressions } // Increment Clock Time if((digitalRead(7) == HIGH) && (digitalRead(8) == LOW) && (digitalRead(9) == HIGH) && (clockmode == 1)){ delay(50); // Debounce by waiting then checking again if((digitalRead(7) == HIGH) && (digitalRead(8) == LOW) && (digitalRead(9) == HIGH) && (clockmode == 1)){ if(timeStatus() == timeSet){ adjustTime(60); RTC.set(now() + 60); blankscreen(); // Blank out all LEDs } } delay(50); // Ensure time delay to detect switch off between depressions } // ARM Alarm if((digitalRead(7) == HIGH) && (digitalRead(8) == LOW) && (digitalRead(9) == LOW) && (clockmode == 2)){ delay(50); // Debounce by waiting then checking again if((digitalRead(7) == HIGH) && (digitalRead(8) == LOW) && (digitalRead(9) == LOW) && (clockmode == 2)){ if ( alarmstatus == 0){ alarmstatus = 1; // ARM Alarm // Wtite the Alarm Time to EEPROM so it can be stored when powered off //alarmhour = (int)ahour; ahour = (byte)alarmhour; amin = (byte)alarmminute; EEPROM.write(100, ahour); EEPROM.write(101, amin); } else{ alarmstatus = 0; // DISARM Alarm } delay(200); // Ensure time delay to detect switch off between depressions } } // In normalclockmode read time and draw the screen if (clockmode == 0) { // Draw time into Array textblock(); // Name always on display itis(); // IT IS always on display } // In Set Time Mode read the Time and display so it can be modified if (clockmode == 1) { timeset(); // Display Time to indicate the time setmode if(hour() <= 11){ // Display AM am(); } else { // Delete AM dam(); } } // In Set Alarm Mode read the Alarm time and draw the screen if (clockmode == 2) { // draw the screen: if(alarmhour <= 11){ // Display AM am(); } else { // Delete AM dam(); } AlarmDisp(); //UpdateDisp(); al(); // Display ON if Alarm Armed if ( alarmstatus == 1) { armed(); } else { darmed(); } } // Sound Alarm if set and time is correct if ( alarmhour == hour() && alarmminute == minute() && alarmstatus == 1 && clockmode == 0) { for (int g = 300; g < 1500;g++ ) { tone(10, g, 20); // delayMicroseconds(1000); refreshScreen(); } tone(10, 1500, 200); delay(1000); } // draw the screen: refreshScreen(); // delay(250); } /* 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 UpdateDisp() { // "Display the time based on current RTC data" if((minute()>4) && (minute()<10)){ // FIVE MINUTES fivemins(); past(); dTo(); dtenmins(); dquarter(); dtwenty(); dhalf(); doclock(); } if((minute()>9) && (minute()<15)) { //TEN MINUTES; tenmins(); past(); dTo(); dfivemins(); dquarter(); dtwenty(); dhalf(); doclock(); } if((minute()>14) && (minute()<20)) { // QUARTER quarter(); past(); dfivemins(); dTo(); dtenmins(); dtwenty(); dhalf(); doclock(); } if((minute()>19) && (minute()<25)) { //TWENTY MINUTES twenty(); past(); dfivemins(); dTo(); dtenmins(); dquarter(); dhalf(); doclock(); } if((minute()>24) && (minute()<30)) { //TWENTY FIVE twentyfive(); past(); dTo(); dtenmins(); dquarter(); dhalf(); doclock(); } if((minute()>29) && (minute()<35)) { // HALF half(); past(); dfivemins(); dTo(); dtenmins(); dquarter(); dtwenty(); doclock(); } if((minute()>34) && (minute()<40)) { //TWENTY FIVE TO twentyfive(); To(); dpast(); dtenmins(); dquarter(); dhalf(); doclock(); } if((minute()>39) && (minute()<45)) { //TWENTY TO twenty(); To(); dfivemins(); dpast(); dtenmins(); dquarter(); dhalf(); doclock(); } if((minute()>44) && (minute()<50)) { // QUARTER TO quarter(); To(); dfivemins(); dpast(); dtenmins(); dtwenty(); dhalf(); doclock(); } if((minute()>49) && (minute()<55)){ // TEN TO tenmins(); To(); dfivemins(); dpast(); dquarter(); dtwenty(); dhalf(); doclock(); } if(minute()>54){ // FIVE TO fivemins(); To(); dpast(); dtenmins(); dquarter(); dtwenty(); dhalf(); doclock(); } if(minute()<5){ // OClock oclock(); dfivemins(); dpast(); dTo(); dtenmins(); dquarter(); dtwenty(); dhalf(); } // Display correct Hour for the clock // Do this by determining if after 30mins past the hour if(minute()<35){ // Hours on the clock if 34 minutes or less past the hour if((hour()==1)||(hour()==13)){ // One Oclock one(); dtwelve(); dtwo(); } if((hour()==2)||(hour()==14)){ // Two Oclock two(); done(); dthree(); } if((hour()==3)||(hour()==15)){ // Three Oclock three(); dtwo(); dfour(); } if((hour()==4)||(hour()==16)){ // four Oclock four(); dthree(); dfive(); } if((hour()==5)||(hour()==17)){ // five Oclock five(); dfour(); dsix(); } if((hour()==6)||(hour()==18)){ // Six Oclock six(); dfive(); dseven(); } if((hour()==7)||(hour()==19)){ // Seven Oclock seven(); dsix(); deight(); } if((hour()==8)||(hour()==20)){ // Eight Oclock eight(); dseven(); dnine(); } if((hour()==9)||(hour()==21)){ // Nine Oclock nine(); deight(); dten(); } if((hour()==10)||(hour()==22)){ // Ten Oclock ten(); dnine(); deleven(); } if((hour()==11)||(hour()==23)){ // Eleven Oclock eleven(); dten(); dtwelve(); } if((hour()==12)||(hour()==0)){ // Twelve Oclock twelve(); deleven(); done(); } } else { // Hours on the clock if 35 minutes or more past the hour if((hour()==1)||(hour()==13)){ // To two Oclock two(); done(); dthree(); } if((hour()==2)||(hour()==14)){ // To three Oclock three(); dtwo(); dfour(); } if((hour()==3)||(hour()==15)){ // To four Oclock four(); dthree(); dfive(); } if((hour()==4)||(hour()==16)){ // To five Oclock five(); dfour(); dsix(); } if((hour()==5)||(hour()==17)){ // To six Oclock six(); dfive(); dseven(); } if((hour()==6)||(hour()==18)){ // To seven Oclock seven(); dsix(); deight(); } if((hour()==7)||(hour()==19)){ // To eight Oclock eight(); dseven(); dnine(); } if((hour()==8)||(hour()==20)){ // To nine Oclock nine(); hi(); // Display hi on screen deight(); dten(); } if((hour()==9)||(hour()==21)){ // To ten Oclock ten(); dnine(); deleven(); dhi(); // Delete hi from screen } if((hour()==10)||(hour()==22)){ // To eleven Oclock eleven(); dten(); dtwelve(); } if((hour()==11)||(hour()==23)){ // To twelve Oclock twelve(); deleven(); done(); } if((hour()==12)||(hour()==0)){ // To one Oclock one(); dtwelve(); dtwo(); } } // Change the Birthday Date here so that you can pesonalise for recipient // Happy Birthday 31st October if((month()==10)&&(day()==17)){ happybirthday(); } else { dhappybirthday(); } // Display Hi at 4pm if ((hour()==16)) { hi(); } else { dhi(); } // Good morning if ((hour()>=6) && (hour()<=9)) { goodmorning(); } else { dgoodmorning(); } // Carpe Diem 10am-12pm if ((hour()>=10) && (hour()<=12)) { carpediem(); } else { dcarpediem(); } // Time to Sleep if (hour()>=23) { timetosleep(); } else { dtimetosleep(); } /* */ } // DISPLAY ROUTINES TO TURN ON LEDS void oclock() { // "oclock" 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 twelve() { // "twelve oclock" pixels[12][0]=HIGH; pixels[12][1]=HIGH; pixels[12][2]=HIGH; pixels[12][3]=HIGH; pixels[12][4]=HIGH; pixels[12][5]=HIGH; } void eleven() { // "eleven oclock" 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 ten() { // "ten" pixels[11][4]=HIGH; pixels[11][5]=HIGH; pixels[11][6]=HIGH; } void nine() { // "nine" pixels[11][0]=HIGH; pixels[11][1]=HIGH; pixels[11][2]=HIGH; pixels[11][3]=HIGH; } void eight() { // "eight" pixels[10][8]=HIGH; pixels[10][9]=HIGH; pixels[10][10]=HIGH; pixels[10][11]=HIGH; pixels[10][12]=HIGH; } void seven() { // "seven o'clock" pixels[10][3]=HIGH; pixels[10][4]=HIGH; pixels[10][5]=HIGH; pixels[10][6]=HIGH; pixels[10][7]=HIGH; } void six() { // "six o'clock" pixels[10][0]=HIGH; pixels[10][1]=HIGH; pixels[10][2]=HIGH; } void five() { // "five o'clock" pixels[9][7]=HIGH; pixels[9][8]=HIGH; pixels[9][9]=HIGH; pixels[9][10]=HIGH; } void four() { // "Four o'clock" pixels[9][3]=HIGH; pixels[9][4]=HIGH; pixels[9][5]=HIGH; pixels[9][6]=HIGH; } void two() { // "two o'clock" pixels[9][0]=HIGH; pixels[9][1]=HIGH; pixels[9][2]=HIGH; } void three() { // "three o'clock" pixels[8][8]=HIGH; pixels[8][9]=HIGH; pixels[8][10]=HIGH; pixels[8][11]=HIGH; pixels[8][12]=HIGH; } void one() { // "one o'clock" pixels[8][5]=HIGH; pixels[8][6]=HIGH; pixels[8][7]=HIGH; } void past() { // past pixels[8][0]=HIGH; pixels[8][1]=HIGH; pixels[8][2]=HIGH; pixels[8][3]=HIGH; } void To() { // "To" pixels[7][5]=HIGH; pixels[7][6]=HIGH; } void fivemins() { // "Five Minutes" pixels[7][0]=HIGH; pixels[7][1]=HIGH; pixels[7][2]=HIGH; pixels[7][3]=HIGH; } void twenty() { // twenty mins 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 twentyfive() { // twenty five mins pixels[6][7]=HIGH; pixels[6][8]=HIGH; pixels[6][9]=HIGH; pixels[6][10]=HIGH; pixels[6][11]=HIGH; pixels[6][12]=HIGH; pixels[7][0]=HIGH; pixels[7][1]=HIGH; pixels[7][2]=HIGH; pixels[7][3]=HIGH; } void quarter() { // quarter 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; } void tenmins() { // "ten mins" pixels[5][10]=HIGH; pixels[5][11]=HIGH; pixels[5][12]=HIGH; } void half() { // "Half hour" pixels[5][6]=HIGH; pixels[5][7]=HIGH; pixels[5][8]=HIGH; pixels[5][9]=HIGH; } void happybirthday() { // happybirthday 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[3][8]=HIGH; pixels[3][9]=HIGH; pixels[3][10]=HIGH; pixels[3][11]=HIGH; pixels[3][12]=HIGH; } void timetosleep() { // timetosleep pixels[3][0]=HIGH; pixels[3][1]=HIGH; pixels[3][2]=HIGH; pixels[3][3]=HIGH; pixels[3][5]=HIGH; pixels[3][6]=HIGH; pixels[4][8]=HIGH; pixels[4][9]=HIGH; pixels[4][10]=HIGH; pixels[4][11]=HIGH; pixels[4][12]=HIGH; } void carpediem() { // Carpediem pixels[2][0]=HIGH; pixels[2][1]=HIGH; pixels[2][2]=HIGH; pixels[2][3]=HIGH; pixels[2][4]=HIGH; pixels[2][6]=HIGH; pixels[2][7]=HIGH; pixels[2][8]=HIGH; pixels[2][9]=HIGH; } void textblock() { // Personalised Name Text Block pixels[0][7]=HIGH; pixels[0][8]=HIGH; pixels[0][9]=HIGH; pixels[0][10]=HIGH; pixels[0][11]=HIGH; pixels[0][12]=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 am() { // "am" 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; } void timeset() { // timeset pixels[3][0]=HIGH; pixels[3][1]=HIGH; pixels[3][2]=HIGH; pixels[3][3]=HIGH; } void sett() { // sett pixels[5][5]=HIGH; pixels[6][5]=HIGH; pixels[7][5]=HIGH; } void al() { // alarm pixels[3][9]=HIGH; pixels[4][9]=HIGH; } void armed() { // ARM alarm pixels[3][6]=HIGH; pixels[3][7]=HIGH; } //----------------------------------- void itis() { // "It Is" pixels[5][0]=HIGH; pixels[5][1]=HIGH; pixels[5][3]=HIGH; pixels[5][4]=HIGH; } void goodmorning() { // Personalised Name Text Block pixels[0][0]=HIGH; pixels[0][1]=HIGH; pixels[0][2]=HIGH; pixels[0][3]=HIGH; 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; } void hi() { // Personalised Name Text Block pixels[0][4]=HIGH; pixels[0][5]=HIGH; } // DISPLAY ROUTINES TO TURN OFF LEDS void doclock() { // "oclock" pixels[12][7]=LOW; pixels[12][8]=LOW; pixels[12][9]=LOW; pixels[12][10]=LOW; pixels[12][11]=LOW; pixels[12][12]=LOW; } void dtwelve() { // "twelve oclock" pixels[12][0]=LOW; pixels[12][1]=LOW; pixels[12][2]=LOW; pixels[12][3]=LOW; pixels[12][4]=LOW; pixels[12][5]=LOW; } void deleven() { // "eleven oclock" 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 dten() { // "ten" pixels[11][4]=LOW; pixels[11][5]=LOW; pixels[11][6]=LOW; } void dnine() { // "nine" pixels[11][0]=LOW; pixels[11][1]=LOW; pixels[11][2]=LOW; pixels[11][3]=LOW; } void deight() { // "eight" pixels[10][8]=LOW; pixels[10][9]=LOW; pixels[10][10]=LOW; pixels[10][11]=LOW; pixels[10][12]=LOW; } void dseven() { // "seven o'clock" pixels[10][3]=LOW; pixels[10][4]=LOW; pixels[10][5]=LOW; pixels[10][6]=LOW; pixels[10][7]=LOW; } void dsix() { // "six o'clock" pixels[10][0]=LOW; pixels[10][1]=LOW; pixels[10][2]=LOW; } void dfive() { // "five o'clock" pixels[9][7]=LOW; pixels[9][8]=LOW; pixels[9][9]=LOW; pixels[9][10]=LOW; } void dfour() { // "Four o'clock" pixels[9][3]=LOW; pixels[9][4]=LOW; pixels[9][5]=LOW; pixels[9][6]=LOW; } void dtwo() { // "two o'clock" pixels[9][0]=LOW; pixels[9][1]=LOW; pixels[9][2]=LOW; } void dthree() { // "three o'clock" pixels[8][8]=LOW; pixels[8][9]=LOW; pixels[8][10]=LOW; pixels[8][11]=LOW; pixels[8][12]=LOW; } void done() { // "one o'clock" pixels[8][5]=LOW; pixels[8][6]=LOW; pixels[8][7]=LOW; } void dpast() { // past pixels[8][0]=LOW; pixels[8][1]=LOW; pixels[8][2]=LOW; pixels[8][3]=LOW; } void dTo() { // "To" pixels[7][5]=LOW; pixels[7][6]=LOW; } void dfivemins() { // "Five Minutes" pixels[7][0]=LOW; pixels[7][1]=LOW; pixels[7][2]=LOW; pixels[7][3]=LOW; } void dtwenty() { // twenty mins 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 dtwentyfive() { // twenty five mins pixels[6][7]=LOW; pixels[6][8]=LOW; pixels[6][9]=LOW; pixels[6][10]=LOW; pixels[6][11]=LOW; pixels[6][12]=LOW; pixels[7][0]=LOW; pixels[7][1]=LOW; pixels[7][2]=LOW; pixels[7][3]=LOW; } void dquarter() { // quarter 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; } void dtenmins() { // "ten mins" pixels[5][10]=LOW; pixels[5][11]=LOW; pixels[5][12]=LOW; } void dhalf() { // "Half hour" pixels[5][6]=LOW; pixels[5][7]=LOW; pixels[5][8]=LOW; pixels[5][9]=LOW; } void dhappybirthday() { // happybirthday 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[3][8]=LOW; pixels[3][9]=LOW; pixels[3][10]=LOW; pixels[3][11]=LOW; pixels[3][12]=LOW; } void dtimetosleep() { // timetosleep pixels[3][0]=LOW; pixels[3][1]=LOW; pixels[3][2]=LOW; pixels[3][3]=LOW; pixels[3][5]=LOW; pixels[3][6]=LOW; pixels[4][8]=LOW; pixels[4][9]=LOW; pixels[4][10]=LOW; pixels[4][11]=LOW; pixels[4][12]=LOW; } void dcarpediem() { // Carpediem pixels[2][0]=LOW; pixels[2][1]=LOW; pixels[2][2]=LOW; pixels[2][3]=LOW; pixels[2][4]=LOW; pixels[2][6]=LOW; pixels[2][7]=LOW; pixels[2][8]=LOW; pixels[2][9]=LOW; } void dtextblock() { // Personalised Name Text Block pixels[0][7]=LOW; pixels[0][8]=LOW; pixels[0][9]=LOW; pixels[0][10]=LOW; pixels[0][11]=LOW; pixels[0][12]=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 ditis() { // "It Is" pixels[5][0]=LOW; pixels[5][1]=LOW; pixels[5][3]=LOW; pixels[5][4]=LOW; } //----------------------------------- void dam() { // "am" 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; } void dtimeset() { // timeset pixels[3][0]=LOW; pixels[3][1]=LOW; pixels[3][2]=LOW; pixels[3][3]=LOW; } void dsett() { // sett pixels[5][5]=LOW; pixels[6][5]=LOW; pixels[7][5]=LOW; } void dal() { // alarm pixels[3][9]=LOW; pixels[4][9]=LOW; } void darmed() { // ARM alarm pixels[3][6]=LOW; pixels[3][7]=LOW; } //----------------------------------- void dgoodmorning() { // Personalised Name Text Block pixels[0][0]=LOW; pixels[0][1]=LOW; pixels[0][2]=LOW; pixels[0][3]=LOW; 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; } void dhi() { // Personalised Name Text Block pixels[0][4]=LOW; pixels[0][5]=LOW; } // Temp test routine void hmdmDisplay(){ // display hmdm on monitor Serial.print(hour()); Serial.println(minute()); Serial.println(day()); Serial.println(month()); } // 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); } } // take the row pin high to turn off the whole row: digitalWrite(row[thisRow], HIGH); // delay (1); } } void AlarmDisp() { // "Display the Alarm Time based on current Alarm Variable data" // hour of alarm setting - alarmhour // Minute of alarm setting - alarmminute if((alarmminute>4) && (alarmminute<10)){ // FIVE MINUTES fivemins(); past(); dTo(); dtenmins(); dquarter(); dtwenty(); dhalf(); doclock(); } if((alarmminute>9) && (alarmminute<15)) { //TEN MINUTES; tenmins(); past(); dTo(); dfivemins(); dquarter(); dtwenty(); dhalf(); doclock(); } if((alarmminute>14) && (alarmminute<20)) { // QUARTER quarter(); past(); dfivemins(); dTo(); dtenmins(); dtwenty(); dhalf(); doclock(); } if((alarmminute>19) && (alarmminute<25)) { //TWENTY MINUTES twenty(); past(); dfivemins(); dTo(); dtenmins(); dquarter(); dhalf(); doclock(); } if((alarmminute>24) && (alarmminute<30)) { //TWENTY FIVE twentyfive(); past(); dTo(); dtenmins(); dquarter(); dhalf(); doclock(); } if((alarmminute>29) && (alarmminute<35)) { // HALF half(); past(); dfivemins(); dTo(); dtenmins(); dquarter(); dtwenty(); doclock(); } if((alarmminute>34) && (alarmminute<40)) { //TWENTY FIVE TO twentyfive(); To(); dpast(); dtenmins(); dquarter(); dhalf(); doclock(); } if((alarmminute>39) && (alarmminute<45)) { //TWENTY TO twenty(); To(); dfivemins(); dpast(); dtenmins(); dquarter(); dhalf(); doclock(); } if((alarmminute>44) && (alarmminute<50)) { // QUARTER TO quarter(); To(); dfivemins(); dpast(); dtenmins(); dtwenty(); dhalf(); doclock(); } if((alarmminute>49) && (alarmminute<55)){ // TEN TO tenmins(); To(); dfivemins(); dpast(); dquarter(); dtwenty(); dhalf(); doclock(); } if(alarmminute>54){ // FIVE TO fivemins(); To(); dpast(); dtenmins(); dquarter(); dtwenty(); dhalf(); doclock(); } if(alarmminute<5){ // OClock oclock(); dfivemins(); dpast(); dTo(); dtenmins(); dquarter(); dtwenty(); dhalf(); } // Display correct Hour for the clock // Do this by determining if after 30mins past the hour if(alarmminute<35){ // Hours on the clock if 34 minutes or less past the hour if((alarmhour==1)||(alarmhour==13)){ // One Oclock one(); dtwelve(); dtwo(); } if((alarmhour==2)||(alarmhour==14)){ // Two Oclock two(); done(); dthree(); } if((alarmhour==3)||(alarmhour==15)){ // Three Oclock three(); dtwo(); dfour(); } if((alarmhour==4)||(alarmhour==16)){ // four Oclock four(); dthree(); dfive(); } if((alarmhour==5)||(alarmhour==17)){ // five Oclock five(); dfour(); dsix(); } if((alarmhour==6)||(alarmhour==18)){ // Six Oclock six(); dfive(); dseven(); } if((alarmhour==7)||(alarmhour==19)){ // Seven Oclock seven(); dsix(); deight(); } if((alarmhour==8)||(alarmhour==20)){ // Eight Oclock eight(); dseven(); dnine(); } if((alarmhour==9)||(alarmhour==21)){ // Nine Oclock nine(); deight(); dten(); } if((alarmhour==10)||(alarmhour==22)){ // Ten Oclock ten(); dnine(); deleven(); } if((alarmhour==11)||(alarmhour==23)){ // Eleven Oclock eleven(); dten(); dtwelve(); } if((alarmhour==12)||(alarmhour==0)){ // Twelve Oclock twelve(); deleven(); done(); dgoodmorning; } } else { // Hours on the clock if 35 minutes or more past the hour if((alarmhour==1)||(alarmhour==13)){ // To two Oclock two(); done(); dthree(); } if((alarmhour==2)||(alarmhour==14)){ // To three Oclock three(); dtwo(); dfour(); } if((alarmhour==3)||(alarmhour==15)){ // To four Oclock four(); dthree(); dfive(); } if((alarmhour==4)||(alarmhour==16)){ // To five Oclock five(); dfour(); dsix(); } if((alarmhour==5)||(alarmhour==17)){ // To six Oclock six(); dfive(); dseven(); } if((alarmhour==6)||(alarmhour==18)){ // To seven Oclock seven(); dsix(); deight(); } if((alarmhour==7)||(alarmhour==19)){ // To eight Oclock eight(); dseven(); dnine(); } if((alarmhour==8)||(alarmhour==20)){ // To nine Oclock nine(); // hi(); // Display hi on screen deight(); dten(); } if((alarmhour==9)||(alarmhour==21)){ // To ten Oclock ten(); dnine(); deleven(); dhi(); // Delete hi from screen } if((alarmhour==10)||(alarmhour==22)){ // To eleven Oclock eleven(); dten(); dtwelve(); } if((alarmhour==11)||(alarmhour==23)){ // To twelve Oclock twelve(); deleven(); done(); } if((alarmhour==12)||(alarmhour==0)){ // To one Oclock one(); dtwelve(); dtwo(); dgoodmorning; } } }