Components and supplies
Power Connector
DSD TECH HM-10 Bluetooth 4.0
Power Block
LM 2596S DC to DC Voltage Regulator
JST Connectors
MP1584EN DC to DC Voltage Regulator
Tactile Switch
Capacitor 1000 µF
Resistor 330 ohm
Mini Speaker 4Ω (3W)
Pin Headers
Arduino Nano Every
LED Matrix Panel
Resistor 5.1K
Diode 1N5404
Real Time Clock DS3231
Hex Stand Offs
Resistor 2.21k ohm
Adafruit Sound FX Board 2Mb
USB Panel Lead
Push Button Switch
Resistor 10k ohm
Tools and machines
Soldering iron (generic)
Solder Wire, Lead Free
Project description
Code
Digital Alarm Clock
arduino
Main sketch for the Digital Alarm Clock
1/* 2 Name: Swear_Box.ino - NeoPixel Clock using a DS3231 3 Created: 7/14/2020 2:23:26 PM 4 5 Original code kindly referenced from: Tiziano Bianchettin 6 7 Serioulsy hacked about by: Christopher Cooper in 2020 8*/ 9 10// Libraries. 11 12#include <avr/pgmspace.h> // Special memory library. 13#include <DS3231.h> // RTC library. 14#include <Wire.h> // I2C library. 15#include <EEPROM.h> // EEPROM library. 16#include <SoftwareSerial.h> // Software serial library. 17 18// Declare real time clock object. 19 20DS3231 rtc; 21 22// Configure software serial pins. 23 24SoftwareSerial s1Serial(20, 21); // RX, TX, Bluetooth module. 25 26// Adafruit NeoPixel libraries. 27 28#include <Adafruit_GFX.h> 29#include <Adafruit_NeoMatrix.h> 30#include <Adafruit_NeoPixel.h> 31 32// Configure NeoPixel. 33 34#define PIXEL_COUNT 320 // Total number of NeoPixels. 35#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels. 36 37// Declare NeoPixel matrix object. 38 39Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, 5, 1, 6, 40 41 NEO_MATRIX_TOP + NEO_MATRIX_LEFT + 42 NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE, 43 NEO_RGB + NEO_KHZ800); 44 45// Argument 1 = Number of rows in NeoPixel array. 46// Argument 2 = Number of columns in NeoPixel array. 47// Argument 3 = Number of horizontal tiles. 48// Argument 4 = Number of vertical tiles. 49// Argument 5 = Arduino pin number. 50// From adafruit help for tiled arrays matrixWidth, matrixHeight, tilesX, tilesY, pin, matrixType, ledType); 51 52// Configure NeoPixel colours and variables. 53 54const uint16_t colors[8] = { 55 matrix.Color(255, 0, 0), 56 matrix.Color(0, 255, 0), 57 matrix.Color(255, 255, 0), 58 matrix.Color(0, 0, 255), 59 matrix.Color(255, 0, 255), 60 matrix.Color(0, 255, 255), 61 matrix.Color(255, 255, 255) 62}; 63 64char colorArray[9][8] = { "Green", "Red", "Yellow", "Blue", "Teal", "Purple", "White" }; 65 66byte pixelPerChar = 6; // Width of standard font characters is 8X6 pixels. 67int x = matrix.width(); // Width of the NeoPixel display. 68byte speedSet = 10; // Scrolling text speed. 69byte tempSpeedSet = 50; // Used for reversing speed variable. 70byte colorSet = 6; // Color selection. 71byte brightnessSet = 5; // Display brightness. 72 73// Configure buttons & pins. 74 75const byte intPinAlarmOneSet = 4; // Buttom to set alarm one. 76const byte intPinMenu = 5; // Button SET MENU' using Interupt. 77const byte intPinScrollingDate = 8; // Button to call display Date Function using Interupt. 78const byte intPinWhite = 9; // Button to call blue random strings using Interupt. 79const byte intPinAlarmOneSleep = 10; // Sleep, cancel alarm one. 80 81const byte bPlus = 2; // Button + 82const byte bMinus = 3; // Button - 83const byte vPlus = A0; // Volume + 84const byte vMinus = 13; // Volume - 85 86const byte Mahnamahna = A1; // The Muppets Mahnamaha pin trigger. 87const byte GSTQ = A2; // God save the queen anthem pin trgger. 88const byte SSB = A3; // Star spangled banner anthem pin trigger. 89 90// Global variables. 91 92boolean debug = false; // Debugging flag for serial output. 93 94byte volumeSet = 25; // Volume setting. 95bool musicScroll = false; // Music menu scroll prevention. 96char musicArray[4][25] = { "God Save the Queen", "Star Spangled Banner" , "The Muppets - Mahnamahna" }; // Music track array. 97byte musicSet = 0; // Music setting menu. 98byte musicPlay = A1; // Music setting menu. 99 100int buttonDelay = 200; 101 102bool h12; // 12 / 24 hour clock flag from RTC. 103bool PM; // AM / PM clock flag from RTC. 104bool set1224 = false; // 12 / 24 hour clock flag. 105bool Century = false; // Century flag from RTC. 106bool resetRTC = false; // Reset RTC flag. 107bool resetWelcome = false; // Reset welcome message flag. 108 109byte alarmBits; // Alarm variables. 110bool alarmDy; 111bool alarmH12; 112bool alarmPm; 113 114bool alarmOneState = false; // Sleep variables. 115bool setSleepStart = false; 116byte sleepStart; 117byte sleepSet = 5; 118 119#define ALRM1_MATCH_EVERY_SEC 0b1111 // Once a second. 120#define ALRM1_MATCH_SEC 0b1110 // When seconds match. 121#define ALRM1_MATCH_MIN_SEC 0b1100 // When minutes and seconds match. 122#define ALRM1_MATCH_HR_MIN_SEC 0b1000 // When hours, minutes, and seconds match. 123 124#define ALRM2_ONCE_PER_MIN 0b111 // Once per minute (00 seconds of every minute). 125#define ALRM2_MATCH_MIN 0b110 // When minutes match. 126#define ALRM2_MATCH_HR_MIN 0b100 // When hours and minutes match. 127 128byte hourSet; // Set time variables. 129byte minSet; 130byte yearSet; 131byte monthSet; 132byte daySet; 133byte dowSet; 134 135byte alarmOneHourSet; // Set alarm one time variables. 136byte alarmOneMinSet; 137byte alarmOneSecSet = 0; 138byte alarmOneYearSet; 139byte alarmOneMonthSet; 140byte alarmOneDaySet; 141byte alarmOneDowSet; 142 143byte alarmOneSch; 144char* alarmSchArray[6] = { "Off" , "Once" , "Daily" , "M - F" , "S - S"}; // off, once, daily, weekday & weekend. 145 146long randNumber; 147 148volatile byte menu = 0; // Menu system variable for scrolling through options. 149 150int rtcArray[8]; // RTC array for date time variables. 151byte rtcA1Array[7]; // RTC alarm array. 152 153char* dayArray[9] = { "","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" }; 154char* dayShortArray[9] = { "","Su","Mo","Tu","We","Th","Fr","Sa"}; // Used for DoW menu setting only. Leading "" is because "0" is not a DoW parameter acording to the DS3231 data sheet. 155char* monthArray[14] = { "", 156 "January", 157 "February", 158 "March", 159 "April", 160 "May", 161 "June", 162 "July", 163 "August", 164 "September", 165 "October", 166 "November", 167 "December" 168}; // Initial "" is to solve the leading Zero in the array when matching to the month select function. 169 170char DisplayDateString[30]; // Strings to concatinate rtc variables in the right format x 4 171char DateAndTimeString[40]; 172char HourAndMinuteString[20]; 173char MinuteAndSecondString[20]; 174 175// Strings, lots and lots of strings, placing them into flash to save SRAM. 176 177const char string_0[] PROGMEM = "The greatest glory in living lies not in never falling, but in rising every time we fall - Nelson Mandela"; // "String 0" etc are strings to store - change to suit. 178const char string_1[] PROGMEM = "The way to get started is to quit talking and begin doing - Walt Disney"; 179const char string_2[] PROGMEM = "If life were predictable it would cease to be life, and be without flavor - Eleanor Roosevelt"; 180const char string_3[] PROGMEM = "Great things never come from comfort zones..."; 181const char string_4[] PROGMEM = "If you look at what you have in life, you'll always have more. If you look at what you don't have in life, you'll never have enough - Oprah Winfrey"; 182const char string_5[] PROGMEM = "If you set your goals ridiculously high and it's a failure, you will fail above everyone else's success - James Cameron"; 183const char string_6[] PROGMEM = "Life is what happens when you're busy making other plans - John Lennon"; 184const char string_7[] PROGMEM = "Spread love everywhere you go. Let no one ever come to you without leaving happier - Mother Teresa"; 185const char string_8[] PROGMEM = "When you reach the end of your rope, tie a knot in it and hang on - Franklin D.Roosevelt"; 186const char string_9[] PROGMEM = "Always remember that you are absolutely unique. Just like everyone else - Margaret Mead"; 187const char string_10[] PROGMEM = "Don't judge each day by the harvest you reap but by the seeds that you plant - Robert Louis Stevenson"; 188const char string_11[] PROGMEM = "The future belongs to those who believe in the beauty of their dreams - Eleanor Roosevelt"; 189const char string_12[] PROGMEM = "Tell me and I forget. Teach me and I remember. Involve me and I learn - Benjamin Franklin"; 190const char string_13[] PROGMEM = "The best and most beautiful things in the world cannot be seen or even touched - they must be felt with the heart - Helen Keller"; 191const char string_14[] PROGMEM = "It is during our darkest moments that we must focus to see the light - Aristotle"; 192const char string_15[] PROGMEM = "Whoever is happy will make others happy too - Anne Frank"; 193const char string_16[] PROGMEM = "In the end, it's not the years in your life that count. It's the life in your years - Abraham Lincoln"; 194const char string_17[] PROGMEM = "Life is never fair, and perhaps it is a good thing for most of us that it is not - Oscar Wilde"; 195const char string_18[] PROGMEM = "Only a life lived for others is a life worthwhile - Albert Einstein"; 196const char string_19[] PROGMEM = "The purpose of our lives is to be happy - Dalai Lama"; 197const char string_20[] PROGMEM = "Life is really simple, but we insist on making it complicated - Confucius"; 198const char string_21[] PROGMEM = "Keep smiling, because life is a beautiful thing and there's so much to smile about - Marilyn Monroe"; 199const char string_22[] PROGMEM = "Love the life you live. Live the life you love - Bob Marley"; 200const char string_23[] PROGMEM = "Life is made of ever so many partings welded together - Charles Dickens"; 201const char string_24[] PROGMEM = "I find that the harder I work, the more luck I seem to have - Thomas Jefferson"; 202const char string_25[] PROGMEM = "The secret of success is to do the common thing uncommonly well - John D.Rockefeller Jr."; 203const char string_26[] PROGMEM = "I never dreamed about success, I worked for it - Estee Lauder"; 204const char string_27[] PROGMEM = "Try not to become a man of success. Rather become a man of value - Albert Einstein"; 205const char string_28[] PROGMEM = "Nothing is impossible, the word itself says, ‘I'm possible!' - Audrey Hepburn"; 206const char string_29[] PROGMEM = "Whether you think you can or you think you can't, you're right - Henry Ford"; 207 208// Table to reference the strings. 209 210const char* const string_table[] PROGMEM = { string_0, string_1, string_2, string_3, string_4, string_5, string_6, string_7, string_8, string_9, 211 string_10, string_11, string_12, string_13, string_14, string_15, string_16, string_17, string_18, string_19, 212 string_20, string_21, string_22, string_23, string_24, string_25, string_26, string_27, string_28, string_29 }; 213 214char buffer[120]; // Make sure this is large enough for the largest string it must hold 215 216// Configure BlueTooth data variables. 217 218const byte numChars = 64; // Size of charater array that can be received. 219char receivedChars[numChars]; // An array to store the received data. 220boolean newData = false; // Flag to detech new serial data is ready to display from BlueTooth. 221byte receivedNumChar = 0; // Count to help calculate scrolling max setting. 222 223// Configure EEEPROM. 224 225int ee1224Address = 0; // EEPROM address for 12 / 24 hour clock setting. 226bool ee1224Setting; // Actual commit for writing, 2 bytes. 227bool ee1224Change = false; // To save EEPROM writes. 228 229int eeBrightAddress = 4; // EEPROM address for brightness setting. 230byte eeBrightSetting; // Actual commit for writing, 4 bytes. 231bool eeBrightChange = false; // To save EEPROM writes. 232 233int eeColAddress = 8; // EEPROM address for colour setting. 234byte eeColSetting; // Actual commit for writing, 4 bytes. 235bool eeColChange = false; // To save EEPROM writes. 236 237int eeSpeedAddress = 12; // EEPROM address for speed setting. 238byte eeSpeedSetting; // Actual commit for writing, 4 bytes. 239bool eeSpeedChange = false; // To save EEPROM writes. 240 241int eeAlarmOneSchAddress = 16; // EEPROM address for alarm one schedule setting. 242byte eeAlarmOneSchSetting; // Actual commit for writing, 4 bytes. 243bool eeAlarmOneSchChange = false; // To save EEPROM writes. 244 245int eeMusicAddress = 20; // EEPROM address for music setting. 246byte eeMusicSetting; // Actual commit for writing, 4 bytes. 247bool eeMusicChange = false; // To save EEPROM writes. 248 249int eeSleepSetAddress = 24; // EEPROM address for sleep duration setting. 250byte eeSleepSetSetting; // Actual commit for writing, 4 bytes. 251bool eeSleepSetChange = false; // To save EEPROM writes. 252 253int eeRTCResetAddress = 28; // EEPROM address for RTC reset. 254bool eeRTCResetSetting; // Actual commit for writing, 2 bytes. 255bool eeRTCResetChange = false; // To save EEPROM writes. 256 257int eeWelcomeAddress = 32; // EEPROM address for welcome message. 258bool eeWelcomeSetting; // Actual commit for writing, 2 bytes. 259bool eeWelcomeChange = false; // To save EEPROM writes. 260 261 262void setup() { 263 264 // Configure button pin modes. 265 266 pinMode(intPinMenu, INPUT); 267 pinMode(intPinScrollingDate, INPUT); 268 pinMode(intPinWhite, INPUT); 269 pinMode(intPinAlarmOneSet, INPUT); 270 pinMode(intPinAlarmOneSleep, INPUT); 271 272 pinMode(bPlus, INPUT); // Menu plus / minus pins. 273 pinMode(bMinus, INPUT); 274 275 pinMode(vPlus, OUTPUT); // Volume plus / minus pins. 276 pinMode(vMinus, OUTPUT); 277 278 pinMode(GSTQ, OUTPUT); // Sound trigger pins. 279 pinMode(SSB, OUTPUT); 280 pinMode(Mahnamahna, OUTPUT); 281 282 digitalWrite(GSTQ, HIGH); // Ensure sounds do not start on start up. 283 digitalWrite(SSB, HIGH); 284 digitalWrite(Mahnamahna, HIGH); 285 286 // Configure interupts. 287 288 attachInterrupt(digitalPinToInterrupt(intPinMenu), menuISR_Menu, FALLING); 289 attachInterrupt(digitalPinToInterrupt(intPinScrollingDate), dateISR_ScrollingDate, FALLING); 290 attachInterrupt(digitalPinToInterrupt(intPinWhite), whiteISR_ScrollingRandom, FALLING); 291 attachInterrupt(digitalPinToInterrupt(intPinAlarmOneSet), alarmISR_alarmOneSet, FALLING); 292 attachInterrupt(digitalPinToInterrupt(intPinAlarmOneSleep), alarmISR_alarmOneSleep, FALLING); 293 294 // Begin serial, mySerial, wire and RTC module. 295 296 Serial.begin(38400); 297 s1Serial.begin(38400); // Used for Bluetooth module. 298 Wire.begin(); 299 300 // Display current date and time, comment out before release, debugging only. 301 302 rtc.setClockMode(false); // Set to 24h 303 304 rtcArray[6] = rtc.getYear(); 305 rtcArray[5] = rtc.getMonth(Century); 306 rtcArray[4] = rtc.getDate(); 307 rtcArray[3] = rtc.getDoW(); 308 dowSet = rtc.getDoW(); 309 rtcArray[2] = rtc.getHour(h12, PM); 310 rtcArray[1] = rtc.getMinute(); 311 rtcArray[0] = rtc.getSecond(); 312 313 char* dayOfTheWeek = (dayArray[rtcArray[3]]); // Returns actual day of the week. 314 char* monthOfTheYear = (monthArray[rtcArray[5]]); // Returns actual month of the year. 315 316 // Function to output data to serial monitor for debugging. 317 318 sprintf_P(DateAndTimeString, PSTR("%02d:%02d on %s %02d %s %02d"), rtcArray[2], rtcArray[1], dayOfTheWeek, rtcArray[4], monthOfTheYear, rtcArray[6]); 319 Serial.println(); 320 Serial.print("The current time and date is "); 321 Serial.println(DateAndTimeString); 322 323 // Read EEPROM settings to see if RTC needs master reset. 324 325 EEPROM.get(eeRTCResetAddress, eeRTCResetSetting); 326 327 if (eeRTCResetSetting == 0) { 328 329 resetRTC = false; 330 } 331 332 else if (eeRTCResetSetting == 1) { 333 334 resetRTC = true; 335 } 336 337 if (resetRTC == true) { 338 339 resetAllSettings(); 340 341 } 342 343 // Read EEPROM settings back into volatile memory. 344 345 EEPROM.get(ee1224Address, ee1224Setting); // 12 / 24 Hour clock setting. 346 347 if (ee1224Setting == 0) { 348 349 set1224 = false; 350 } 351 352 else if (ee1224Setting == 1) { 353 354 set1224 = true; 355 } 356 357 EEPROM.get(eeBrightAddress, eeBrightSetting); // Brightness setting. 358 359 brightnessSet = eeBrightSetting; 360 361 EEPROM.get(eeColAddress, eeColSetting); // Colour setting. 362 363 colorSet = eeColSetting; 364 365 EEPROM.get(eeSpeedAddress, eeSpeedSetting); // Scrolling speed setting. 366 367 tempSpeedSet = eeSpeedSetting; 368 369 speedSet = 61 - tempSpeedSet; 370 371 EEPROM.get(eeAlarmOneSchAddress, eeAlarmOneSchSetting); // Alarm setting. 372 373 alarmOneSch = eeAlarmOneSchSetting; 374 375 EEPROM.get(eeMusicAddress, eeMusicSetting); // Music setting. 376 377 musicSet = eeMusicSetting; 378 379 if (musicSet == 0) { // Set which music to play just in case power fails 380 381 musicPlay = GSTQ; 382 383 } 384 385 else if (musicSet == 1) { 386 387 musicPlay = SSB; 388 389 } 390 391 else if (musicSet == 2) { 392 393 musicPlay == Mahnamahna; 394 395 } 396 397 EEPROM.get(eeSleepSetAddress, eeSleepSetSetting); // Sleep setting. 398 399 sleepSet = eeSleepSetSetting; 400 401 EEPROM.get(eeWelcomeAddress, eeWelcomeSetting); // Welcome message on start up setting. 402 403 if (eeWelcomeSetting == 0) { 404 405 resetWelcome = false; 406 } 407 408 else if (eeWelcomeSetting == 1) { 409 410 resetWelcome = true; 411 } 412 413 // Begin NeoPixel matrix. 414 415 matrix.begin(); 416 matrix.setTextWrap(false); 417 matrix.setBrightness(brightnessSet); 418 matrix.setTextColor(colors[colorSet]); 419 420 // Configure random number. 421 422 randomSeed(analogRead(A3)); 423 424 // Get Alarm One current settings 425 426 displayCurrentAlarmOne(); 427 428 // Display welcome message. 429 430 if (resetWelcome == true) { 431 432 menu = 32; 433 } 434 435} // Close setup. 436 437void loop() { 438 439 // Check menu and trigger menu functions from interupt. 440 441 if (menu == 0) 442 { 443 displayCurrentTime(); 444 } 445 if (menu == 1) 446 { 447 displaySetHour(); 448 } 449 if (menu == 2) 450 { 451 displaySetMinute(); 452 } 453 if (menu == 3) 454 { 455 displaySetYear(); 456 } 457 if (menu == 4) 458 { 459 displaySetMonth(); 460 } 461 if (menu == 5) 462 { 463 displaySetDay(); 464 } 465 if (menu == 6) 466 { 467 displaySetDoW(); 468 } 469 if (menu == 7) 470 { 471 amPm(); 472 } 473 if (menu == 8) 474 { 475 displayColorSet(); 476 } 477 if (menu == 9) 478 { 479 displayBrightness(); 480 } 481 if (menu == 10) 482 { 483 displaySpeedSet(); 484 } 485 if (menu == 11) 486 { 487 resetWelcomeMessage(); 488 } 489 if (menu == 12) 490 { 491 resetClock(); 492 } 493 if (menu == 13) 494 { 495 saveTimeAndDate(); 496 } 497 if (menu == 20) 498 { 499 alarmOneSchedule(); 500 } 501 if (menu == 21) 502 { 503 alarmOneSetHour(); 504 } 505 if (menu == 22) 506 { 507 alarmOneSetMinute(); 508 } 509 if (menu == 23) 510 { 511 alarmOneMusicSet(); 512 } 513 if (menu == 24) 514 { 515 alarmOneSleepTime(); 516 } 517 if (menu == 25) 518 { 519 alarmOneVolume(); 520 } 521 if (menu == 26) 522 { 523 alarmOneSave(); 524 } 525 if (menu == 27) 526 { 527 alarmOneSleepCancel(); 528 } 529 if (menu == 30) 530 { 531 displayScrollingDate(); 532 } 533 if (menu == 31) 534 { 535 displayRandomWhite(); // Display random stored messages from array. 536 } 537 if (menu == 32) 538 { 539 displayWelcomeMessage(); // Display welcome message on start up only. 540 } 541 542 alarmOneTriggered(); // Check if alarm one triggered. 543 checkSleep(); // Check if sleep time has been reached. 544 recvBTWithStartAndEndMarker(); // Receive serial data by bluetooth. 545 showNewBTData(); // Display serial data once received. 546 547} // Close loop. 548 549void menuISR_Menu() { 550 551 static unsigned long last_interrupt_time = 0; // Function to solve debounce 552 unsigned long interrupt_time = millis(); 553 554 if (interrupt_time - last_interrupt_time > 200) 555 { 556 menu++; 557 } 558 559 if (menu > 13) 560 { 561 menu = 0; 562 digitalWrite(SSB, HIGH); // These digital writes are to stop music playing if menu is pressed by mistake during alarm settings 563 digitalWrite(GSTQ, HIGH); 564 digitalWrite(Mahnamahna, HIGH); 565 } 566 567 last_interrupt_time = interrupt_time; 568 569} // Close function. 570 571void alarmISR_alarmOneSet() { 572 573 static unsigned long last_interrupt_time = 0; // Function to solve debounce 574 unsigned long interrupt_time = millis(); 575 576 if (interrupt_time - last_interrupt_time > 200) 577 { 578 if (menu == 0) { 579 580 menu = 20; 581 582 } 583 584 else menu++; 585 586 } 587 588 last_interrupt_time = interrupt_time; 589 590} // Close function. 591 592 593void alarmISR_alarmOneSleep() { 594 595 static unsigned long last_interrupt_time = 0; // Function to solve debounce 596 unsigned long interrupt_time = millis(); 597 598 if (interrupt_time - last_interrupt_time > 200) 599 { 600 601 if (menu == 0) { 602 603 menu = 27; 604 setSleepStart = true; 605 606 } 607 608 } 609 610 last_interrupt_time = interrupt_time; 611 612} // Close function. 613 614void dateISR_ScrollingDate() { 615 616 static unsigned long last_interrupt_dateISR_time = 0; // Function to solve debounce 617 unsigned long interrupt_dateISR_time = millis(); 618 619 if (interrupt_dateISR_time - last_interrupt_dateISR_time > 200) 620 { 621 menu = 30; 622 } 623 624 last_interrupt_dateISR_time = interrupt_dateISR_time; 625 626} // Close function. 627 628void whiteISR_ScrollingRandom() { 629 630 static unsigned long last_interrupt_dateISR_time = 0; // Function to solve debounce 631 unsigned long interrupt_dateISR_time = millis(); 632 633 if (interrupt_dateISR_time - last_interrupt_dateISR_time > 200) 634 { 635 menu = 31; 636 } 637 638 last_interrupt_dateISR_time = interrupt_dateISR_time; 639 640} // Close function. 641 642void displayCurrentTime() { 643 644 // Get current date and time. 645 646 rtcArray[6] = rtc.getYear(); 647 rtcArray[5] = rtc.getMonth(Century); 648 rtcArray[4] = rtc.getDate(); 649 rtcArray[3] = rtc.getDoW(); 650 dowSet = rtc.getDoW(); 651 rtcArray[2] = rtc.getHour(h12, PM); 652 rtcArray[1] = rtc.getMinute(); 653 rtcArray[0] = rtc.getSecond(); 654 655 // Configure either 12 or 24 hour time display. 656 657 if (set1224 == true) { 658 659 int hr12; 660 661 if (rtcArray[2] > 12) { 662 663 hr12 = rtcArray[2] - 12; 664 sprintf_P(HourAndMinuteString, PSTR("%2d:%02d"), hr12, rtcArray[1]); 665 666 } 667 668 else if (rtcArray[2] <= 12) { 669 670 sprintf_P(HourAndMinuteString, PSTR("%2d:%02d"), rtcArray[2], rtcArray[1]); 671 672 } 673 674 } 675 676 else sprintf_P(HourAndMinuteString, PSTR("%02d:%02d"), rtcArray[2], rtcArray[1]); 677 678 // Update setting variables, so when selecting, they are to current time. 679 680 minSet = rtcArray[1]; 681 hourSet = rtcArray[2]; 682 dowSet = rtcArray[3]; 683 daySet = rtcArray[4]; 684 monthSet = rtcArray[5]; 685 yearSet = rtcArray[6]; 686 687 // Check if current time is behind displayed time to save display refreshes and flickering, display is changed. 688 689 if (HourAndMinuteString >= HourAndMinuteString) { 690 691 matrix.clear(); 692 693 if (set1224 == true) { // Configure 12 hour display and set cursor positions. 694 695 int hr12; 696 697 if (rtcArray[2] > 12) { 698 699 hr12 = rtcArray[2] - 12; 700 701 if (hr12 <= 9) { 702 703 matrix.setCursor(3, 0); 704 705 } 706 707 else matrix.setCursor(6, 0); 708 709 } 710 711 else if (rtcArray[2] <= 9) { 712 713 matrix.setCursor(3, 0); 714 715 } 716 717 else matrix.setCursor(6, 0); 718 719 } 720 721 else matrix.setCursor(6, 0); 722 723 // Configure & display PM sign for 12 hour clock display. 724 725 if (set1224 == true) { 726 727 if (rtcArray[2] >= 12) { 728 729 if (colorSet == 0) { 730 731 matrix.setPixelColor(300, 255, 0, 0); 732 matrix.setPixelColor(301, 255, 0, 0); 733 matrix.setPixelColor(308, 255, 0, 0); 734 matrix.setPixelColor(309, 255, 0, 0); 735 matrix.setPixelColor(316, 255, 0, 0); 736 } 737 738 else if (colorSet == 1) { 739 740 matrix.setPixelColor(300, 0, 255, 0); 741 matrix.setPixelColor(301, 0, 255, 0); 742 matrix.setPixelColor(308, 0, 255, 0); 743 matrix.setPixelColor(309, 0, 255, 0); 744 matrix.setPixelColor(316, 0, 255, 0); 745 } 746 747 else if (colorSet == 2) { 748 749 matrix.setPixelColor(300, 255, 255, 0); 750 matrix.setPixelColor(301, 255, 255, 0); 751 matrix.setPixelColor(308, 255, 255, 0); 752 matrix.setPixelColor(309, 255, 255, 0); 753 matrix.setPixelColor(316, 255, 255, 0); 754 } 755 756 else if (colorSet == 3) { 757 758 matrix.setPixelColor(300, 0, 0, 255); 759 matrix.setPixelColor(301, 0, 0, 255); 760 matrix.setPixelColor(308, 0, 0, 255); 761 matrix.setPixelColor(309, 0, 0, 255); 762 matrix.setPixelColor(316, 0, 0, 255); 763 } 764 765 else if (colorSet == 4) { 766 767 matrix.setPixelColor(300, 255, 0, 255); 768 matrix.setPixelColor(301, 255, 0, 255); 769 matrix.setPixelColor(308, 255, 0, 255); 770 matrix.setPixelColor(309, 255, 0, 255); 771 matrix.setPixelColor(316, 255, 0, 255); 772 } 773 774 else if (colorSet == 5) { 775 776 matrix.setPixelColor(300, 0, 255, 255); 777 matrix.setPixelColor(301, 0, 255, 255); 778 matrix.setPixelColor(308, 0, 255, 255); 779 matrix.setPixelColor(309, 0, 255, 255); 780 matrix.setPixelColor(316, 0, 255, 255); 781 } 782 783 else if (colorSet == 6) { 784 785 matrix.setPixelColor(300, 255, 255, 255); 786 matrix.setPixelColor(301, 255, 255, 255); 787 matrix.setPixelColor(308, 255, 255, 255); 788 matrix.setPixelColor(309, 255, 255, 255); 789 matrix.setPixelColor(316, 255, 255, 255); 790 } 791 } 792 } 793 794 // Configure & display alarm one sign. 795 796 if (rtc.checkAlarmEnabled(1)) { 797 798 if (colorSet == 0) { 799 800 matrix.setPixelColor(276, 255, 0, 0); 801 matrix.setPixelColor(277, 255, 0, 0); 802 matrix.setPixelColor(284, 255, 0, 0); 803 matrix.setPixelColor(285, 255, 0, 0); 804 } 805 806 else if (colorSet == 1) { 807 808 matrix.setPixelColor(276, 0, 255, 0); 809 matrix.setPixelColor(277, 0, 255, 0); 810 matrix.setPixelColor(284, 0, 255, 0); 811 matrix.setPixelColor(285, 0, 255, 0); 812 } 813 814 else if (colorSet == 2) { 815 816 matrix.setPixelColor(276, 255, 255, 0); 817 matrix.setPixelColor(277, 255, 255, 0); 818 matrix.setPixelColor(284, 255, 255, 0); 819 matrix.setPixelColor(285, 255, 255, 0); 820 } 821 822 else if (colorSet == 3) { 823 824 matrix.setPixelColor(276, 0, 0, 255); 825 matrix.setPixelColor(277, 0, 0, 255); 826 matrix.setPixelColor(284, 0, 0, 255); 827 matrix.setPixelColor(285, 0, 0, 255); 828 } 829 830 else if (colorSet == 4) { 831 832 matrix.setPixelColor(276, 255, 0, 255); 833 matrix.setPixelColor(277, 255, 0, 255); 834 matrix.setPixelColor(284, 255, 0, 255); 835 matrix.setPixelColor(285, 255, 0, 255); 836 } 837 838 else if (colorSet == 5) { 839 840 matrix.setPixelColor(276, 0, 255, 255); 841 matrix.setPixelColor(277, 0, 255, 255); 842 matrix.setPixelColor(284, 0, 255, 255); 843 matrix.setPixelColor(285, 0, 255, 255); 844 } 845 846 else if (colorSet == 6) { 847 848 matrix.setPixelColor(276, 255, 255, 255); 849 matrix.setPixelColor(277, 255, 255, 255); 850 matrix.setPixelColor(284, 255, 255, 255); 851 matrix.setPixelColor(285, 255, 255, 255); 852 } 853 } 854 855 } 856 857 matrix.setTextColor(colors[colorSet]); 858 matrix.print(HourAndMinuteString); 859 matrix.show(); 860 861} // Close function. 862 863void displaySetHour() { 864 865 // Set hour time setting. 866 867 if (digitalRead(bPlus) == LOW) 868 { 869 if (hourSet == 23) // 24 hour clock. 870 { 871 hourSet = 0; 872 } 873 else 874 { 875 hourSet = hourSet + 1; // Increment by 1. 876 } 877 } 878 if (digitalRead(bMinus) == LOW) 879 { 880 if (hourSet == 0) 881 { 882 hourSet = 23; 883 } 884 else 885 { 886 hourSet = hourSet - 1; // Decrement by 1. 887 } 888 } 889 890 matrix.clear(); 891 matrix.setCursor(1, 0); 892 matrix.print(F("Hr :")); 893 matrix.show(); 894 895 matrix.print(hourSet); 896 matrix.show(); 897 898 delay(buttonDelay); 899 900} // Close function. 901 902void displaySetMinute() { 903 904 // Setting the minutes. 905 906 if (digitalRead(bPlus) == LOW) 907 { 908 if (minSet == 59) 909 { 910 minSet = 0; 911 } 912 else 913 { 914 minSet = minSet + 1; 915 } 916 } 917 if (digitalRead(bMinus) == LOW) 918 { 919 if (minSet == 0) 920 { 921 minSet = 59; 922 } 923 else 924 { 925 minSet = minSet - 1; 926 } 927 } 928 929 matrix.clear(); 930 matrix.setCursor(1, 0); 931 matrix.print(F("Min:")); 932 matrix.show(); 933 934 matrix.print(minSet); 935 matrix.show(); 936 937 delay(buttonDelay); 938 939} // Close function. 940 941void displaySetYear() { 942 943 // setting the year. 944 945 if (digitalRead(bPlus) == LOW) 946 { 947 yearSet = yearSet + 1; 948 } 949 if (digitalRead(bMinus) == LOW) 950 { 951 yearSet = yearSet - 1; 952 } 953 954 matrix.clear(); 955 matrix.setCursor(1, 0); 956 matrix.print(F("Yr :")); 957 matrix.show(); 958 959 int yearSet2 = yearSet; // 960 961 matrix.print(yearSet2 % 100); 962 matrix.show(); 963 964 delay(buttonDelay); 965 966} // Close function. 967 968void displaySetMonth() { 969 970 // Setting the month. 971 972 if (digitalRead(bPlus) == LOW) 973 { 974 if (monthSet == 12) 975 { 976 monthSet = 1; 977 } 978 else 979 { 980 monthSet = monthSet + 1; 981 } 982 } 983 if (digitalRead(bMinus) == LOW) 984 { 985 if (monthSet == 1) 986 { 987 monthSet = 12; 988 } 989 else 990 { 991 monthSet = monthSet - 1; 992 } 993 } 994 995 matrix.clear(); 996 matrix.setCursor(1, 0); 997 matrix.print(F("Mth:")); 998 matrix.show(); 999 1000 matrix.print(monthSet); 1001 matrix.show(); 1002 1003 delay(buttonDelay); 1004 1005} // Close function. 1006 1007void displaySetDay() { 1008 1009 // Configure quantity of days per month. 1010 1011 byte qtyDays; 1012 1013 if (monthSet == 1 || monthSet == 3 || monthSet == 5 || monthSet == 7 || monthSet == 8 || monthSet == 10 || monthSet == 12) { 1014 1015 qtyDays = 31; 1016 } 1017 1018 else if (monthSet == 4 || monthSet == 6 || monthSet == 9 || monthSet == 11) { 1019 1020 qtyDays = 30; 1021 } 1022 1023 else if (monthSet == 2) { 1024 1025 qtyDays = 28; 1026 } 1027 1028 // Setting the day. 1029 1030 if (digitalRead(bPlus) == LOW) 1031 { 1032 if (daySet == qtyDays) 1033 { 1034 daySet = 1; 1035 } 1036 else 1037 { 1038 daySet = daySet + 1; 1039 } 1040 } 1041 if (digitalRead(bMinus) == LOW) 1042 { 1043 if (daySet == 1) 1044 { 1045 daySet = qtyDays; 1046 } 1047 else 1048 { 1049 daySet = daySet - 1; 1050 } 1051 } 1052 1053 matrix.clear(); 1054 matrix.setCursor(1, 0); 1055 matrix.print(F("Day:")); 1056 matrix.show(); 1057 1058 matrix.print(daySet); 1059 matrix.show(); 1060 1061 delay(buttonDelay); 1062 1063} // Close function. 1064 1065void displaySetDoW() { 1066 1067 // Setting the DoW. 1068 1069 if (digitalRead(bPlus) == LOW) 1070 { 1071 if (dowSet == 7) 1072 { 1073 dowSet = 1; 1074 } 1075 else 1076 { 1077 dowSet = dowSet + 1; 1078 } 1079 } 1080 if (digitalRead(bMinus) == LOW) 1081 { 1082 if (dowSet == 1) 1083 { 1084 dowSet = 7; 1085 } 1086 else 1087 { 1088 dowSet = dowSet - 1; 1089 } 1090 } 1091 1092 matrix.clear(); 1093 matrix.setCursor(1, 0); 1094 matrix.print(F("DoW:")); 1095 matrix.show(); 1096 1097 matrix.print(dayShortArray[dowSet]); 1098 matrix.show(); 1099 1100 delay(buttonDelay); 1101 1102} // Close function. 1103 1104void displaySpeedSet() { 1105 1106 // Setting the display speed. 1107 1108 if (digitalRead(bPlus) == LOW) 1109 { 1110 if (tempSpeedSet == 60) 1111 { 1112 tempSpeedSet = 1; 1113 } 1114 else 1115 { 1116 tempSpeedSet = tempSpeedSet + 1; 1117 } 1118 1119 eeSpeedChange = true; 1120 } 1121 1122 if (digitalRead(bMinus) == LOW) 1123 { 1124 if (tempSpeedSet == 1) 1125 { 1126 tempSpeedSet = 60; 1127 } 1128 else 1129 { 1130 tempSpeedSet = tempSpeedSet - 1; 1131 } 1132 1133 eeSpeedChange = true; 1134 } 1135 1136 matrix.clear(); 1137 matrix.setCursor(1, 0); 1138 matrix.print(F("Spd:")); 1139 matrix.show(); 1140 1141 matrix.print(tempSpeedSet); 1142 matrix.show(); 1143 1144 speedSet = 61 - tempSpeedSet; 1145 1146 if (eeSpeedChange == true) 1147 { 1148 eeSpeedSetting = tempSpeedSet; 1149 EEPROM.update(eeSpeedAddress, eeSpeedSetting); // Record speed setting into EEPROM. 1150 eeSpeedChange = false; 1151 } 1152 1153 delay(buttonDelay); 1154 1155} // Close function. 1156 1157void displayColorSet() { 1158 1159 // Setting the display speed. 1160 1161 if (digitalRead(bPlus) == LOW) 1162 { 1163 if (colorSet == 6) 1164 { 1165 colorSet = 0; 1166 } 1167 else 1168 { 1169 colorSet = colorSet + 1; 1170 } 1171 1172 eeColChange = true; 1173 } 1174 if (digitalRead(bMinus) == LOW) 1175 { 1176 if (colorSet == 0) 1177 { 1178 colorSet = 6; 1179 } 1180 else 1181 { 1182 colorSet = colorSet - 1; 1183 } 1184 1185 eeColChange = true; 1186 } 1187 1188 matrix.clear(); 1189 matrix.setCursor(1, 0); 1190 matrix.setTextColor(colors[colorSet]); 1191 matrix.print(colorArray[colorSet]); 1192 matrix.show(); 1193 1194 if (eeColChange == true) 1195 { 1196 eeColSetting = colorSet; 1197 EEPROM.update(eeColAddress, eeColSetting); // Record brightness setting into EEPROM. 1198 eeColChange = false; 1199 } 1200 delay(buttonDelay); 1201 1202} // Close function. 1203 1204void displayBrightness() { 1205 1206 // Setting the display brightness. 1207 1208 if (digitalRead(bPlus) == LOW) 1209 { 1210 if (brightnessSet == 95) 1211 { 1212 brightnessSet = 1; 1213 } 1214 else 1215 { 1216 brightnessSet = brightnessSet + 1; 1217 } 1218 1219 eeBrightChange = true; 1220 } 1221 if (digitalRead(bMinus) == LOW) 1222 { 1223 if (brightnessSet == 1) 1224 { 1225 brightnessSet = 95; 1226 } 1227 else 1228 { 1229 brightnessSet = brightnessSet - 1; 1230 } 1231 1232 eeBrightChange = true; 1233 } 1234 1235 matrix.clear(); 1236 matrix.setCursor(1, 0); 1237 matrix.setBrightness(brightnessSet); 1238 matrix.print(F("Brg:")); 1239 matrix.show(); 1240 1241 matrix.print(brightnessSet); 1242 matrix.show(); 1243 1244 if (eeBrightChange == true) 1245 { 1246 eeBrightSetting = brightnessSet; 1247 EEPROM.update(eeBrightAddress, eeBrightSetting); // Record brightness setting into EEPROM. 1248 eeBrightChange = false; 1249 } 1250 1251 1252 delay(buttonDelay); 1253 1254} // Close function. 1255 1256void amPm() { 1257 1258 // Setting either 12 or 24 hour clock display. 1259 1260 if (digitalRead(bPlus) == LOW) 1261 { 1262 if (set1224 == false) 1263 { 1264 set1224 = true; 1265 } 1266 else 1267 { 1268 set1224 = false; 1269 } 1270 1271 ee1224Change = true; 1272 } 1273 if (digitalRead(bMinus) == LOW) 1274 { 1275 if (set1224 == true) 1276 { 1277 set1224 = false; 1278 } 1279 else 1280 { 1281 set1224 = true; 1282 } 1283 1284 ee1224Change = true; 1285 } 1286 1287 matrix.clear(); 1288 matrix.setCursor(1, 0); 1289 matrix.setBrightness(brightnessSet); 1290 matrix.print(F("12H: ")); 1291 matrix.show(); 1292 1293 char yesNo[2][2] = { "N", "Y" }; 1294 1295 if (set1224 == false) { 1296 1297 matrix.print(yesNo[0]); 1298 matrix.show(); 1299 } 1300 1301 else { 1302 1303 matrix.print(yesNo[1]); 1304 matrix.show(); 1305 1306 } 1307 1308 // Commit to EEPROM. 1309 1310 if (set1224 == false) { 1311 1312 ee1224Setting = 0; 1313 } 1314 1315 else if (set1224 == true) { 1316 1317 ee1224Setting = 1; 1318 } 1319 1320 if (ee1224Change == true) 1321 { 1322 EEPROM.update(ee1224Address, ee1224Setting); // Record the 12 / 24 hour clock setting into EEPROM. 1323 ee1224Change = false; 1324 } 1325 1326 delay(buttonDelay); 1327 1328} // Close function. 1329 1330void resetWelcomeMessage() { 1331 1332 // Reset the welcome message on start up. 1333 1334 if (digitalRead(bPlus) == LOW) 1335 { 1336 if (resetWelcome == false) 1337 { 1338 resetWelcome = true; 1339 } 1340 else 1341 { 1342 resetWelcome = false; 1343 } 1344 1345 eeWelcomeChange = true; 1346 } 1347 if (digitalRead(bMinus) == LOW) 1348 { 1349 if (resetWelcome == true) 1350 { 1351 resetWelcome = false; 1352 } 1353 else 1354 { 1355 resetWelcome = true; 1356 } 1357 1358 eeWelcomeChange = true; 1359 } 1360 1361 matrix.clear(); 1362 matrix.setCursor(1, 0); 1363 matrix.setBrightness(brightnessSet); 1364 matrix.print(F("Wel: ")); 1365 matrix.show(); 1366 1367 char yesNo[2][2] = { "N", "Y" }; 1368 1369 if (resetWelcome == false) { 1370 1371 matrix.print(yesNo[0]); 1372 matrix.show(); 1373 } 1374 1375 else { 1376 1377 matrix.print(yesNo[1]); 1378 matrix.show(); 1379 1380 } 1381 1382 // Commit to EEPROM. 1383 1384 if (resetWelcome == false) { 1385 1386 eeWelcomeSetting = 0; 1387 } 1388 1389 else if (resetWelcome == true) { 1390 1391 eeWelcomeSetting = 1; 1392 } 1393 1394 if (eeWelcomeChange == true) 1395 { 1396 EEPROM.update(eeWelcomeAddress, eeWelcomeSetting); // Record the welcome message flag into EEPROM. 1397 eeWelcomeChange = false; 1398 } 1399 1400 delay(buttonDelay); 1401 1402} 1403 1404void resetClock() { 1405 1406 // Reset the RTC if EEPROM corrupts. 1407 1408 if (digitalRead(bPlus) == LOW) 1409 { 1410 if (resetRTC == false) 1411 { 1412 resetRTC = true; 1413 } 1414 else 1415 { 1416 resetRTC = false; 1417 } 1418 1419 eeRTCResetChange = true; 1420 } 1421 if (digitalRead(bMinus) == LOW) 1422 { 1423 if (resetRTC == true) 1424 { 1425 resetRTC = false; 1426 } 1427 else 1428 { 1429 resetRTC = true; 1430 } 1431 1432 eeRTCResetChange = true; 1433 } 1434 1435 matrix.clear(); 1436 matrix.setCursor(1, 0); 1437 matrix.setBrightness(brightnessSet); 1438 matrix.print(F("Rst: ")); 1439 matrix.show(); 1440 1441 char yesNo[2][2] = { "N", "Y" }; 1442 1443 if (resetRTC == false) { 1444 1445 matrix.print(yesNo[0]); 1446 matrix.show(); 1447 } 1448 1449 else { 1450 1451 matrix.print(yesNo[1]); 1452 matrix.show(); 1453 1454 } 1455 1456 // Commit to EEPROM. 1457 1458 if (resetRTC == false) { 1459 1460 eeRTCResetSetting = 0; 1461 } 1462 1463 else if (resetRTC == true) { 1464 1465 eeRTCResetSetting = 1; 1466 } 1467 1468 if (eeRTCResetChange == true) 1469 { 1470 EEPROM.update(eeRTCResetAddress, eeRTCResetSetting); // Record the 12 / 24 hour clock setting into EEPROM. 1471 eeRTCResetChange = false; 1472 } 1473 1474 delay(buttonDelay); 1475 1476} 1477 1478void saveTimeAndDate() { 1479 1480 // Set date / time. 1481 1482 //rtc.adjust(DateTime(yearSet, monthSet, daySet, hourSet, minSet, 0)); // Send updated variables to RTC module. 1483 1484 rtc.setYear(yearSet); 1485 rtc.setMonth(monthSet); 1486 rtc.setDate(daySet); 1487 rtc.setDoW(dowSet); 1488 rtc.setHour(hourSet); 1489 rtc.setMinute(minSet); 1490 //rtc.setSecond(Second); 1491 1492 // Variable saving. 1493 1494 matrix.clear(); 1495 matrix.setCursor(5, 0); 1496 matrix.print(F("Saved")); 1497 matrix.show(); 1498 delay(2000); 1499 1500 menu = 0; // Reset menu option once saved. 1501 1502 //DateTime now = rtc.now(); 1503 1504 rtcArray[6] = rtc.getYear(); 1505 rtcArray[5] = rtc.getMonth(Century); 1506 rtcArray[4] = rtc.getDate(); 1507 rtcArray[3] = rtc.getDoW(); 1508 rtcArray[2] = rtc.getHour(h12, PM); 1509 rtcArray[1] = rtc.getMinute(); 1510 rtcArray[0] = rtc.getSecond(); 1511 1512 char* dayOfTheWeek = (dayArray[rtcArray[3]]); // returns actual day of the week. 1513 char* monthOfTheYear = (monthArray[rtcArray[5]]); // returns actual month of the year. 1514 1515 sprintf_P(DateAndTimeString, PSTR("%02d:%02d on %s %02d %s %02d"), rtcArray[2], rtcArray[1], dayOfTheWeek, rtcArray[4], monthOfTheYear, rtcArray[6]); 1516 Serial.print("Time and Date have been set to: "); 1517 Serial.println(DateAndTimeString); 1518 1519} // Close function. 1520 1521void alarmOneSchedule() { 1522 1523 // Get Alarm One current settings 1524 1525 displayCurrentAlarmOne(); 1526 1527 // Alarm scheudle - off, once, daily, workday, weekend 1528 1529 if (digitalRead(bPlus) == LOW) 1530 { 1531 if (alarmOneSch == 4) 1532 { 1533 alarmOneSch = 0; 1534 } 1535 else 1536 { 1537 alarmOneSch = alarmOneSch + 1; // Increment by 1. 1538 } 1539 1540 eeAlarmOneSchChange = true; 1541 } 1542 if (digitalRead(bMinus) == LOW) 1543 { 1544 if (alarmOneSch == 0) 1545 { 1546 alarmOneSch = 4; 1547 } 1548 else 1549 { 1550 alarmOneSch = alarmOneSch - 1; // Decrement by 1. 1551 } 1552 1553 eeAlarmOneSchChange = true; 1554 } 1555 1556 matrix.clear(); 1557 matrix.setCursor(6, 0); 1558 matrix.print(alarmSchArray[alarmOneSch]); 1559 matrix.show(); 1560 1561 if (eeAlarmOneSchChange == true) 1562 { 1563 eeAlarmOneSchSetting = alarmOneSch; 1564 EEPROM.update(eeAlarmOneSchAddress, eeAlarmOneSchSetting); // Record alarm one schedule setting into EEPROM. 1565 eeAlarmOneSchChange = false; 1566 } 1567 delay(buttonDelay); 1568 1569} 1570 1571void alarmOneSetHour() { 1572 1573 // Check schedule. 1574 1575 if (alarmOneSch != 0) { 1576 1577 // Alarm one set hour. 1578 1579 if (digitalRead(bPlus) == LOW) 1580 { 1581 if (alarmOneHourSet == 23) // 24 hour clock. 1582 { 1583 alarmOneHourSet = 0; 1584 } 1585 else 1586 { 1587 alarmOneHourSet = alarmOneHourSet + 1; // Increment by 1. 1588 } 1589 } 1590 if (digitalRead(bMinus) == LOW) 1591 { 1592 if (alarmOneHourSet == 0) 1593 { 1594 alarmOneHourSet = 23; 1595 } 1596 else 1597 { 1598 alarmOneHourSet = alarmOneHourSet - 1; // Decrement by 1. 1599 } 1600 } 1601 1602 char alarmOneHourSetString[4]; 1603 char alarmOneMinSetString[4]; 1604 1605 sprintf_P(alarmOneHourSetString, PSTR("%02d"), alarmOneHourSet); 1606 sprintf_P(alarmOneMinSetString, PSTR("%02d"), alarmOneMinSet); 1607 1608 matrix.clear(); 1609 matrix.setCursor(6, 0); 1610 1611 if (colorSet != 1) { 1612 1613 matrix.setTextColor(colors[1]); 1614 1615 } 1616 1617 else { 1618 1619 matrix.setTextColor(colors[6]); 1620 } 1621 1622 matrix.print(alarmOneHourSetString); 1623 matrix.setTextColor(colors[colorSet]); 1624 matrix.print(F(":")); 1625 matrix.print(alarmOneMinSetString); 1626 matrix.show(); 1627 1628 } 1629 1630 else alarmOneSave(); 1631 1632 delay(buttonDelay); 1633 1634} // Close function. 1635 1636void alarmOneSetMinute() { 1637 1638 // Alarm one set minute. 1639 1640 if (digitalRead(bPlus) == LOW) 1641 { 1642 if (alarmOneMinSet == 59) 1643 { 1644 alarmOneMinSet = 0; 1645 } 1646 else 1647 { 1648 alarmOneMinSet = alarmOneMinSet + 1; // Increment by 1. 1649 } 1650 } 1651 if (digitalRead(bMinus) == LOW) 1652 { 1653 if (alarmOneMinSet == 0) 1654 { 1655 alarmOneMinSet = 59; 1656 } 1657 else 1658 { 1659 alarmOneMinSet = alarmOneMinSet - 1; // Decrement by 1. 1660 } 1661 } 1662 1663 char alarmOneHourSetString[4]; 1664 char alarmOneMinSetString[4]; 1665 1666 sprintf_P(alarmOneHourSetString, PSTR("%02d"), alarmOneHourSet); 1667 sprintf_P(alarmOneMinSetString, PSTR("%02d"), alarmOneMinSet); 1668 1669 matrix.clear(); 1670 matrix.setCursor(6, 0); 1671 matrix.setTextColor(colors[colorSet]); 1672 matrix.print(alarmOneHourSetString); 1673 matrix.print(F(":")); 1674 1675 if (colorSet != 1) { 1676 1677 matrix.setTextColor(colors[1]); 1678 1679 } 1680 1681 else { 1682 1683 matrix.setTextColor(colors[6]); 1684 } 1685 1686 matrix.print(alarmOneMinSetString); 1687 matrix.show(); 1688 1689 delay(buttonDelay); 1690 1691} // Close function. 1692 1693void alarmOneSleepTime() { 1694 1695 digitalWrite(musicPlay, HIGH); 1696 1697 // Alarm one set sleep period. 1698 1699 if (digitalRead(bPlus) == LOW) 1700 { 1701 if (sleepSet == 15) 1702 { 1703 sleepSet = 1; 1704 } 1705 else 1706 { 1707 sleepSet = sleepSet + 1; // Increment by 1. 1708 } 1709 1710 eeSleepSetChange = true; 1711 } 1712 if (digitalRead(bMinus) == LOW) 1713 { 1714 if (sleepSet == 1) 1715 { 1716 sleepSet = 15; 1717 } 1718 else 1719 { 1720 sleepSet = sleepSet - 1; // Decrement by 1. 1721 } 1722 1723 eeSleepSetChange = true; 1724 } 1725 1726 matrix.clear(); 1727 matrix.setCursor(0, 0); 1728 matrix.setTextColor(colors[colorSet]); 1729 matrix.print(F("Slp:")); 1730 matrix.show(); 1731 1732 matrix.print(sleepSet); 1733 matrix.show(); 1734 1735 if (eeSleepSetChange == true) 1736 { 1737 eeSleepSetSetting = sleepSet; 1738 EEPROM.update(eeSleepSetAddress, eeSleepSetSetting); // Record sleep setting into EEPROM. 1739 eeSleepSetChange = false; 1740 } 1741 delay(buttonDelay); 1742 1743} 1744 1745void alarmOneMusicSet() { 1746 1747 // Alarm one choose music option. 1748 1749 if (digitalRead(bPlus) == LOW) 1750 { 1751 if (musicSet == 2) 1752 { 1753 musicSet = 0; 1754 musicScroll = true; 1755 } 1756 else 1757 { 1758 musicSet = musicSet + 1; // Increment by 1. 1759 musicScroll = true; 1760 } 1761 1762 eeMusicChange = true; 1763 } 1764 if (digitalRead(bMinus) == LOW) 1765 { 1766 if (musicSet == 0) 1767 { 1768 musicSet = 2; 1769 musicScroll = true; 1770 1771 } 1772 else 1773 { 1774 musicSet = musicSet - 1; // Decrement by 1. 1775 musicScroll = true; 1776 } 1777 1778 eeMusicChange = true; 1779 } 1780 1781 if (musicScroll == true) { 1782 1783 matrix.clear(); 1784 matrix.setCursor(0, 0); 1785 matrix.show(); 1786 1787 String msgText = (musicArray[musicSet]); 1788 1789 Serial.print("Message Text From Table: "); 1790 Serial.println(msgText); 1791 1792 int textLenght = msgText.length(); 1793 int msgSize = (textLenght * pixelPerChar); // Calculate message length. 1794 int scrollingMax = (msgSize); // Adjust displacement for message length. 1795 1796 if (!debug == true) { 1797 1798 // Print variables for debugging messages lenghts 1799 1800 Serial.print("Matrix Width = "); 1801 Serial.println(x); 1802 Serial.print(" Text Lenght = "); 1803 Serial.print(textLenght); 1804 Serial.print(" Message Size = "); 1805 Serial.print(msgSize); 1806 Serial.print(" Scrolling Max = "); 1807 Serial.println(scrollingMax); 1808 1809 } // Close if. 1810 1811 while (x > -scrollingMax) { // Only display text for one pass 1812 1813 matrix.fillScreen(0); 1814 matrix.setCursor(x, 0); 1815 matrix.setTextColor(colors[colorSet]); 1816 matrix.print(msgText); 1817 1818 if (--x < -scrollingMax) 1819 { 1820 x = matrix.width(); 1821 } 1822 matrix.show(); 1823 delay(speedSet); 1824 1825 } // Close while. 1826 1827 x = matrix.width(); 1828 1829 } // Close if. 1830 1831 musicScroll = false; 1832 1833 matrix.clear(); 1834 matrix.setCursor(0, 0); 1835 matrix.show(); 1836 1837 if (musicSet == 0) { 1838 1839 matrix.setCursor(9, 0); 1840 matrix.setTextColor(colors[colorSet]); 1841 matrix.print("GSTQ"); 1842 matrix.show(); 1843 1844 } 1845 1846 else if (musicSet == 1) { 1847 1848 matrix.setCursor(11, 0); 1849 matrix.setTextColor(colors[colorSet]); 1850 matrix.print("SSB"); 1851 matrix.show(); 1852 1853 } 1854 1855 else if (musicSet == 2) { 1856 1857 matrix.setCursor(0, 0); 1858 matrix.setTextColor(colors[colorSet]); 1859 matrix.print("Muppets"); 1860 matrix.show(); 1861 1862 } 1863 1864 if (musicSet == 0) { 1865 1866 musicPlay = GSTQ; 1867 digitalWrite(GSTQ, LOW); 1868 digitalWrite(SSB, HIGH); 1869 digitalWrite(Mahnamahna, HIGH); 1870 } 1871 1872 else if (musicSet == 1) { 1873 1874 musicPlay = SSB; 1875 digitalWrite(GSTQ, HIGH); 1876 digitalWrite(SSB, LOW); 1877 digitalWrite(Mahnamahna, HIGH); 1878 1879 } 1880 1881 else if (musicSet == 2) { 1882 1883 musicPlay = Mahnamahna; 1884 digitalWrite(GSTQ, HIGH); 1885 digitalWrite(SSB, HIGH); 1886 digitalWrite(Mahnamahna, LOW); 1887 1888 } 1889 1890 if (eeMusicChange == true) 1891 { 1892 eeMusicSetting = musicSet; 1893 EEPROM.update(eeMusicAddress, eeMusicSetting); // Record music setting into EEPROM. 1894 eeAlarmOneSchChange = false; 1895 } 1896 delay(buttonDelay); 1897 1898} 1899 1900void alarmOneVolume() { 1901 1902 // Alarm one volume. 1903 1904 if (digitalRead(bPlus) == LOW) 1905 { 1906 volumeSet = volumeSet + 1; // Increment by 1. 1907 digitalWrite(vPlus, LOW); 1908 delay(100); 1909 digitalWrite(vPlus, HIGH); 1910 1911 } 1912 if (digitalRead(bMinus) == LOW) 1913 { 1914 volumeSet = volumeSet - 1; // Decrement by 1. 1915 digitalWrite(vMinus, LOW); 1916 delay(100); 1917 digitalWrite(vMinus, HIGH); 1918 1919 } 1920 1921 matrix.clear(); 1922 matrix.setCursor(0, 0); 1923 matrix.setTextColor(colors[colorSet]); 1924 matrix.print(F("Vol:")); 1925 matrix.show(); 1926 1927 if (volumeSet >= 26) // For loop to ensure volume doesnt get out of sync due to earlier menu. 1928 { 1929 byte tempVol = volumeSet - 25; 1930 1931 for (byte i = tempVol; i == 0; i--) { 1932 1933 digitalWrite(vMinus, LOW); 1934 delay(100); 1935 digitalWrite(vMinus, HIGH); 1936 } 1937 1938 volumeSet = 25; 1939 } 1940 1941 if (volumeSet <= 1) 1942 { 1943 volumeSet = 1; 1944 } 1945 1946 matrix.print(volumeSet); 1947 matrix.show(); 1948 1949 delay(buttonDelay); 1950 1951} 1952 1953void alarmOneSave() { 1954 1955 // Alarm one save and display. 1956 1957 if (alarmOneSch == 0) { // Alarm one off. 1958 1959 rtc.turnOffAlarm(1); 1960 digitalWrite(SSB, HIGH); 1961 digitalWrite(GSTQ, HIGH); 1962 digitalWrite(Mahnamahna, HIGH); 1963 1964 if (rtc.checkAlarmEnabled(1) == false) { 1965 1966 Serial.print("Alarm is disabled"); 1967 1968 } 1969 1970 else Serial.print("Alarm is enabled"); 1971 } 1972 1973 1974 else if (alarmOneSch == 1) { // Alarm one once. 1975 1976 rtc.setA1Time(1, alarmOneHourSet, alarmOneMinSet, 0, ALRM1_MATCH_HR_MIN_SEC, false, false, false); 1977 rtc.turnOnAlarm(1); 1978 rtc.checkAlarmEnabled(1); 1979 1980 if (rtc.checkAlarmEnabled(1) == false) { 1981 1982 Serial.print("Alarm is disabled"); 1983 1984 } 1985 1986 else Serial.print("Alarm is enabled"); 1987 } 1988 1989 else if (alarmOneSch == 2 || alarmOneSch == 3 || alarmOneSch == 4 || alarmOneSch == 5) { // Other alarm one schedules. 1990 1991 rtc.setA1Time(1, alarmOneHourSet, alarmOneMinSet, 0, ALRM1_MATCH_HR_MIN_SEC, false, false, false); 1992 rtc.turnOnAlarm(1); 1993 rtc.checkAlarmEnabled(1); 1994 1995 if (rtc.checkAlarmEnabled(1) == false) { 1996 1997 Serial.print("Alarm is disabled"); 1998 1999 } 2000 2001 else Serial.print("Alarm is enabled"); 2002 } 2003 2004 // Variable saving. 2005 2006 matrix.clear(); 2007 matrix.setCursor(5, 0); 2008 matrix.setTextColor(colors[colorSet]); 2009 matrix.print(F("Saved")); 2010 matrix.show(); 2011 delay(2000); 2012 2013 displayCurrentAlarmOne(); 2014 2015 char alarmOneDateAndTimeString[30]; 2016 2017 sprintf_P(alarmOneDateAndTimeString, PSTR("%02d:%02d"), alarmOneHourSet, alarmOneMinSet); 2018 Serial.print("Alarm One Set To: "); 2019 Serial.println(alarmOneDateAndTimeString); 2020 2021 menu = 0; // Reset menu option once saved. 2022 2023} // Close function. 2024 2025void alarmOneTriggered() { 2026 2027 // Alarm one check if triggered - // 0 = off / 1 = once / 2 = daily / 3 = weekday / 4 = weekend 2028 2029 // DoW: 1 = Sunday / 2 = Monday / 3 = Tuesday / 4 = Wednesday / 5 = Thursday / 6 = Friday / 7 = Saturday 2030 2031 if (rtc.checkIfAlarm(1)) 2032 2033 if (alarmOneSch == 0) { 2034 2035 if (debug == true) { 2036 2037 Serial.println(); 2038 Serial.print("No Alarm scheduled"); 2039 Serial.println(); 2040 } 2041 2042 } 2043 2044 else if (alarmOneSch == 1) { 2045 2046 if (debug == true) { 2047 2048 Serial.println(); 2049 Serial.print("Alarm schedule 1 Triggered / Once"); 2050 Serial.println(); 2051 } 2052 2053 digitalWrite(musicPlay, LOW); 2054 alarmOneState = true; 2055 2056 } 2057 2058 else if (alarmOneSch == 2) { 2059 2060 if (debug == true) { 2061 2062 Serial.println(); 2063 Serial.print("Alarm schedule 2 Triggered / Daily"); 2064 Serial.println(); 2065 } 2066 2067 digitalWrite(musicPlay, LOW); 2068 alarmOneState = true; 2069 2070 } 2071 2072 else if (alarmOneSch == 3) { 2073 2074 if (dowSet == 2 || dowSet == 3 || dowSet == 4 || dowSet == 5 || dowSet == 6) { 2075 2076 if (debug == true) { 2077 2078 Serial.println(); 2079 Serial.print("Alarm schedule 3 Triggered / Weekday"); 2080 Serial.println(); 2081 } 2082 2083 digitalWrite(musicPlay, LOW); 2084 alarmOneState = true; 2085 2086 } 2087 2088 } 2089 2090 else if (alarmOneSch == 4) { 2091 2092 if (dowSet == 1 || dowSet == 7) { 2093 2094 if (debug == true) { 2095 2096 Serial.println(); 2097 Serial.print("Alarm schedule 4 Triggered / Weekend"); 2098 Serial.println(); 2099 } 2100 2101 digitalWrite(musicPlay, LOW); 2102 alarmOneState = true; 2103 2104 } 2105 2106 } 2107 2108} // Close function. 2109 2110void alarmOneSleepCancel() { 2111 2112 // Alarm one sleep alarm. 2113 2114 if (alarmOneState == true && setSleepStart == true) { 2115 2116 digitalWrite(musicPlay, HIGH); 2117 sleepStart = rtc.getMinute(); 2118 setSleepStart = false; 2119 2120 matrix.clear(); 2121 matrix.setCursor(5, 0); 2122 matrix.setTextColor(colors[colorSet]); 2123 matrix.print(F("Sleep")); 2124 matrix.show(); 2125 delay(1250); 2126 2127 } 2128 2129 menu = 0; 2130 2131 // Get Alarm One current settings 2132 2133 displayCurrentAlarmOne(); 2134 2135} // Close function. 2136 2137void checkSleep() { 2138 2139 // Alarm one check sleep period. 2140 2141 byte currentTime = rtc.getMinute(); 2142 byte wakeTime = sleepStart + sleepSet; 2143 2144 if (wakeTime > 59) { 2145 2146 wakeTime = (wakeTime - 60); 2147 } 2148 2149 if (alarmOneState == true) { 2150 2151 if (currentTime == wakeTime) { 2152 2153 digitalWrite(musicPlay, LOW); 2154 Serial.println(); 2155 Serial.print("Sleep Time Ended"); 2156 Serial.println(); 2157 2158 } 2159 2160 } 2161 2162} // Close function. 2163 2164void displayScrollingDate() { 2165 2166 // This function is also used to cancel alarm one. 2167 2168 digitalWrite(SSB, HIGH); 2169 digitalWrite(GSTQ, HIGH); 2170 digitalWrite(Mahnamahna, HIGH); 2171 alarmOneState = false; 2172 2173 if (alarmOneSch == 0) { // Alarm one off. 2174 2175 rtc.turnOffAlarm(1); 2176 alarmOneSch = 0; 2177 } 2178 2179 else if (alarmOneSch == 1) { // Alarm one once. 2180 2181 rtc.turnOffAlarm(1); 2182 alarmOneSch = 0; 2183 eeAlarmOneSchChange = true; 2184 2185 if (eeAlarmOneSchChange == true) // Record change into EEPROM. 2186 { 2187 eeAlarmOneSchSetting = alarmOneSch; 2188 EEPROM.update(eeAlarmOneSchAddress, eeAlarmOneSchSetting); // Record alarm one schedule setting into EEPROM. 2189 eeAlarmOneSchChange = false; 2190 } 2191 2192 } 2193 2194 else if (alarmOneSch == 2 || alarmOneSch == 3 || alarmOneSch == 4) { // Alarm one daily, weekday or weekend 2195 2196 rtc.turnOnAlarm(1); 2197 rtc.checkAlarmEnabled(1); 2198 2199 } 2200 2201 // Get alarm one date and time. 2202 2203 displayCurrentAlarmOne(); 2204 2205 // Display date. 2206 2207 char* dayOfTheWeek = (dayArray[rtcArray[3]]); // returns actual day of the week. 2208 char* monthOfTheYear = (monthArray[rtcArray[5]]); // returns actual month of the year. 2209 2210 sprintf_P(DisplayDateString, PSTR("%s %02d %s %02d"), dayOfTheWeek, rtcArray[4], monthOfTheYear, rtcArray[6]); 2211 2212 if (!debug == true) { 2213 2214 // Print date, comment out before release, debugging only. 2215 2216 Serial.print("Today's Date is: "); 2217 Serial.println(DisplayDateString); 2218 2219 } // Close if. 2220 2221 String msgText = DisplayDateString; 2222 2223 int textLenght = msgText.length(); 2224 int msgSize = (textLenght * pixelPerChar) + (2 * pixelPerChar); // Calculate message length. 2225 int scrollingMax = (msgSize)+matrix.width() + matrix.width(); // Adjust displacement for message length. 2226 2227 if (!debug == true) { 2228 2229 // Print variables for debugging messages lenghts 2230 2231 Serial.print("Matrix Width = "); 2232 Serial.println(x); 2233 Serial.print(" Text Lenght = "); 2234 Serial.print(textLenght); 2235 Serial.print(" Message Size = "); 2236 Serial.print(msgSize); 2237 Serial.print(" Scrolling Max = "); 2238 Serial.println(scrollingMax); 2239 2240 } // Close if. 2241 2242 while (x > -scrollingMax) { // Only display text for one pass 2243 2244 matrix.fillScreen(0); 2245 matrix.setCursor(x, 0); 2246 matrix.setTextColor(colors[colorSet]); 2247 matrix.print(F("Today's Date : ")); 2248 matrix.print(DisplayDateString); 2249 2250 if (--x < -scrollingMax) 2251 { 2252 x = matrix.width(); 2253 } 2254 matrix.show(); 2255 delay(speedSet); 2256 2257 } // Close while. 2258 2259 // Reset width and menu flag. 2260 2261 x = matrix.width(); 2262 delay(500); 2263 menu = 0; 2264 2265} // Close function. 2266 2267void displayRandomWhite() { 2268 2269 // Display random messages. 2270 2271 randNumber = random(30); 2272 2273 Serial.print("Random Number: "); 2274 Serial.println(randNumber); 2275 2276 strcpy_P(buffer, (char*)pgm_read_word(&(string_table[randNumber]))); 2277 2278 String msgText = buffer; 2279 2280 Serial.print("Message Text From Table: "); 2281 Serial.println(msgText); 2282 2283 int textLenght = msgText.length(); 2284 int msgSize = (textLenght * pixelPerChar); // Calculate message length. 2285 int scrollingMax = (msgSize); // Adjust displacement for message length. 2286 2287 if (!debug == true) { 2288 2289 // Print variables for debugging messages lenghts 2290 2291 Serial.print("Matrix Width = "); 2292 Serial.println(x); 2293 Serial.print(" Text Lenght = "); 2294 Serial.print(textLenght); 2295 Serial.print(" Message Size = "); 2296 Serial.print(msgSize); 2297 Serial.print(" Scrolling Max = "); 2298 Serial.println(scrollingMax); 2299 2300 } // Close if. 2301 2302 while (x > -scrollingMax) { // Only display text for one pass 2303 2304 matrix.fillScreen(0); 2305 matrix.setCursor(x, 0); 2306 matrix.setTextColor(colors[colorSet]); 2307 matrix.print(msgText); 2308 2309 if (--x < -scrollingMax) 2310 { 2311 x = matrix.width(); 2312 } 2313 matrix.show(); 2314 delay(speedSet); 2315 2316 } // Close while. 2317 2318 // Reset width and menu flag. 2319 2320 x = matrix.width(); 2321 delay(500); 2322 menu = 0; 2323 2324} // Close function. 2325 2326void displayWelcomeMessage() { 2327 2328 // Display welcome message. Edit depending on who it is going to. 2329 2330 String msgText = " Insert message here..."; 2331 2332 Serial.print("Welcome Message Text: "); 2333 Serial.println(msgText); 2334 2335 int textLenght = msgText.length(); 2336 int msgSize = (textLenght * pixelPerChar); // Calculate message length. 2337 int scrollingMax = (msgSize); // Adjust displacement for message length. 2338 2339 if (!debug == true) { 2340 2341 // Print variables for debugging messages lenghts 2342 2343 Serial.print("Matrix Width = "); 2344 Serial.println(x); 2345 Serial.print(" Text Lenght = "); 2346 Serial.print(textLenght); 2347 Serial.print(" Message Size = "); 2348 Serial.print(msgSize); 2349 Serial.print(" Scrolling Max = "); 2350 Serial.println(scrollingMax); 2351 2352 } // Close if. 2353 2354 while (digitalRead(intPinAlarmOneSleep) == HIGH) { // Press sleep button to continue message. 2355 2356 while (x > -378) { // Only display text for one pass. 2357 2358 matrix.fillScreen(0); 2359 matrix.setCursor(x, 0); 2360 matrix.setTextColor(colors[colorSet]); 2361 matrix.print("Hold down the sleep button until music plays to continue... "); 2362 2363 if (--x < -378) 2364 { 2365 x = matrix.width(); 2366 } 2367 matrix.show(); 2368 delay(speedSet); 2369 2370 } // Close while. 2371 2372 x = matrix.width(); // Reset cursor position for next message. 2373 2374 } // Close while. 2375 2376 // Play the Muppets for a laugh... 2377 2378 digitalWrite(Mahnamahna, LOW); 2379 2380 while (x > -scrollingMax) { // Only display text for one pass. 2381 2382 matrix.fillScreen(0); 2383 matrix.setCursor(x, 0); 2384 matrix.setTextColor(colors[colorSet]); 2385 matrix.print(msgText); 2386 2387 if (--x < -scrollingMax) 2388 { 2389 x = matrix.width(); 2390 } 2391 matrix.show(); 2392 delay(16); 2393 2394 } // Close while. 2395 2396 // Reset width and menu flag. 2397 2398 x = matrix.width(); 2399 delay(500); 2400 menu = 0; 2401 eeWelcomeSetting = false; 2402 resetWelcome = false; 2403 EEPROM.update(eeWelcomeAddress, eeWelcomeSetting); // Record the welcome message flag into EEPROM. 2404 digitalWrite(Mahnamahna, HIGH); 2405 2406} // Close function. 2407 2408void recvBTWithStartAndEndMarker() { 2409 2410 // Save received BlueTooth data into array. 2411 2412 static boolean recvInProgress = false; 2413 byte ndx = 0; 2414 char startMarker = '('; 2415 char endMarker = ')'; 2416 char rc; 2417 receivedNumChar = 0; 2418 2419 while (s1Serial.available() > 0 && newData == false) { 2420 rc = s1Serial.read(); 2421 2422 if (recvInProgress == true) { 2423 if (rc != endMarker) { 2424 receivedChars[ndx] = rc; 2425 ndx++; 2426 receivedNumChar++; 2427 if (ndx >= numChars) { 2428 ndx = numChars - 1; 2429 } 2430 } 2431 else { 2432 receivedChars[ndx] = '\\0'; // terminate the string 2433 recvInProgress = false; 2434 ndx = 0; 2435 newData = true; 2436 } 2437 } 2438 2439 else if (rc == startMarker) { 2440 recvInProgress = true; 2441 } 2442 2443 } // Close while. 2444 2445} // Close function. 2446 2447void showNewBTData() { 2448 2449 // Call BlueTooth array data to be displayed. 2450 2451 if (newData == true) { 2452 2453 if (!debug == true) { 2454 2455 Serial.print("This just in ... "); 2456 Serial.println(); 2457 Serial.println(); 2458 Serial.println(receivedChars); 2459 Serial.println(); 2460 2461 } // Close if. 2462 2463 displayBlueToothText(); 2464 2465 newData = false; 2466 } 2467 2468} // Close function. 2469 2470void displayBlueToothText() { 2471 2472 // Display BlueTooth array data. 2473 2474 if (!debug == true) { 2475 2476 Serial.print("Whats in the Received Charaters Buffer? "); 2477 Serial.println(); 2478 Serial.println(); 2479 Serial.println(receivedChars); 2480 Serial.println(); 2481 2482 Serial.print("How many received charaters? "); 2483 Serial.println(receivedNumChar); 2484 Serial.println(); 2485 2486 } // Close if. 2487 2488 int msgSize = (receivedNumChar * pixelPerChar); // Calculate message length. 2489 int scrollingMax = (msgSize); // Adjust displacement for message length. 2490 2491 if (!debug == true) { 2492 2493 Serial.print("What size is scrolling max? "); 2494 Serial.println(scrollingMax); 2495 Serial.println(); 2496 2497 } // Close if. 2498 2499 while (x > -scrollingMax) { // Only display text for one pass 2500 2501 matrix.fillScreen(0); 2502 matrix.setCursor(x, 0); 2503 matrix.setTextColor(colors[colorSet]); 2504 matrix.print(receivedChars); 2505 2506 if (--x < -scrollingMax) 2507 { 2508 x = matrix.width(); 2509 } 2510 matrix.show(); 2511 delay(speedSet); 2512 2513 } // Close while. 2514 2515 // Clear the software serial buffer. 2516 2517 while (s1Serial.available() > 0) { 2518 s1Serial.read(); 2519 2520 if (!debug == true) { 2521 2522 Serial.println(); 2523 Serial.println("Clearing software serial buffer..."); 2524 2525 } // Close if. 2526 2527 } // Close while 2528 2529 // Clear the character array. 2530 2531 for (byte i = 0; i <= numChars; i++) { 2532 receivedChars[i] = 0; 2533 2534 if (!debug == true) { 2535 Serial.println(); 2536 Serial.println("Clearing character array..."); 2537 2538 } // Close if. 2539 2540 } // Close for. 2541 2542 Serial.println(); 2543 Serial.println("Ready."); 2544 Serial.println(); 2545 2546 // Reset width, menu, received # characters and new data flags. 2547 2548 x = matrix.width(); 2549 2550 receivedNumChar = 0; 2551 menu = 0; 2552 2553} // Close function. 2554 2555void displayCurrentAlarmOne() { 2556 2557 rtc.getA1Time(alarmOneDowSet, alarmOneHourSet, alarmOneMinSet, alarmOneSecSet, alarmBits, alarmDy, alarmH12, alarmPm); 2558 2559 if (debug == true) { 2560 2561 Serial.println(); 2562 2563 if (alarmDy) { 2564 Serial.print("DoW: "); 2565 } 2566 else { 2567 Serial.print("Date: "); 2568 } 2569 Serial.print(alarmOneDowSet, DEC); 2570 2571 Serial.print(" "); 2572 Serial.print("Alarm One Set To: "); 2573 Serial.print(alarmOneHourSet, DEC); 2574 Serial.print(':'); 2575 Serial.print(alarmOneMinSet, DEC); 2576 Serial.print(':'); 2577 Serial.print(alarmOneSecSet, DEC); 2578 Serial.print(' '); 2579 2580 /* if (alarmH12) { 2581 if (alarmPm) { 2582 Serial.print("pm "); 2583 } 2584 else { 2585 Serial.print("am "); 2586 } 2587 } 2588 */ 2589 2590 if (rtc.checkAlarmEnabled(1)) { 2591 Serial.print("Alarm is enabled"); 2592 } 2593 2594 else { 2595 Serial.print("Alarm is disabled"); 2596 } 2597 Serial.println(); 2598 } 2599 2600 Serial.println(); 2601 2602} // Close function. 2603 2604void resetAllSettings() { 2605 2606 // Set date / time and Send to RTC module. 2607 2608 rtc.setYear(21); 2609 rtc.setMonth(01); 2610 rtc.setDate(01); 2611 rtc.setDoW(5); 2612 rtc.setHour(0); 2613 rtc.setMinute(0); 2614 rtc.setSecond(0); 2615 2616 rtc.setA1Time(1, 0, 0, 0, ALRM1_MATCH_HR_MIN_SEC, false, false, false); // Set alarm and send to RTC module. 2617 2618 EEPROM.update(ee1224Address, 0); // Record the 12 / 24 hour clock setting into EEPROM. 2619 2620 EEPROM.update(eeBrightAddress, 5); // Record brightness setting into EEPROM. 2621 2622 EEPROM.update(eeColAddress, 6); // Record brightness setting into EEPROM. 2623 2624 EEPROM.update(eeSpeedAddress, 45); // Record speed setting into EEPROM. 2625 2626 EEPROM.update(eeAlarmOneSchAddress, 0); // Record alarm one schedule setting into EEPROM. 2627 2628 EEPROM.update(eeSleepSetAddress, 10); // Record sleep setting into EEPROM. 2629 2630 EEPROM.update(eeMusicAddress, 0); // Record music setting into EEPROM. 2631 2632 EEPROM.update(eeRTCResetAddress, 0); // Record RTC reset setting back into EEPROM. 2633 eeRTCResetChange = false; 2634 resetRTC = false; 2635 2636}
Digital Alarm Clock
arduino
Main sketch for the Digital Alarm Clock
1/* 2 Name: Swear_Box.ino - NeoPixel Clock using a DS3231 3 Created: 7/14/2020 2:23:26 PM 4 5 Original code kindly referenced from: Tiziano Bianchettin 6 7 Serioulsy hacked about by: Christopher Cooper in 2020 8*/ 9 10// Libraries. 11 12#include <avr/pgmspace.h> // Special memory library. 13#include <DS3231.h> // RTC library. 14#include <Wire.h> // I2C library. 15#include <EEPROM.h> // EEPROM library. 16#include <SoftwareSerial.h> // Software serial library. 17 18// Declare real time clock object. 19 20DS3231 rtc; 21 22// Configure software serial pins. 23 24SoftwareSerial s1Serial(20, 21); // RX, TX, Bluetooth module. 25 26// Adafruit NeoPixel libraries. 27 28#include <Adafruit_GFX.h> 29#include <Adafruit_NeoMatrix.h> 30#include <Adafruit_NeoPixel.h> 31 32// Configure NeoPixel. 33 34#define PIXEL_COUNT 320 // Total number of NeoPixels. 35#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels. 36 37// Declare NeoPixel matrix object. 38 39Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, 5, 1, 6, 40 41 NEO_MATRIX_TOP + NEO_MATRIX_LEFT + 42 NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE, 43 NEO_RGB + NEO_KHZ800); 44 45// Argument 1 = Number of rows in NeoPixel array. 46// Argument 2 = Number of columns in NeoPixel array. 47// Argument 3 = Number of horizontal tiles. 48// Argument 4 = Number of vertical tiles. 49// Argument 5 = Arduino pin number. 50// From adafruit help for tiled arrays matrixWidth, matrixHeight, tilesX, tilesY, pin, matrixType, ledType); 51 52// Configure NeoPixel colours and variables. 53 54const uint16_t colors[8] = { 55 matrix.Color(255, 0, 0), 56 matrix.Color(0, 255, 0), 57 matrix.Color(255, 255, 0), 58 matrix.Color(0, 0, 255), 59 matrix.Color(255, 0, 255), 60 matrix.Color(0, 255, 255), 61 matrix.Color(255, 255, 255) 62}; 63 64char colorArray[9][8] = { "Green", "Red", "Yellow", "Blue", "Teal", "Purple", "White" }; 65 66byte pixelPerChar = 6; // Width of standard font characters is 8X6 pixels. 67int x = matrix.width(); // Width of the NeoPixel display. 68byte speedSet = 10; // Scrolling text speed. 69byte tempSpeedSet = 50; // Used for reversing speed variable. 70byte colorSet = 6; // Color selection. 71byte brightnessSet = 5; // Display brightness. 72 73// Configure buttons & pins. 74 75const byte intPinAlarmOneSet = 4; // Buttom to set alarm one. 76const byte intPinMenu = 5; // Button SET MENU' using Interupt. 77const byte intPinScrollingDate = 8; // Button to call display Date Function using Interupt. 78const byte intPinWhite = 9; // Button to call blue random strings using Interupt. 79const byte intPinAlarmOneSleep = 10; // Sleep, cancel alarm one. 80 81const byte bPlus = 2; // Button + 82const byte bMinus = 3; // Button - 83const byte vPlus = A0; // Volume + 84const byte vMinus = 13; // Volume - 85 86const byte Mahnamahna = A1; // The Muppets Mahnamaha pin trigger. 87const byte GSTQ = A2; // God save the queen anthem pin trgger. 88const byte SSB = A3; // Star spangled banner anthem pin trigger. 89 90// Global variables. 91 92boolean debug = false; // Debugging flag for serial output. 93 94byte volumeSet = 25; // Volume setting. 95bool musicScroll = false; // Music menu scroll prevention. 96char musicArray[4][25] = { "God Save the Queen", "Star Spangled Banner" , "The Muppets - Mahnamahna" }; // Music track array. 97byte musicSet = 0; // Music setting menu. 98byte musicPlay = A1; // Music setting menu. 99 100int buttonDelay = 200; 101 102bool h12; // 12 / 24 hour clock flag from RTC. 103bool PM; // AM / PM clock flag from RTC. 104bool set1224 = false; // 12 / 24 hour clock flag. 105bool Century = false; // Century flag from RTC. 106bool resetRTC = false; // Reset RTC flag. 107bool resetWelcome = false; // Reset welcome message flag. 108 109byte alarmBits; // Alarm variables. 110bool alarmDy; 111bool alarmH12; 112bool alarmPm; 113 114bool alarmOneState = false; // Sleep variables. 115bool setSleepStart = false; 116byte sleepStart; 117byte sleepSet = 5; 118 119#define ALRM1_MATCH_EVERY_SEC 0b1111 // Once a second. 120#define ALRM1_MATCH_SEC 0b1110 // When seconds match. 121#define ALRM1_MATCH_MIN_SEC 0b1100 // When minutes and seconds match. 122#define ALRM1_MATCH_HR_MIN_SEC 0b1000 // When hours, minutes, and seconds match. 123 124#define ALRM2_ONCE_PER_MIN 0b111 // Once per minute (00 seconds of every minute). 125#define ALRM2_MATCH_MIN 0b110 // When minutes match. 126#define ALRM2_MATCH_HR_MIN 0b100 // When hours and minutes match. 127 128byte hourSet; // Set time variables. 129byte minSet; 130byte yearSet; 131byte monthSet; 132byte daySet; 133byte dowSet; 134 135byte alarmOneHourSet; // Set alarm one time variables. 136byte alarmOneMinSet; 137byte alarmOneSecSet = 0; 138byte alarmOneYearSet; 139byte alarmOneMonthSet; 140byte alarmOneDaySet; 141byte alarmOneDowSet; 142 143byte alarmOneSch; 144char* alarmSchArray[6] = { "Off" , "Once" , "Daily" , "M - F" , "S - S"}; // off, once, daily, weekday & weekend. 145 146long randNumber; 147 148volatile byte menu = 0; // Menu system variable for scrolling through options. 149 150int rtcArray[8]; // RTC array for date time variables. 151byte rtcA1Array[7]; // RTC alarm array. 152 153char* dayArray[9] = { "","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" }; 154char* dayShortArray[9] = { "","Su","Mo","Tu","We","Th","Fr","Sa"}; // Used for DoW menu setting only. Leading "" is because "0" is not a DoW parameter acording to the DS3231 data sheet. 155char* monthArray[14] = { "", 156 "January", 157 "February", 158 "March", 159 "April", 160 "May", 161 "June", 162 "July", 163 "August", 164 "September", 165 "October", 166 "November", 167 "December" 168}; // Initial "" is to solve the leading Zero in the array when matching to the month select function. 169 170char DisplayDateString[30]; // Strings to concatinate rtc variables in the right format x 4 171char DateAndTimeString[40]; 172char HourAndMinuteString[20]; 173char MinuteAndSecondString[20]; 174 175// Strings, lots and lots of strings, placing them into flash to save SRAM. 176 177const char string_0[] PROGMEM = "The greatest glory in living lies not in never falling, but in rising every time we fall - Nelson Mandela"; // "String 0" etc are strings to store - change to suit. 178const char string_1[] PROGMEM = "The way to get started is to quit talking and begin doing - Walt Disney"; 179const char string_2[] PROGMEM = "If life were predictable it would cease to be life, and be without flavor - Eleanor Roosevelt"; 180const char string_3[] PROGMEM = "Great things never come from comfort zones..."; 181const char string_4[] PROGMEM = "If you look at what you have in life, you'll always have more. If you look at what you don't have in life, you'll never have enough - Oprah Winfrey"; 182const char string_5[] PROGMEM = "If you set your goals ridiculously high and it's a failure, you will fail above everyone else's success - James Cameron"; 183const char string_6[] PROGMEM = "Life is what happens when you're busy making other plans - John Lennon"; 184const char string_7[] PROGMEM = "Spread love everywhere you go. Let no one ever come to you without leaving happier - Mother Teresa"; 185const char string_8[] PROGMEM = "When you reach the end of your rope, tie a knot in it and hang on - Franklin D.Roosevelt"; 186const char string_9[] PROGMEM = "Always remember that you are absolutely unique. Just like everyone else - Margaret Mead"; 187const char string_10[] PROGMEM = "Don't judge each day by the harvest you reap but by the seeds that you plant - Robert Louis Stevenson"; 188const char string_11[] PROGMEM = "The future belongs to those who believe in the beauty of their dreams - Eleanor Roosevelt"; 189const char string_12[] PROGMEM = "Tell me and I forget. Teach me and I remember. Involve me and I learn - Benjamin Franklin"; 190const char string_13[] PROGMEM = "The best and most beautiful things in the world cannot be seen or even touched - they must be felt with the heart - Helen Keller"; 191const char string_14[] PROGMEM = "It is during our darkest moments that we must focus to see the light - Aristotle"; 192const char string_15[] PROGMEM = "Whoever is happy will make others happy too - Anne Frank"; 193const char string_16[] PROGMEM = "In the end, it's not the years in your life that count. It's the life in your years - Abraham Lincoln"; 194const char string_17[] PROGMEM = "Life is never fair, and perhaps it is a good thing for most of us that it is not - Oscar Wilde"; 195const char string_18[] PROGMEM = "Only a life lived for others is a life worthwhile - Albert Einstein"; 196const char string_19[] PROGMEM = "The purpose of our lives is to be happy - Dalai Lama"; 197const char string_20[] PROGMEM = "Life is really simple, but we insist on making it complicated - Confucius"; 198const char string_21[] PROGMEM = "Keep smiling, because life is a beautiful thing and there's so much to smile about - Marilyn Monroe"; 199const char string_22[] PROGMEM = "Love the life you live. Live the life you love - Bob Marley"; 200const char string_23[] PROGMEM = "Life is made of ever so many partings welded together - Charles Dickens"; 201const char string_24[] PROGMEM = "I find that the harder I work, the more luck I seem to have - Thomas Jefferson"; 202const char string_25[] PROGMEM = "The secret of success is to do the common thing uncommonly well - John D.Rockefeller Jr."; 203const char string_26[] PROGMEM = "I never dreamed about success, I worked for it - Estee Lauder"; 204const char string_27[] PROGMEM = "Try not to become a man of success. Rather become a man of value - Albert Einstein"; 205const char string_28[] PROGMEM = "Nothing is impossible, the word itself says, ‘I'm possible!' - Audrey Hepburn"; 206const char string_29[] PROGMEM = "Whether you think you can or you think you can't, you're right - Henry Ford"; 207 208// Table to reference the strings. 209 210const char* const string_table[] PROGMEM = { string_0, string_1, string_2, string_3, string_4, string_5, string_6, string_7, string_8, string_9, 211 string_10, string_11, string_12, string_13, string_14, string_15, string_16, string_17, string_18, string_19, 212 string_20, string_21, string_22, string_23, string_24, string_25, string_26, string_27, string_28, string_29 }; 213 214char buffer[120]; // Make sure this is large enough for the largest string it must hold 215 216// Configure BlueTooth data variables. 217 218const byte numChars = 64; // Size of charater array that can be received. 219char receivedChars[numChars]; // An array to store the received data. 220boolean newData = false; // Flag to detech new serial data is ready to display from BlueTooth. 221byte receivedNumChar = 0; // Count to help calculate scrolling max setting. 222 223// Configure EEEPROM. 224 225int ee1224Address = 0; // EEPROM address for 12 / 24 hour clock setting. 226bool ee1224Setting; // Actual commit for writing, 2 bytes. 227bool ee1224Change = false; // To save EEPROM writes. 228 229int eeBrightAddress = 4; // EEPROM address for brightness setting. 230byte eeBrightSetting; // Actual commit for writing, 4 bytes. 231bool eeBrightChange = false; // To save EEPROM writes. 232 233int eeColAddress = 8; // EEPROM address for colour setting. 234byte eeColSetting; // Actual commit for writing, 4 bytes. 235bool eeColChange = false; // To save EEPROM writes. 236 237int eeSpeedAddress = 12; // EEPROM address for speed setting. 238byte eeSpeedSetting; // Actual commit for writing, 4 bytes. 239bool eeSpeedChange = false; // To save EEPROM writes. 240 241int eeAlarmOneSchAddress = 16; // EEPROM address for alarm one schedule setting. 242byte eeAlarmOneSchSetting; // Actual commit for writing, 4 bytes. 243bool eeAlarmOneSchChange = false; // To save EEPROM writes. 244 245int eeMusicAddress = 20; // EEPROM address for music setting. 246byte eeMusicSetting; // Actual commit for writing, 4 bytes. 247bool eeMusicChange = false; // To save EEPROM writes. 248 249int eeSleepSetAddress = 24; // EEPROM address for sleep duration setting. 250byte eeSleepSetSetting; // Actual commit for writing, 4 bytes. 251bool eeSleepSetChange = false; // To save EEPROM writes. 252 253int eeRTCResetAddress = 28; // EEPROM address for RTC reset. 254bool eeRTCResetSetting; // Actual commit for writing, 2 bytes. 255bool eeRTCResetChange = false; // To save EEPROM writes. 256 257int eeWelcomeAddress = 32; // EEPROM address for welcome message. 258bool eeWelcomeSetting; // Actual commit for writing, 2 bytes. 259bool eeWelcomeChange = false; // To save EEPROM writes. 260 261 262void setup() { 263 264 // Configure button pin modes. 265 266 pinMode(intPinMenu, INPUT); 267 pinMode(intPinScrollingDate, INPUT); 268 pinMode(intPinWhite, INPUT); 269 pinMode(intPinAlarmOneSet, INPUT); 270 pinMode(intPinAlarmOneSleep, INPUT); 271 272 pinMode(bPlus, INPUT); // Menu plus / minus pins. 273 pinMode(bMinus, INPUT); 274 275 pinMode(vPlus, OUTPUT); // Volume plus / minus pins. 276 pinMode(vMinus, OUTPUT); 277 278 pinMode(GSTQ, OUTPUT); // Sound trigger pins. 279 pinMode(SSB, OUTPUT); 280 pinMode(Mahnamahna, OUTPUT); 281 282 digitalWrite(GSTQ, HIGH); // Ensure sounds do not start on start up. 283 digitalWrite(SSB, HIGH); 284 digitalWrite(Mahnamahna, HIGH); 285 286 // Configure interupts. 287 288 attachInterrupt(digitalPinToInterrupt(intPinMenu), menuISR_Menu, FALLING); 289 attachInterrupt(digitalPinToInterrupt(intPinScrollingDate), dateISR_ScrollingDate, FALLING); 290 attachInterrupt(digitalPinToInterrupt(intPinWhite), whiteISR_ScrollingRandom, FALLING); 291 attachInterrupt(digitalPinToInterrupt(intPinAlarmOneSet), alarmISR_alarmOneSet, FALLING); 292 attachInterrupt(digitalPinToInterrupt(intPinAlarmOneSleep), alarmISR_alarmOneSleep, FALLING); 293 294 // Begin serial, mySerial, wire and RTC module. 295 296 Serial.begin(38400); 297 s1Serial.begin(38400); // Used for Bluetooth module. 298 Wire.begin(); 299 300 // Display current date and time, comment out before release, debugging only. 301 302 rtc.setClockMode(false); // Set to 24h 303 304 rtcArray[6] = rtc.getYear(); 305 rtcArray[5] = rtc.getMonth(Century); 306 rtcArray[4] = rtc.getDate(); 307 rtcArray[3] = rtc.getDoW(); 308 dowSet = rtc.getDoW(); 309 rtcArray[2] = rtc.getHour(h12, PM); 310 rtcArray[1] = rtc.getMinute(); 311 rtcArray[0] = rtc.getSecond(); 312 313 char* dayOfTheWeek = (dayArray[rtcArray[3]]); // Returns actual day of the week. 314 char* monthOfTheYear = (monthArray[rtcArray[5]]); // Returns actual month of the year. 315 316 // Function to output data to serial monitor for debugging. 317 318 sprintf_P(DateAndTimeString, PSTR("%02d:%02d on %s %02d %s %02d"), rtcArray[2], rtcArray[1], dayOfTheWeek, rtcArray[4], monthOfTheYear, rtcArray[6]); 319 Serial.println(); 320 Serial.print("The current time and date is "); 321 Serial.println(DateAndTimeString); 322 323 // Read EEPROM settings to see if RTC needs master reset. 324 325 EEPROM.get(eeRTCResetAddress, eeRTCResetSetting); 326 327 if (eeRTCResetSetting == 0) { 328 329 resetRTC = false; 330 } 331 332 else if (eeRTCResetSetting == 1) { 333 334 resetRTC = true; 335 } 336 337 if (resetRTC == true) { 338 339 resetAllSettings(); 340 341 } 342 343 // Read EEPROM settings back into volatile memory. 344 345 EEPROM.get(ee1224Address, ee1224Setting); // 12 / 24 Hour clock setting. 346 347 if (ee1224Setting == 0) { 348 349 set1224 = false; 350 } 351 352 else if (ee1224Setting == 1) { 353 354 set1224 = true; 355 } 356 357 EEPROM.get(eeBrightAddress, eeBrightSetting); // Brightness setting. 358 359 brightnessSet = eeBrightSetting; 360 361 EEPROM.get(eeColAddress, eeColSetting); // Colour setting. 362 363 colorSet = eeColSetting; 364 365 EEPROM.get(eeSpeedAddress, eeSpeedSetting); // Scrolling speed setting. 366 367 tempSpeedSet = eeSpeedSetting; 368 369 speedSet = 61 - tempSpeedSet; 370 371 EEPROM.get(eeAlarmOneSchAddress, eeAlarmOneSchSetting); // Alarm setting. 372 373 alarmOneSch = eeAlarmOneSchSetting; 374 375 EEPROM.get(eeMusicAddress, eeMusicSetting); // Music setting. 376 377 musicSet = eeMusicSetting; 378 379 if (musicSet == 0) { // Set which music to play just in case power fails 380 381 musicPlay = GSTQ; 382 383 } 384 385 else if (musicSet == 1) { 386 387 musicPlay = SSB; 388 389 } 390 391 else if (musicSet == 2) { 392 393 musicPlay == Mahnamahna; 394 395 } 396 397 EEPROM.get(eeSleepSetAddress, eeSleepSetSetting); // Sleep setting. 398 399 sleepSet = eeSleepSetSetting; 400 401 EEPROM.get(eeWelcomeAddress, eeWelcomeSetting); // Welcome message on start up setting. 402 403 if (eeWelcomeSetting == 0) { 404 405 resetWelcome = false; 406 } 407 408 else if (eeWelcomeSetting == 1) { 409 410 resetWelcome = true; 411 } 412 413 // Begin NeoPixel matrix. 414 415 matrix.begin(); 416 matrix.setTextWrap(false); 417 matrix.setBrightness(brightnessSet); 418 matrix.setTextColor(colors[colorSet]); 419 420 // Configure random number. 421 422 randomSeed(analogRead(A3)); 423 424 // Get Alarm One current settings 425 426 displayCurrentAlarmOne(); 427 428 // Display welcome message. 429 430 if (resetWelcome == true) { 431 432 menu = 32; 433 } 434 435} // Close setup. 436 437void loop() { 438 439 // Check menu and trigger menu functions from interupt. 440 441 if (menu == 0) 442 { 443 displayCurrentTime(); 444 } 445 if (menu == 1) 446 { 447 displaySetHour(); 448 } 449 if (menu == 2) 450 { 451 displaySetMinute(); 452 } 453 if (menu == 3) 454 { 455 displaySetYear(); 456 } 457 if (menu == 4) 458 { 459 displaySetMonth(); 460 } 461 if (menu == 5) 462 { 463 displaySetDay(); 464 } 465 if (menu == 6) 466 { 467 displaySetDoW(); 468 } 469 if (menu == 7) 470 { 471 amPm(); 472 } 473 if (menu == 8) 474 { 475 displayColorSet(); 476 } 477 if (menu == 9) 478 { 479 displayBrightness(); 480 } 481 if (menu == 10) 482 { 483 displaySpeedSet(); 484 } 485 if (menu == 11) 486 { 487 resetWelcomeMessage(); 488 } 489 if (menu == 12) 490 { 491 resetClock(); 492 } 493 if (menu == 13) 494 { 495 saveTimeAndDate(); 496 } 497 if (menu == 20) 498 { 499 alarmOneSchedule(); 500 } 501 if (menu == 21) 502 { 503 alarmOneSetHour(); 504 } 505 if (menu == 22) 506 { 507 alarmOneSetMinute(); 508 } 509 if (menu == 23) 510 { 511 alarmOneMusicSet(); 512 } 513 if (menu == 24) 514 { 515 alarmOneSleepTime(); 516 } 517 if (menu == 25) 518 { 519 alarmOneVolume(); 520 } 521 if (menu == 26) 522 { 523 alarmOneSave(); 524 } 525 if (menu == 27) 526 { 527 alarmOneSleepCancel(); 528 } 529 if (menu == 30) 530 { 531 displayScrollingDate(); 532 } 533 if (menu == 31) 534 { 535 displayRandomWhite(); // Display random stored messages from array. 536 } 537 if (menu == 32) 538 { 539 displayWelcomeMessage(); // Display welcome message on start up only. 540 } 541 542 alarmOneTriggered(); // Check if alarm one triggered. 543 checkSleep(); // Check if sleep time has been reached. 544 recvBTWithStartAndEndMarker(); // Receive serial data by bluetooth. 545 showNewBTData(); // Display serial data once received. 546 547} // Close loop. 548 549void menuISR_Menu() { 550 551 static unsigned long last_interrupt_time = 0; // Function to solve debounce 552 unsigned long interrupt_time = millis(); 553 554 if (interrupt_time - last_interrupt_time > 200) 555 { 556 menu++; 557 } 558 559 if (menu > 13) 560 { 561 menu = 0; 562 digitalWrite(SSB, HIGH); // These digital writes are to stop music playing if menu is pressed by mistake during alarm settings 563 digitalWrite(GSTQ, HIGH); 564 digitalWrite(Mahnamahna, HIGH); 565 } 566 567 last_interrupt_time = interrupt_time; 568 569} // Close function. 570 571void alarmISR_alarmOneSet() { 572 573 static unsigned long last_interrupt_time = 0; // Function to solve debounce 574 unsigned long interrupt_time = millis(); 575 576 if (interrupt_time - last_interrupt_time > 200) 577 { 578 if (menu == 0) { 579 580 menu = 20; 581 582 } 583 584 else menu++; 585 586 } 587 588 last_interrupt_time = interrupt_time; 589 590} // Close function. 591 592 593void alarmISR_alarmOneSleep() { 594 595 static unsigned long last_interrupt_time = 0; // Function to solve debounce 596 unsigned long interrupt_time = millis(); 597 598 if (interrupt_time - last_interrupt_time > 200) 599 { 600 601 if (menu == 0) { 602 603 menu = 27; 604 setSleepStart = true; 605 606 } 607 608 } 609 610 last_interrupt_time = interrupt_time; 611 612} // Close function. 613 614void dateISR_ScrollingDate() { 615 616 static unsigned long last_interrupt_dateISR_time = 0; // Function to solve debounce 617 unsigned long interrupt_dateISR_time = millis(); 618 619 if (interrupt_dateISR_time - last_interrupt_dateISR_time > 200) 620 { 621 menu = 30; 622 } 623 624 last_interrupt_dateISR_time = interrupt_dateISR_time; 625 626} // Close function. 627 628void whiteISR_ScrollingRandom() { 629 630 static unsigned long last_interrupt_dateISR_time = 0; // Function to solve debounce 631 unsigned long interrupt_dateISR_time = millis(); 632 633 if (interrupt_dateISR_time - last_interrupt_dateISR_time > 200) 634 { 635 menu = 31; 636 } 637 638 last_interrupt_dateISR_time = interrupt_dateISR_time; 639 640} // Close function. 641 642void displayCurrentTime() { 643 644 // Get current date and time. 645 646 rtcArray[6] = rtc.getYear(); 647 rtcArray[5] = rtc.getMonth(Century); 648 rtcArray[4] = rtc.getDate(); 649 rtcArray[3] = rtc.getDoW(); 650 dowSet = rtc.getDoW(); 651 rtcArray[2] = rtc.getHour(h12, PM); 652 rtcArray[1] = rtc.getMinute(); 653 rtcArray[0] = rtc.getSecond(); 654 655 // Configure either 12 or 24 hour time display. 656 657 if (set1224 == true) { 658 659 int hr12; 660 661 if (rtcArray[2] > 12) { 662 663 hr12 = rtcArray[2] - 12; 664 sprintf_P(HourAndMinuteString, PSTR("%2d:%02d"), hr12, rtcArray[1]); 665 666 } 667 668 else if (rtcArray[2] <= 12) { 669 670 sprintf_P(HourAndMinuteString, PSTR("%2d:%02d"), rtcArray[2], rtcArray[1]); 671 672 } 673 674 } 675 676 else sprintf_P(HourAndMinuteString, PSTR("%02d:%02d"), rtcArray[2], rtcArray[1]); 677 678 // Update setting variables, so when selecting, they are to current time. 679 680 minSet = rtcArray[1]; 681 hourSet = rtcArray[2]; 682 dowSet = rtcArray[3]; 683 daySet = rtcArray[4]; 684 monthSet = rtcArray[5]; 685 yearSet = rtcArray[6]; 686 687 // Check if current time is behind displayed time to save display refreshes and flickering, display is changed. 688 689 if (HourAndMinuteString >= HourAndMinuteString) { 690 691 matrix.clear(); 692 693 if (set1224 == true) { // Configure 12 hour display and set cursor positions. 694 695 int hr12; 696 697 if (rtcArray[2] > 12) { 698 699 hr12 = rtcArray[2] - 12; 700 701 if (hr12 <= 9) { 702 703 matrix.setCursor(3, 0); 704 705 } 706 707 else matrix.setCursor(6, 0); 708 709 } 710 711 else if (rtcArray[2] <= 9) { 712 713 matrix.setCursor(3, 0); 714 715 } 716 717 else matrix.setCursor(6, 0); 718 719 } 720 721 else matrix.setCursor(6, 0); 722 723 // Configure & display PM sign for 12 hour clock display. 724 725 if (set1224 == true) { 726 727 if (rtcArray[2] >= 12) { 728 729 if (colorSet == 0) { 730 731 matrix.setPixelColor(300, 255, 0, 0); 732 matrix.setPixelColor(301, 255, 0, 0); 733 matrix.setPixelColor(308, 255, 0, 0); 734 matrix.setPixelColor(309, 255, 0, 0); 735 matrix.setPixelColor(316, 255, 0, 0); 736 } 737 738 else if (colorSet == 1) { 739 740 matrix.setPixelColor(300, 0, 255, 0); 741 matrix.setPixelColor(301, 0, 255, 0); 742 matrix.setPixelColor(308, 0, 255, 0); 743 matrix.setPixelColor(309, 0, 255, 0); 744 matrix.setPixelColor(316, 0, 255, 0); 745 } 746 747 else if (colorSet == 2) { 748 749 matrix.setPixelColor(300, 255, 255, 0); 750 matrix.setPixelColor(301, 255, 255, 0); 751 matrix.setPixelColor(308, 255, 255, 0); 752 matrix.setPixelColor(309, 255, 255, 0); 753 matrix.setPixelColor(316, 255, 255, 0); 754 } 755 756 else if (colorSet == 3) { 757 758 matrix.setPixelColor(300, 0, 0, 255); 759 matrix.setPixelColor(301, 0, 0, 255); 760 matrix.setPixelColor(308, 0, 0, 255); 761 matrix.setPixelColor(309, 0, 0, 255); 762 matrix.setPixelColor(316, 0, 0, 255); 763 } 764 765 else if (colorSet == 4) { 766 767 matrix.setPixelColor(300, 255, 0, 255); 768 matrix.setPixelColor(301, 255, 0, 255); 769 matrix.setPixelColor(308, 255, 0, 255); 770 matrix.setPixelColor(309, 255, 0, 255); 771 matrix.setPixelColor(316, 255, 0, 255); 772 } 773 774 else if (colorSet == 5) { 775 776 matrix.setPixelColor(300, 0, 255, 255); 777 matrix.setPixelColor(301, 0, 255, 255); 778 matrix.setPixelColor(308, 0, 255, 255); 779 matrix.setPixelColor(309, 0, 255, 255); 780 matrix.setPixelColor(316, 0, 255, 255); 781 } 782 783 else if (colorSet == 6) { 784 785 matrix.setPixelColor(300, 255, 255, 255); 786 matrix.setPixelColor(301, 255, 255, 255); 787 matrix.setPixelColor(308, 255, 255, 255); 788 matrix.setPixelColor(309, 255, 255, 255); 789 matrix.setPixelColor(316, 255, 255, 255); 790 } 791 } 792 } 793 794 // Configure & display alarm one sign. 795 796 if (rtc.checkAlarmEnabled(1)) { 797 798 if (colorSet == 0) { 799 800 matrix.setPixelColor(276, 255, 0, 0); 801 matrix.setPixelColor(277, 255, 0, 0); 802 matrix.setPixelColor(284, 255, 0, 0); 803 matrix.setPixelColor(285, 255, 0, 0); 804 } 805 806 else if (colorSet == 1) { 807 808 matrix.setPixelColor(276, 0, 255, 0); 809 matrix.setPixelColor(277, 0, 255, 0); 810 matrix.setPixelColor(284, 0, 255, 0); 811 matrix.setPixelColor(285, 0, 255, 0); 812 } 813 814 else if (colorSet == 2) { 815 816 matrix.setPixelColor(276, 255, 255, 0); 817 matrix.setPixelColor(277, 255, 255, 0); 818 matrix.setPixelColor(284, 255, 255, 0); 819 matrix.setPixelColor(285, 255, 255, 0); 820 } 821 822 else if (colorSet == 3) { 823 824 matrix.setPixelColor(276, 0, 0, 255); 825 matrix.setPixelColor(277, 0, 0, 255); 826 matrix.setPixelColor(284, 0, 0, 255); 827 matrix.setPixelColor(285, 0, 0, 255); 828 } 829 830 else if (colorSet == 4) { 831 832 matrix.setPixelColor(276, 255, 0, 255); 833 matrix.setPixelColor(277, 255, 0, 255); 834 matrix.setPixelColor(284, 255, 0, 255); 835 matrix.setPixelColor(285, 255, 0, 255); 836 } 837 838 else if (colorSet == 5) { 839 840 matrix.setPixelColor(276, 0, 255, 255); 841 matrix.setPixelColor(277, 0, 255, 255); 842 matrix.setPixelColor(284, 0, 255, 255); 843 matrix.setPixelColor(285, 0, 255, 255); 844 } 845 846 else if (colorSet == 6) { 847 848 matrix.setPixelColor(276, 255, 255, 255); 849 matrix.setPixelColor(277, 255, 255, 255); 850 matrix.setPixelColor(284, 255, 255, 255); 851 matrix.setPixelColor(285, 255, 255, 255); 852 } 853 } 854 855 } 856 857 matrix.setTextColor(colors[colorSet]); 858 matrix.print(HourAndMinuteString); 859 matrix.show(); 860 861} // Close function. 862 863void displaySetHour() { 864 865 // Set hour time setting. 866 867 if (digitalRead(bPlus) == LOW) 868 { 869 if (hourSet == 23) // 24 hour clock. 870 { 871 hourSet = 0; 872 } 873 else 874 { 875 hourSet = hourSet + 1; // Increment by 1. 876 } 877 } 878 if (digitalRead(bMinus) == LOW) 879 { 880 if (hourSet == 0) 881 { 882 hourSet = 23; 883 } 884 else 885 { 886 hourSet = hourSet - 1; // Decrement by 1. 887 } 888 } 889 890 matrix.clear(); 891 matrix.setCursor(1, 0); 892 matrix.print(F("Hr :")); 893 matrix.show(); 894 895 matrix.print(hourSet); 896 matrix.show(); 897 898 delay(buttonDelay); 899 900} // Close function. 901 902void displaySetMinute() { 903 904 // Setting the minutes. 905 906 if (digitalRead(bPlus) == LOW) 907 { 908 if (minSet == 59) 909 { 910 minSet = 0; 911 } 912 else 913 { 914 minSet = minSet + 1; 915 } 916 } 917 if (digitalRead(bMinus) == LOW) 918 { 919 if (minSet == 0) 920 { 921 minSet = 59; 922 } 923 else 924 { 925 minSet = minSet - 1; 926 } 927 } 928 929 matrix.clear(); 930 matrix.setCursor(1, 0); 931 matrix.print(F("Min:")); 932 matrix.show(); 933 934 matrix.print(minSet); 935 matrix.show(); 936 937 delay(buttonDelay); 938 939} // Close function. 940 941void displaySetYear() { 942 943 // setting the year. 944 945 if (digitalRead(bPlus) == LOW) 946 { 947 yearSet = yearSet + 1; 948 } 949 if (digitalRead(bMinus) == LOW) 950 { 951 yearSet = yearSet - 1; 952 } 953 954 matrix.clear(); 955 matrix.setCursor(1, 0); 956 matrix.print(F("Yr :")); 957 matrix.show(); 958 959 int yearSet2 = yearSet; // 960 961 matrix.print(yearSet2 % 100); 962 matrix.show(); 963 964 delay(buttonDelay); 965 966} // Close function. 967 968void displaySetMonth() { 969 970 // Setting the month. 971 972 if (digitalRead(bPlus) == LOW) 973 { 974 if (monthSet == 12) 975 { 976 monthSet = 1; 977 } 978 else 979 { 980 monthSet = monthSet + 1; 981 } 982 } 983 if (digitalRead(bMinus) == LOW) 984 { 985 if (monthSet == 1) 986 { 987 monthSet = 12; 988 } 989 else 990 { 991 monthSet = monthSet - 1; 992 } 993 } 994 995 matrix.clear(); 996 matrix.setCursor(1, 0); 997 matrix.print(F("Mth:")); 998 matrix.show(); 999 1000 matrix.print(monthSet); 1001 matrix.show(); 1002 1003 delay(buttonDelay); 1004 1005} // Close function. 1006 1007void displaySetDay() { 1008 1009 // Configure quantity of days per month. 1010 1011 byte qtyDays; 1012 1013 if (monthSet == 1 || monthSet == 3 || monthSet == 5 || monthSet == 7 || monthSet == 8 || monthSet == 10 || monthSet == 12) { 1014 1015 qtyDays = 31; 1016 } 1017 1018 else if (monthSet == 4 || monthSet == 6 || monthSet == 9 || monthSet == 11) { 1019 1020 qtyDays = 30; 1021 } 1022 1023 else if (monthSet == 2) { 1024 1025 qtyDays = 28; 1026 } 1027 1028 // Setting the day. 1029 1030 if (digitalRead(bPlus) == LOW) 1031 { 1032 if (daySet == qtyDays) 1033 { 1034 daySet = 1; 1035 } 1036 else 1037 { 1038 daySet = daySet + 1; 1039 } 1040 } 1041 if (digitalRead(bMinus) == LOW) 1042 { 1043 if (daySet == 1) 1044 { 1045 daySet = qtyDays; 1046 } 1047 else 1048 { 1049 daySet = daySet - 1; 1050 } 1051 } 1052 1053 matrix.clear(); 1054 matrix.setCursor(1, 0); 1055 matrix.print(F("Day:")); 1056 matrix.show(); 1057 1058 matrix.print(daySet); 1059 matrix.show(); 1060 1061 delay(buttonDelay); 1062 1063} // Close function. 1064 1065void displaySetDoW() { 1066 1067 // Setting the DoW. 1068 1069 if (digitalRead(bPlus) == LOW) 1070 { 1071 if (dowSet == 7) 1072 { 1073 dowSet = 1; 1074 } 1075 else 1076 { 1077 dowSet = dowSet + 1; 1078 } 1079 } 1080 if (digitalRead(bMinus) == LOW) 1081 { 1082 if (dowSet == 1) 1083 { 1084 dowSet = 7; 1085 } 1086 else 1087 { 1088 dowSet = dowSet - 1; 1089 } 1090 } 1091 1092 matrix.clear(); 1093 matrix.setCursor(1, 0); 1094 matrix.print(F("DoW:")); 1095 matrix.show(); 1096 1097 matrix.print(dayShortArray[dowSet]); 1098 matrix.show(); 1099 1100 delay(buttonDelay); 1101 1102} // Close function. 1103 1104void displaySpeedSet() { 1105 1106 // Setting the display speed. 1107 1108 if (digitalRead(bPlus) == LOW) 1109 { 1110 if (tempSpeedSet == 60) 1111 { 1112 tempSpeedSet = 1; 1113 } 1114 else 1115 { 1116 tempSpeedSet = tempSpeedSet + 1; 1117 } 1118 1119 eeSpeedChange = true; 1120 } 1121 1122 if (digitalRead(bMinus) == LOW) 1123 { 1124 if (tempSpeedSet == 1) 1125 { 1126 tempSpeedSet = 60; 1127 } 1128 else 1129 { 1130 tempSpeedSet = tempSpeedSet - 1; 1131 } 1132 1133 eeSpeedChange = true; 1134 } 1135 1136 matrix.clear(); 1137 matrix.setCursor(1, 0); 1138 matrix.print(F("Spd:")); 1139 matrix.show(); 1140 1141 matrix.print(tempSpeedSet); 1142 matrix.show(); 1143 1144 speedSet = 61 - tempSpeedSet; 1145 1146 if (eeSpeedChange == true) 1147 { 1148 eeSpeedSetting = tempSpeedSet; 1149 EEPROM.update(eeSpeedAddress, eeSpeedSetting); // Record speed setting into EEPROM. 1150 eeSpeedChange = false; 1151 } 1152 1153 delay(buttonDelay); 1154 1155} // Close function. 1156 1157void displayColorSet() { 1158 1159 // Setting the display speed. 1160 1161 if (digitalRead(bPlus) == LOW) 1162 { 1163 if (colorSet == 6) 1164 { 1165 colorSet = 0; 1166 } 1167 else 1168 { 1169 colorSet = colorSet + 1; 1170 } 1171 1172 eeColChange = true; 1173 } 1174 if (digitalRead(bMinus) == LOW) 1175 { 1176 if (colorSet == 0) 1177 { 1178 colorSet = 6; 1179 } 1180 else 1181 { 1182 colorSet = colorSet - 1; 1183 } 1184 1185 eeColChange = true; 1186 } 1187 1188 matrix.clear(); 1189 matrix.setCursor(1, 0); 1190 matrix.setTextColor(colors[colorSet]); 1191 matrix.print(colorArray[colorSet]); 1192 matrix.show(); 1193 1194 if (eeColChange == true) 1195 { 1196 eeColSetting = colorSet; 1197 EEPROM.update(eeColAddress, eeColSetting); // Record brightness setting into EEPROM. 1198 eeColChange = false; 1199 } 1200 delay(buttonDelay); 1201 1202} // Close function. 1203 1204void displayBrightness() { 1205 1206 // Setting the display brightness. 1207 1208 if (digitalRead(bPlus) == LOW) 1209 { 1210 if (brightnessSet == 95) 1211 { 1212 brightnessSet = 1; 1213 } 1214 else 1215 { 1216 brightnessSet = brightnessSet + 1; 1217 } 1218 1219 eeBrightChange = true; 1220 } 1221 if (digitalRead(bMinus) == LOW) 1222 { 1223 if (brightnessSet == 1) 1224 { 1225 brightnessSet = 95; 1226 } 1227 else 1228 { 1229 brightnessSet = brightnessSet - 1; 1230 } 1231 1232 eeBrightChange = true; 1233 } 1234 1235 matrix.clear(); 1236 matrix.setCursor(1, 0); 1237 matrix.setBrightness(brightnessSet); 1238 matrix.print(F("Brg:")); 1239 matrix.show(); 1240 1241 matrix.print(brightnessSet); 1242 matrix.show(); 1243 1244 if (eeBrightChange == true) 1245 { 1246 eeBrightSetting = brightnessSet; 1247 EEPROM.update(eeBrightAddress, eeBrightSetting); // Record brightness setting into EEPROM. 1248 eeBrightChange = false; 1249 } 1250 1251 1252 delay(buttonDelay); 1253 1254} // Close function. 1255 1256void amPm() { 1257 1258 // Setting either 12 or 24 hour clock display. 1259 1260 if (digitalRead(bPlus) == LOW) 1261 { 1262 if (set1224 == false) 1263 { 1264 set1224 = true; 1265 } 1266 else 1267 { 1268 set1224 = false; 1269 } 1270 1271 ee1224Change = true; 1272 } 1273 if (digitalRead(bMinus) == LOW) 1274 { 1275 if (set1224 == true) 1276 { 1277 set1224 = false; 1278 } 1279 else 1280 { 1281 set1224 = true; 1282 } 1283 1284 ee1224Change = true; 1285 } 1286 1287 matrix.clear(); 1288 matrix.setCursor(1, 0); 1289 matrix.setBrightness(brightnessSet); 1290 matrix.print(F("12H: ")); 1291 matrix.show(); 1292 1293 char yesNo[2][2] = { "N", "Y" }; 1294 1295 if (set1224 == false) { 1296 1297 matrix.print(yesNo[0]); 1298 matrix.show(); 1299 } 1300 1301 else { 1302 1303 matrix.print(yesNo[1]); 1304 matrix.show(); 1305 1306 } 1307 1308 // Commit to EEPROM. 1309 1310 if (set1224 == false) { 1311 1312 ee1224Setting = 0; 1313 } 1314 1315 else if (set1224 == true) { 1316 1317 ee1224Setting = 1; 1318 } 1319 1320 if (ee1224Change == true) 1321 { 1322 EEPROM.update(ee1224Address, ee1224Setting); // Record the 12 / 24 hour clock setting into EEPROM. 1323 ee1224Change = false; 1324 } 1325 1326 delay(buttonDelay); 1327 1328} // Close function. 1329 1330void resetWelcomeMessage() { 1331 1332 // Reset the welcome message on start up. 1333 1334 if (digitalRead(bPlus) == LOW) 1335 { 1336 if (resetWelcome == false) 1337 { 1338 resetWelcome = true; 1339 } 1340 else 1341 { 1342 resetWelcome = false; 1343 } 1344 1345 eeWelcomeChange = true; 1346 } 1347 if (digitalRead(bMinus) == LOW) 1348 { 1349 if (resetWelcome == true) 1350 { 1351 resetWelcome = false; 1352 } 1353 else 1354 { 1355 resetWelcome = true; 1356 } 1357 1358 eeWelcomeChange = true; 1359 } 1360 1361 matrix.clear(); 1362 matrix.setCursor(1, 0); 1363 matrix.setBrightness(brightnessSet); 1364 matrix.print(F("Wel: ")); 1365 matrix.show(); 1366 1367 char yesNo[2][2] = { "N", "Y" }; 1368 1369 if (resetWelcome == false) { 1370 1371 matrix.print(yesNo[0]); 1372 matrix.show(); 1373 } 1374 1375 else { 1376 1377 matrix.print(yesNo[1]); 1378 matrix.show(); 1379 1380 } 1381 1382 // Commit to EEPROM. 1383 1384 if (resetWelcome == false) { 1385 1386 eeWelcomeSetting = 0; 1387 } 1388 1389 else if (resetWelcome == true) { 1390 1391 eeWelcomeSetting = 1; 1392 } 1393 1394 if (eeWelcomeChange == true) 1395 { 1396 EEPROM.update(eeWelcomeAddress, eeWelcomeSetting); // Record the welcome message flag into EEPROM. 1397 eeWelcomeChange = false; 1398 } 1399 1400 delay(buttonDelay); 1401 1402} 1403 1404void resetClock() { 1405 1406 // Reset the RTC if EEPROM corrupts. 1407 1408 if (digitalRead(bPlus) == LOW) 1409 { 1410 if (resetRTC == false) 1411 { 1412 resetRTC = true; 1413 } 1414 else 1415 { 1416 resetRTC = false; 1417 } 1418 1419 eeRTCResetChange = true; 1420 } 1421 if (digitalRead(bMinus) == LOW) 1422 { 1423 if (resetRTC == true) 1424 { 1425 resetRTC = false; 1426 } 1427 else 1428 { 1429 resetRTC = true; 1430 } 1431 1432 eeRTCResetChange = true; 1433 } 1434 1435 matrix.clear(); 1436 matrix.setCursor(1, 0); 1437 matrix.setBrightness(brightnessSet); 1438 matrix.print(F("Rst: ")); 1439 matrix.show(); 1440 1441 char yesNo[2][2] = { "N", "Y" }; 1442 1443 if (resetRTC == false) { 1444 1445 matrix.print(yesNo[0]); 1446 matrix.show(); 1447 } 1448 1449 else { 1450 1451 matrix.print(yesNo[1]); 1452 matrix.show(); 1453 1454 } 1455 1456 // Commit to EEPROM. 1457 1458 if (resetRTC == false) { 1459 1460 eeRTCResetSetting = 0; 1461 } 1462 1463 else if (resetRTC == true) { 1464 1465 eeRTCResetSetting = 1; 1466 } 1467 1468 if (eeRTCResetChange == true) 1469 { 1470 EEPROM.update(eeRTCResetAddress, eeRTCResetSetting); // Record the 12 / 24 hour clock setting into EEPROM. 1471 eeRTCResetChange = false; 1472 } 1473 1474 delay(buttonDelay); 1475 1476} 1477 1478void saveTimeAndDate() { 1479 1480 // Set date / time. 1481 1482 //rtc.adjust(DateTime(yearSet, monthSet, daySet, hourSet, minSet, 0)); // Send updated variables to RTC module. 1483 1484 rtc.setYear(yearSet); 1485 rtc.setMonth(monthSet); 1486 rtc.setDate(daySet); 1487 rtc.setDoW(dowSet); 1488 rtc.setHour(hourSet); 1489 rtc.setMinute(minSet); 1490 //rtc.setSecond(Second); 1491 1492 // Variable saving. 1493 1494 matrix.clear(); 1495 matrix.setCursor(5, 0); 1496 matrix.print(F("Saved")); 1497 matrix.show(); 1498 delay(2000); 1499 1500 menu = 0; // Reset menu option once saved. 1501 1502 //DateTime now = rtc.now(); 1503 1504 rtcArray[6] = rtc.getYear(); 1505 rtcArray[5] = rtc.getMonth(Century); 1506 rtcArray[4] = rtc.getDate(); 1507 rtcArray[3] = rtc.getDoW(); 1508 rtcArray[2] = rtc.getHour(h12, PM); 1509 rtcArray[1] = rtc.getMinute(); 1510 rtcArray[0] = rtc.getSecond(); 1511 1512 char* dayOfTheWeek = (dayArray[rtcArray[3]]); // returns actual day of the week. 1513 char* monthOfTheYear = (monthArray[rtcArray[5]]); // returns actual month of the year. 1514 1515 sprintf_P(DateAndTimeString, PSTR("%02d:%02d on %s %02d %s %02d"), rtcArray[2], rtcArray[1], dayOfTheWeek, rtcArray[4], monthOfTheYear, rtcArray[6]); 1516 Serial.print("Time and Date have been set to: "); 1517 Serial.println(DateAndTimeString); 1518 1519} // Close function. 1520 1521void alarmOneSchedule() { 1522 1523 // Get Alarm One current settings 1524 1525 displayCurrentAlarmOne(); 1526 1527 // Alarm scheudle - off, once, daily, workday, weekend 1528 1529 if (digitalRead(bPlus) == LOW) 1530 { 1531 if (alarmOneSch == 4) 1532 { 1533 alarmOneSch = 0; 1534 } 1535 else 1536 { 1537 alarmOneSch = alarmOneSch + 1; // Increment by 1. 1538 } 1539 1540 eeAlarmOneSchChange = true; 1541 } 1542 if (digitalRead(bMinus) == LOW) 1543 { 1544 if (alarmOneSch == 0) 1545 { 1546 alarmOneSch = 4; 1547 } 1548 else 1549 { 1550 alarmOneSch = alarmOneSch - 1; // Decrement by 1. 1551 } 1552 1553 eeAlarmOneSchChange = true; 1554 } 1555 1556 matrix.clear(); 1557 matrix.setCursor(6, 0); 1558 matrix.print(alarmSchArray[alarmOneSch]); 1559 matrix.show(); 1560 1561 if (eeAlarmOneSchChange == true) 1562 { 1563 eeAlarmOneSchSetting = alarmOneSch; 1564 EEPROM.update(eeAlarmOneSchAddress, eeAlarmOneSchSetting); // Record alarm one schedule setting into EEPROM. 1565 eeAlarmOneSchChange = false; 1566 } 1567 delay(buttonDelay); 1568 1569} 1570 1571void alarmOneSetHour() { 1572 1573 // Check schedule. 1574 1575 if (alarmOneSch != 0) { 1576 1577 // Alarm one set hour. 1578 1579 if (digitalRead(bPlus) == LOW) 1580 { 1581 if (alarmOneHourSet == 23) // 24 hour clock. 1582 { 1583 alarmOneHourSet = 0; 1584 } 1585 else 1586 { 1587 alarmOneHourSet = alarmOneHourSet + 1; // Increment by 1. 1588 } 1589 } 1590 if (digitalRead(bMinus) == LOW) 1591 { 1592 if (alarmOneHourSet == 0) 1593 { 1594 alarmOneHourSet = 23; 1595 } 1596 else 1597 { 1598 alarmOneHourSet = alarmOneHourSet - 1; // Decrement by 1. 1599 } 1600 } 1601 1602 char alarmOneHourSetString[4]; 1603 char alarmOneMinSetString[4]; 1604 1605 sprintf_P(alarmOneHourSetString, PSTR("%02d"), alarmOneHourSet); 1606 sprintf_P(alarmOneMinSetString, PSTR("%02d"), alarmOneMinSet); 1607 1608 matrix.clear(); 1609 matrix.setCursor(6, 0); 1610 1611 if (colorSet != 1) { 1612 1613 matrix.setTextColor(colors[1]); 1614 1615 } 1616 1617 else { 1618 1619 matrix.setTextColor(colors[6]); 1620 } 1621 1622 matrix.print(alarmOneHourSetString); 1623 matrix.setTextColor(colors[colorSet]); 1624 matrix.print(F(":")); 1625 matrix.print(alarmOneMinSetString); 1626 matrix.show(); 1627 1628 } 1629 1630 else alarmOneSave(); 1631 1632 delay(buttonDelay); 1633 1634} // Close function. 1635 1636void alarmOneSetMinute() { 1637 1638 // Alarm one set minute. 1639 1640 if (digitalRead(bPlus) == LOW) 1641 { 1642 if (alarmOneMinSet == 59) 1643 { 1644 alarmOneMinSet = 0; 1645 } 1646 else 1647 { 1648 alarmOneMinSet = alarmOneMinSet + 1; // Increment by 1. 1649 } 1650 } 1651 if (digitalRead(bMinus) == LOW) 1652 { 1653 if (alarmOneMinSet == 0) 1654 { 1655 alarmOneMinSet = 59; 1656 } 1657 else 1658 { 1659 alarmOneMinSet = alarmOneMinSet - 1; // Decrement by 1. 1660 } 1661 } 1662 1663 char alarmOneHourSetString[4]; 1664 char alarmOneMinSetString[4]; 1665 1666 sprintf_P(alarmOneHourSetString, PSTR("%02d"), alarmOneHourSet); 1667 sprintf_P(alarmOneMinSetString, PSTR("%02d"), alarmOneMinSet); 1668 1669 matrix.clear(); 1670 matrix.setCursor(6, 0); 1671 matrix.setTextColor(colors[colorSet]); 1672 matrix.print(alarmOneHourSetString); 1673 matrix.print(F(":")); 1674 1675 if (colorSet != 1) { 1676 1677 matrix.setTextColor(colors[1]); 1678 1679 } 1680 1681 else { 1682 1683 matrix.setTextColor(colors[6]); 1684 } 1685 1686 matrix.print(alarmOneMinSetString); 1687 matrix.show(); 1688 1689 delay(buttonDelay); 1690 1691} // Close function. 1692 1693void alarmOneSleepTime() { 1694 1695 digitalWrite(musicPlay, HIGH); 1696 1697 // Alarm one set sleep period. 1698 1699 if (digitalRead(bPlus) == LOW) 1700 { 1701 if (sleepSet == 15) 1702 { 1703 sleepSet = 1; 1704 } 1705 else 1706 { 1707 sleepSet = sleepSet + 1; // Increment by 1. 1708 } 1709 1710 eeSleepSetChange = true; 1711 } 1712 if (digitalRead(bMinus) == LOW) 1713 { 1714 if (sleepSet == 1) 1715 { 1716 sleepSet = 15; 1717 } 1718 else 1719 { 1720 sleepSet = sleepSet - 1; // Decrement by 1. 1721 } 1722 1723 eeSleepSetChange = true; 1724 } 1725 1726 matrix.clear(); 1727 matrix.setCursor(0, 0); 1728 matrix.setTextColor(colors[colorSet]); 1729 matrix.print(F("Slp:")); 1730 matrix.show(); 1731 1732 matrix.print(sleepSet); 1733 matrix.show(); 1734 1735 if (eeSleepSetChange == true) 1736 { 1737 eeSleepSetSetting = sleepSet; 1738 EEPROM.update(eeSleepSetAddress, eeSleepSetSetting); // Record sleep setting into EEPROM. 1739 eeSleepSetChange = false; 1740 } 1741 delay(buttonDelay); 1742 1743} 1744 1745void alarmOneMusicSet() { 1746 1747 // Alarm one choose music option. 1748 1749 if (digitalRead(bPlus) == LOW) 1750 { 1751 if (musicSet == 2) 1752 { 1753 musicSet = 0; 1754 musicScroll = true; 1755 } 1756 else 1757 { 1758 musicSet = musicSet + 1; // Increment by 1. 1759 musicScroll = true; 1760 } 1761 1762 eeMusicChange = true; 1763 } 1764 if (digitalRead(bMinus) == LOW) 1765 { 1766 if (musicSet == 0) 1767 { 1768 musicSet = 2; 1769 musicScroll = true; 1770 1771 } 1772 else 1773 { 1774 musicSet = musicSet - 1; // Decrement by 1. 1775 musicScroll = true; 1776 } 1777 1778 eeMusicChange = true; 1779 } 1780 1781 if (musicScroll == true) { 1782 1783 matrix.clear(); 1784 matrix.setCursor(0, 0); 1785 matrix.show(); 1786 1787 String msgText = (musicArray[musicSet]); 1788 1789 Serial.print("Message Text From Table: "); 1790 Serial.println(msgText); 1791 1792 int textLenght = msgText.length(); 1793 int msgSize = (textLenght * pixelPerChar); // Calculate message length. 1794 int scrollingMax = (msgSize); // Adjust displacement for message length. 1795 1796 if (!debug == true) { 1797 1798 // Print variables for debugging messages lenghts 1799 1800 Serial.print("Matrix Width = "); 1801 Serial.println(x); 1802 Serial.print(" Text Lenght = "); 1803 Serial.print(textLenght); 1804 Serial.print(" Message Size = "); 1805 Serial.print(msgSize); 1806 Serial.print(" Scrolling Max = "); 1807 Serial.println(scrollingMax); 1808 1809 } // Close if. 1810 1811 while (x > -scrollingMax) { // Only display text for one pass 1812 1813 matrix.fillScreen(0); 1814 matrix.setCursor(x, 0); 1815 matrix.setTextColor(colors[colorSet]); 1816 matrix.print(msgText); 1817 1818 if (--x < -scrollingMax) 1819 { 1820 x = matrix.width(); 1821 } 1822 matrix.show(); 1823 delay(speedSet); 1824 1825 } // Close while. 1826 1827 x = matrix.width(); 1828 1829 } // Close if. 1830 1831 musicScroll = false; 1832 1833 matrix.clear(); 1834 matrix.setCursor(0, 0); 1835 matrix.show(); 1836 1837 if (musicSet == 0) { 1838 1839 matrix.setCursor(9, 0); 1840 matrix.setTextColor(colors[colorSet]); 1841 matrix.print("GSTQ"); 1842 matrix.show(); 1843 1844 } 1845 1846 else if (musicSet == 1) { 1847 1848 matrix.setCursor(11, 0); 1849 matrix.setTextColor(colors[colorSet]); 1850 matrix.print("SSB"); 1851 matrix.show(); 1852 1853 } 1854 1855 else if (musicSet == 2) { 1856 1857 matrix.setCursor(0, 0); 1858 matrix.setTextColor(colors[colorSet]); 1859 matrix.print("Muppets"); 1860 matrix.show(); 1861 1862 } 1863 1864 if (musicSet == 0) { 1865 1866 musicPlay = GSTQ; 1867 digitalWrite(GSTQ, LOW); 1868 digitalWrite(SSB, HIGH); 1869 digitalWrite(Mahnamahna, HIGH); 1870 } 1871 1872 else if (musicSet == 1) { 1873 1874 musicPlay = SSB; 1875 digitalWrite(GSTQ, HIGH); 1876 digitalWrite(SSB, LOW); 1877 digitalWrite(Mahnamahna, HIGH); 1878 1879 } 1880 1881 else if (musicSet == 2) { 1882 1883 musicPlay = Mahnamahna; 1884 digitalWrite(GSTQ, HIGH); 1885 digitalWrite(SSB, HIGH); 1886 digitalWrite(Mahnamahna, LOW); 1887 1888 } 1889 1890 if (eeMusicChange == true) 1891 { 1892 eeMusicSetting = musicSet; 1893 EEPROM.update(eeMusicAddress, eeMusicSetting); // Record music setting into EEPROM. 1894 eeAlarmOneSchChange = false; 1895 } 1896 delay(buttonDelay); 1897 1898} 1899 1900void alarmOneVolume() { 1901 1902 // Alarm one volume. 1903 1904 if (digitalRead(bPlus) == LOW) 1905 { 1906 volumeSet = volumeSet + 1; // Increment by 1. 1907 digitalWrite(vPlus, LOW); 1908 delay(100); 1909 digitalWrite(vPlus, HIGH); 1910 1911 } 1912 if (digitalRead(bMinus) == LOW) 1913 { 1914 volumeSet = volumeSet - 1; // Decrement by 1. 1915 digitalWrite(vMinus, LOW); 1916 delay(100); 1917 digitalWrite(vMinus, HIGH); 1918 1919 } 1920 1921 matrix.clear(); 1922 matrix.setCursor(0, 0); 1923 matrix.setTextColor(colors[colorSet]); 1924 matrix.print(F("Vol:")); 1925 matrix.show(); 1926 1927 if (volumeSet >= 26) // For loop to ensure volume doesnt get out of sync due to earlier menu. 1928 { 1929 byte tempVol = volumeSet - 25; 1930 1931 for (byte i = tempVol; i == 0; i--) { 1932 1933 digitalWrite(vMinus, LOW); 1934 delay(100); 1935 digitalWrite(vMinus, HIGH); 1936 } 1937 1938 volumeSet = 25; 1939 } 1940 1941 if (volumeSet <= 1) 1942 { 1943 volumeSet = 1; 1944 } 1945 1946 matrix.print(volumeSet); 1947 matrix.show(); 1948 1949 delay(buttonDelay); 1950 1951} 1952 1953void alarmOneSave() { 1954 1955 // Alarm one save and display. 1956 1957 if (alarmOneSch == 0) { // Alarm one off. 1958 1959 rtc.turnOffAlarm(1); 1960 digitalWrite(SSB, HIGH); 1961 digitalWrite(GSTQ, HIGH); 1962 digitalWrite(Mahnamahna, HIGH); 1963 1964 if (rtc.checkAlarmEnabled(1) == false) { 1965 1966 Serial.print("Alarm is disabled"); 1967 1968 } 1969 1970 else Serial.print("Alarm is enabled"); 1971 } 1972 1973 1974 else if (alarmOneSch == 1) { // Alarm one once. 1975 1976 rtc.setA1Time(1, alarmOneHourSet, alarmOneMinSet, 0, ALRM1_MATCH_HR_MIN_SEC, false, false, false); 1977 rtc.turnOnAlarm(1); 1978 rtc.checkAlarmEnabled(1); 1979 1980 if (rtc.checkAlarmEnabled(1) == false) { 1981 1982 Serial.print("Alarm is disabled"); 1983 1984 } 1985 1986 else Serial.print("Alarm is enabled"); 1987 } 1988 1989 else if (alarmOneSch == 2 || alarmOneSch == 3 || alarmOneSch == 4 || alarmOneSch == 5) { // Other alarm one schedules. 1990 1991 rtc.setA1Time(1, alarmOneHourSet, alarmOneMinSet, 0, ALRM1_MATCH_HR_MIN_SEC, false, false, false); 1992 rtc.turnOnAlarm(1); 1993 rtc.checkAlarmEnabled(1); 1994 1995 if (rtc.checkAlarmEnabled(1) == false) { 1996 1997 Serial.print("Alarm is disabled"); 1998 1999 } 2000 2001 else Serial.print("Alarm is enabled"); 2002 } 2003 2004 // Variable saving. 2005 2006 matrix.clear(); 2007 matrix.setCursor(5, 0); 2008 matrix.setTextColor(colors[colorSet]); 2009 matrix.print(F("Saved")); 2010 matrix.show(); 2011 delay(2000); 2012 2013 displayCurrentAlarmOne(); 2014 2015 char alarmOneDateAndTimeString[30]; 2016 2017 sprintf_P(alarmOneDateAndTimeString, PSTR("%02d:%02d"), alarmOneHourSet, alarmOneMinSet); 2018 Serial.print("Alarm One Set To: "); 2019 Serial.println(alarmOneDateAndTimeString); 2020 2021 menu = 0; // Reset menu option once saved. 2022 2023} // Close function. 2024 2025void alarmOneTriggered() { 2026 2027 // Alarm one check if triggered - // 0 = off / 1 = once / 2 = daily / 3 = weekday / 4 = weekend 2028 2029 // DoW: 1 = Sunday / 2 = Monday / 3 = Tuesday / 4 = Wednesday / 5 = Thursday / 6 = Friday / 7 = Saturday 2030 2031 if (rtc.checkIfAlarm(1)) 2032 2033 if (alarmOneSch == 0) { 2034 2035 if (debug == true) { 2036 2037 Serial.println(); 2038 Serial.print("No Alarm scheduled"); 2039 Serial.println(); 2040 } 2041 2042 } 2043 2044 else if (alarmOneSch == 1) { 2045 2046 if (debug == true) { 2047 2048 Serial.println(); 2049 Serial.print("Alarm schedule 1 Triggered / Once"); 2050 Serial.println(); 2051 } 2052 2053 digitalWrite(musicPlay, LOW); 2054 alarmOneState = true; 2055 2056 } 2057 2058 else if (alarmOneSch == 2) { 2059 2060 if (debug == true) { 2061 2062 Serial.println(); 2063 Serial.print("Alarm schedule 2 Triggered / Daily"); 2064 Serial.println(); 2065 } 2066 2067 digitalWrite(musicPlay, LOW); 2068 alarmOneState = true; 2069 2070 } 2071 2072 else if (alarmOneSch == 3) { 2073 2074 if (dowSet == 2 || dowSet == 3 || dowSet == 4 || dowSet == 5 || dowSet == 6) { 2075 2076 if (debug == true) { 2077 2078 Serial.println(); 2079 Serial.print("Alarm schedule 3 Triggered / Weekday"); 2080 Serial.println(); 2081 } 2082 2083 digitalWrite(musicPlay, LOW); 2084 alarmOneState = true; 2085 2086 } 2087 2088 } 2089 2090 else if (alarmOneSch == 4) { 2091 2092 if (dowSet == 1 || dowSet == 7) { 2093 2094 if (debug == true) { 2095 2096 Serial.println(); 2097 Serial.print("Alarm schedule 4 Triggered / Weekend"); 2098 Serial.println(); 2099 } 2100 2101 digitalWrite(musicPlay, LOW); 2102 alarmOneState = true; 2103 2104 } 2105 2106 } 2107 2108} // Close function. 2109 2110void alarmOneSleepCancel() { 2111 2112 // Alarm one sleep alarm. 2113 2114 if (alarmOneState == true && setSleepStart == true) { 2115 2116 digitalWrite(musicPlay, HIGH); 2117 sleepStart = rtc.getMinute(); 2118 setSleepStart = false; 2119 2120 matrix.clear(); 2121 matrix.setCursor(5, 0); 2122 matrix.setTextColor(colors[colorSet]); 2123 matrix.print(F("Sleep")); 2124 matrix.show(); 2125 delay(1250); 2126 2127 } 2128 2129 menu = 0; 2130 2131 // Get Alarm One current settings 2132 2133 displayCurrentAlarmOne(); 2134 2135} // Close function. 2136 2137void checkSleep() { 2138 2139 // Alarm one check sleep period. 2140 2141 byte currentTime = rtc.getMinute(); 2142 byte wakeTime = sleepStart + sleepSet; 2143 2144 if (wakeTime > 59) { 2145 2146 wakeTime = (wakeTime - 60); 2147 } 2148 2149 if (alarmOneState == true) { 2150 2151 if (currentTime == wakeTime) { 2152 2153 digitalWrite(musicPlay, LOW); 2154 Serial.println(); 2155 Serial.print("Sleep Time Ended"); 2156 Serial.println(); 2157 2158 } 2159 2160 } 2161 2162} // Close function. 2163 2164void displayScrollingDate() { 2165 2166 // This function is also used to cancel alarm one. 2167 2168 digitalWrite(SSB, HIGH); 2169 digitalWrite(GSTQ, HIGH); 2170 digitalWrite(Mahnamahna, HIGH); 2171 alarmOneState = false; 2172 2173 if (alarmOneSch == 0) { // Alarm one off. 2174 2175 rtc.turnOffAlarm(1); 2176 alarmOneSch = 0; 2177 } 2178 2179 else if (alarmOneSch == 1) { // Alarm one once. 2180 2181 rtc.turnOffAlarm(1); 2182 alarmOneSch = 0; 2183 eeAlarmOneSchChange = true; 2184 2185 if (eeAlarmOneSchChange == true) // Record change into EEPROM. 2186 { 2187 eeAlarmOneSchSetting = alarmOneSch; 2188 EEPROM.update(eeAlarmOneSchAddress, eeAlarmOneSchSetting); // Record alarm one schedule setting into EEPROM. 2189 eeAlarmOneSchChange = false; 2190 } 2191 2192 } 2193 2194 else if (alarmOneSch == 2 || alarmOneSch == 3 || alarmOneSch == 4) { // Alarm one daily, weekday or weekend 2195 2196 rtc.turnOnAlarm(1); 2197 rtc.checkAlarmEnabled(1); 2198 2199 } 2200 2201 // Get alarm one date and time. 2202 2203 displayCurrentAlarmOne(); 2204 2205 // Display date. 2206 2207 char* dayOfTheWeek = (dayArray[rtcArray[3]]); // returns actual day of the week. 2208 char* monthOfTheYear = (monthArray[rtcArray[5]]); // returns actual month of the year. 2209 2210 sprintf_P(DisplayDateString, PSTR("%s %02d %s %02d"), dayOfTheWeek, rtcArray[4], monthOfTheYear, rtcArray[6]); 2211 2212 if (!debug == true) { 2213 2214 // Print date, comment out before release, debugging only. 2215 2216 Serial.print("Today's Date is: "); 2217 Serial.println(DisplayDateString); 2218 2219 } // Close if. 2220 2221 String msgText = DisplayDateString; 2222 2223 int textLenght = msgText.length(); 2224 int msgSize = (textLenght * pixelPerChar) + (2 * pixelPerChar); // Calculate message length. 2225 int scrollingMax = (msgSize)+matrix.width() + matrix.width(); // Adjust displacement for message length. 2226 2227 if (!debug == true) { 2228 2229 // Print variables for debugging messages lenghts 2230 2231 Serial.print("Matrix Width = "); 2232 Serial.println(x); 2233 Serial.print(" Text Lenght = "); 2234 Serial.print(textLenght); 2235 Serial.print(" Message Size = "); 2236 Serial.print(msgSize); 2237 Serial.print(" Scrolling Max = "); 2238 Serial.println(scrollingMax); 2239 2240 } // Close if. 2241 2242 while (x > -scrollingMax) { // Only display text for one pass 2243 2244 matrix.fillScreen(0); 2245 matrix.setCursor(x, 0); 2246 matrix.setTextColor(colors[colorSet]); 2247 matrix.print(F("Today's Date : ")); 2248 matrix.print(DisplayDateString); 2249 2250 if (--x < -scrollingMax) 2251 { 2252 x = matrix.width(); 2253 } 2254 matrix.show(); 2255 delay(speedSet); 2256 2257 } // Close while. 2258 2259 // Reset width and menu flag. 2260 2261 x = matrix.width(); 2262 delay(500); 2263 menu = 0; 2264 2265} // Close function. 2266 2267void displayRandomWhite() { 2268 2269 // Display random messages. 2270 2271 randNumber = random(30); 2272 2273 Serial.print("Random Number: "); 2274 Serial.println(randNumber); 2275 2276 strcpy_P(buffer, (char*)pgm_read_word(&(string_table[randNumber]))); 2277 2278 String msgText = buffer; 2279 2280 Serial.print("Message Text From Table: "); 2281 Serial.println(msgText); 2282 2283 int textLenght = msgText.length(); 2284 int msgSize = (textLenght * pixelPerChar); // Calculate message length. 2285 int scrollingMax = (msgSize); // Adjust displacement for message length. 2286 2287 if (!debug == true) { 2288 2289 // Print variables for debugging messages lenghts 2290 2291 Serial.print("Matrix Width = "); 2292 Serial.println(x); 2293 Serial.print(" Text Lenght = "); 2294 Serial.print(textLenght); 2295 Serial.print(" Message Size = "); 2296 Serial.print(msgSize); 2297 Serial.print(" Scrolling Max = "); 2298 Serial.println(scrollingMax); 2299 2300 } // Close if. 2301 2302 while (x > -scrollingMax) { // Only display text for one pass 2303 2304 matrix.fillScreen(0); 2305 matrix.setCursor(x, 0); 2306 matrix.setTextColor(colors[colorSet]); 2307 matrix.print(msgText); 2308 2309 if (--x < -scrollingMax) 2310 { 2311 x = matrix.width(); 2312 } 2313 matrix.show(); 2314 delay(speedSet); 2315 2316 } // Close while. 2317 2318 // Reset width and menu flag. 2319 2320 x = matrix.width(); 2321 delay(500); 2322 menu = 0; 2323 2324} // Close function. 2325 2326void displayWelcomeMessage() { 2327 2328 // Display welcome message. Edit depending on who it is going to. 2329 2330 String msgText = " Insert message here..."; 2331 2332 Serial.print("Welcome Message Text: "); 2333 Serial.println(msgText); 2334 2335 int textLenght = msgText.length(); 2336 int msgSize = (textLenght * pixelPerChar); // Calculate message length. 2337 int scrollingMax = (msgSize); // Adjust displacement for message length. 2338 2339 if (!debug == true) { 2340 2341 // Print variables for debugging messages lenghts 2342 2343 Serial.print("Matrix Width = "); 2344 Serial.println(x); 2345 Serial.print(" Text Lenght = "); 2346 Serial.print(textLenght); 2347 Serial.print(" Message Size = "); 2348 Serial.print(msgSize); 2349 Serial.print(" Scrolling Max = "); 2350 Serial.println(scrollingMax); 2351 2352 } // Close if. 2353 2354 while (digitalRead(intPinAlarmOneSleep) == HIGH) { // Press sleep button to continue message. 2355 2356 while (x > -378) { // Only display text for one pass. 2357 2358 matrix.fillScreen(0); 2359 matrix.setCursor(x, 0); 2360 matrix.setTextColor(colors[colorSet]); 2361 matrix.print("Hold down the sleep button until music plays to continue... "); 2362 2363 if (--x < -378) 2364 { 2365 x = matrix.width(); 2366 } 2367 matrix.show(); 2368 delay(speedSet); 2369 2370 } // Close while. 2371 2372 x = matrix.width(); // Reset cursor position for next message. 2373 2374 } // Close while. 2375 2376 // Play the Muppets for a laugh... 2377 2378 digitalWrite(Mahnamahna, LOW); 2379 2380 while (x > -scrollingMax) { // Only display text for one pass. 2381 2382 matrix.fillScreen(0); 2383 matrix.setCursor(x, 0); 2384 matrix.setTextColor(colors[colorSet]); 2385 matrix.print(msgText); 2386 2387 if (--x < -scrollingMax) 2388 { 2389 x = matrix.width(); 2390 } 2391 matrix.show(); 2392 delay(16); 2393 2394 } // Close while. 2395 2396 // Reset width and menu flag. 2397 2398 x = matrix.width(); 2399 delay(500); 2400 menu = 0; 2401 eeWelcomeSetting = false; 2402 resetWelcome = false; 2403 EEPROM.update(eeWelcomeAddress, eeWelcomeSetting); // Record the welcome message flag into EEPROM. 2404 digitalWrite(Mahnamahna, HIGH); 2405 2406} // Close function. 2407 2408void recvBTWithStartAndEndMarker() { 2409 2410 // Save received BlueTooth data into array. 2411 2412 static boolean recvInProgress = false; 2413 byte ndx = 0; 2414 char startMarker = '('; 2415 char endMarker = ')'; 2416 char rc; 2417 receivedNumChar = 0; 2418 2419 while (s1Serial.available() > 0 && newData == false) { 2420 rc = s1Serial.read(); 2421 2422 if (recvInProgress == true) { 2423 if (rc != endMarker) { 2424 receivedChars[ndx] = rc; 2425 ndx++; 2426 receivedNumChar++; 2427 if (ndx >= numChars) { 2428 ndx = numChars - 1; 2429 } 2430 } 2431 else { 2432 receivedChars[ndx] = '\\0'; // terminate the string 2433 recvInProgress = false; 2434 ndx = 0; 2435 newData = true; 2436 } 2437 } 2438 2439 else if (rc == startMarker) { 2440 recvInProgress = true; 2441 } 2442 2443 } // Close while. 2444 2445} // Close function. 2446 2447void showNewBTData() { 2448 2449 // Call BlueTooth array data to be displayed. 2450 2451 if (newData == true) { 2452 2453 if (!debug == true) { 2454 2455 Serial.print("This just in ... "); 2456 Serial.println(); 2457 Serial.println(); 2458 Serial.println(receivedChars); 2459 Serial.println(); 2460 2461 } // Close if. 2462 2463 displayBlueToothText(); 2464 2465 newData = false; 2466 } 2467 2468} // Close function. 2469 2470void displayBlueToothText() { 2471 2472 // Display BlueTooth array data. 2473 2474 if (!debug == true) { 2475 2476 Serial.print("Whats in the Received Charaters Buffer? "); 2477 Serial.println(); 2478 Serial.println(); 2479 Serial.println(receivedChars); 2480 Serial.println(); 2481 2482 Serial.print("How many received charaters? "); 2483 Serial.println(receivedNumChar); 2484 Serial.println(); 2485 2486 } // Close if. 2487 2488 int msgSize = (receivedNumChar * pixelPerChar); // Calculate message length. 2489 int scrollingMax = (msgSize); // Adjust displacement for message length. 2490 2491 if (!debug == true) { 2492 2493 Serial.print("What size is scrolling max? "); 2494 Serial.println(scrollingMax); 2495 Serial.println(); 2496 2497 } // Close if. 2498 2499 while (x > -scrollingMax) { // Only display text for one pass 2500 2501 matrix.fillScreen(0); 2502 matrix.setCursor(x, 0); 2503 matrix.setTextColor(colors[colorSet]); 2504 matrix.print(receivedChars); 2505 2506 if (--x < -scrollingMax) 2507 { 2508 x = matrix.width(); 2509 } 2510 matrix.show(); 2511 delay(speedSet); 2512 2513 } // Close while. 2514 2515 // Clear the software serial buffer. 2516 2517 while (s1Serial.available() > 0) { 2518 s1Serial.read(); 2519 2520 if (!debug == true) { 2521 2522 Serial.println(); 2523 Serial.println("Clearing software serial buffer..."); 2524 2525 } // Close if. 2526 2527 } // Close while 2528 2529 // Clear the character array. 2530 2531 for (byte i = 0; i <= numChars; i++) { 2532 receivedChars[i] = 0; 2533 2534 if (!debug == true) { 2535 Serial.println(); 2536 Serial.println("Clearing character array..."); 2537 2538 } // Close if. 2539 2540 } // Close for. 2541 2542 Serial.println(); 2543 Serial.println("Ready."); 2544 Serial.println(); 2545 2546 // Reset width, menu, received # characters and new data flags. 2547 2548 x = matrix.width(); 2549 2550 receivedNumChar = 0; 2551 menu = 0; 2552 2553} // Close function. 2554 2555void displayCurrentAlarmOne() { 2556 2557 rtc.getA1Time(alarmOneDowSet, alarmOneHourSet, alarmOneMinSet, alarmOneSecSet, alarmBits, alarmDy, alarmH12, alarmPm); 2558 2559 if (debug == true) { 2560 2561 Serial.println(); 2562 2563 if (alarmDy) { 2564 Serial.print("DoW: "); 2565 } 2566 else { 2567 Serial.print("Date: "); 2568 } 2569 Serial.print(alarmOneDowSet, DEC); 2570 2571 Serial.print(" "); 2572 Serial.print("Alarm One Set To: "); 2573 Serial.print(alarmOneHourSet, DEC); 2574 Serial.print(':'); 2575 Serial.print(alarmOneMinSet, DEC); 2576 Serial.print(':'); 2577 Serial.print(alarmOneSecSet, DEC); 2578 Serial.print(' '); 2579 2580 /* if (alarmH12) { 2581 if (alarmPm) { 2582 Serial.print("pm "); 2583 } 2584 else { 2585 Serial.print("am "); 2586 } 2587 } 2588 */ 2589 2590 if (rtc.checkAlarmEnabled(1)) { 2591 Serial.print("Alarm is enabled"); 2592 } 2593 2594 else { 2595 Serial.print("Alarm is disabled"); 2596 } 2597 Serial.println(); 2598 } 2599 2600 Serial.println(); 2601 2602} // Close function. 2603 2604void resetAllSettings() { 2605 2606 // Set date / time and Send to RTC module. 2607 2608 rtc.setYear(21); 2609 rtc.setMonth(01); 2610 rtc.setDate(01); 2611 rtc.setDoW(5); 2612 rtc.setHour(0); 2613 rtc.setMinute(0); 2614 rtc.setSecond(0); 2615 2616 rtc.setA1Time(1, 0, 0, 0, ALRM1_MATCH_HR_MIN_SEC, false, false, false); // Set alarm and send to RTC module. 2617 2618 EEPROM.update(ee1224Address, 0); // Record the 12 / 24 hour clock setting into EEPROM. 2619 2620 EEPROM.update(eeBrightAddress, 5); // Record brightness setting into EEPROM. 2621 2622 EEPROM.update(eeColAddress, 6); // Record brightness setting into EEPROM. 2623 2624 EEPROM.update(eeSpeedAddress, 45); // Record speed setting into EEPROM. 2625 2626 EEPROM.update(eeAlarmOneSchAddress, 0); // Record alarm one schedule setting into EEPROM. 2627 2628 EEPROM.update(eeSleepSetAddress, 10); // Record sleep setting into EEPROM. 2629 2630 EEPROM.update(eeMusicAddress, 0); // Record music setting into EEPROM. 2631 2632 EEPROM.update(eeRTCResetAddress, 0); // Record RTC reset setting back into EEPROM. 2633 eeRTCResetChange = false; 2634 resetRTC = false; 2635 2636}
Downloadable files
Printed Circuit Board
This is my bespoke printed circuit board
Printed Circuit Board
Comments
Only logged in users can leave comments
Anonymous user
2 years ago
Christopher with compliment please do you have a drawing where i make your project and another things that i make you wonderfull project thanks joop
Anonymous user
2 years ago
Muito legal, queria comprar um arduíno e fazer um mini projeto desse.
Anonymous user
4 years ago
Buongiorno ottimo progetto scusa se sono un po' fuori tema, sono in possesso di 8 valvole IV-17 a 16 segmenti, è possibile pilotarle con arduino per fare un orologio? ho visto alcuni progetti con RTC DS3231 e registri a scorrimento 74hc595 ma non sono riuscito ad riportare i dati RTC ai display sono riuscito a fare un contatore che puoi vedere qui: https://www.youtube.com/watch?v=KZMISO55mGQ. e qui:https://www.youtube.com/watch?v=Yt3F2omfHKU mi puoi aiutare? Grazie
flaviagravina
4 years ago
Muito legal, queria comprar um arduíno e fazer um mini projeto desse.
Anonymous user
4 years ago
Christopher with compliment please do you have a drawing where i make your project and another things that i make you wonderfull project thanks joop
Anonymous user
4 years ago
hallo, i wonder what you make compliments please can you tel digital alarm clock i canot open the drawing please how can i open joop from the nederlands
Anonymous user
2 years ago
hallo, i wonder what you make compliments please can you tel digital alarm clock i canot open the drawing please how can i open joop from the nederlands