 /*
- * This clock example uses the RTC from a Teensy3 (Teensy 3.0 or 3.1).
+ * This clock example uses the RTC of a Teensy3 (Teensy 3.0 or 3.1).
  *
  * RTC clock is set in response to serial port time message 
  * A Processing example sketch to set the time is included in the download


//#define DEBUG_SERIAL

rgb24 bgCol        = {0x00, 0x00, 0x00};  // background colour

rgb24 timeCol      = {0x2f, 0x2f, 0xff};  // time: segment colour
rgb24 timeColFx    = {0x00, 0x00, 0x1f};  // time: colour of 'non active segment' effect
rgb24 dateCol      = {0x00, 0x00, 0x9f};  // date: segment colour
rgb24 dateColFx    = {0x00, 0x00, 0x15};  // date: colour of 'non active segment' effect

// values for a 96x64 display; need to be adjusted for other resolutions
int timeSegT       = 4;  // time: thickness of a segment (in pixel)
int timeSegW       = 17; // time: length of a single segment (in pixel)
int dateSegT       = 2;  // date: thickness of a segment
int dateSegW       = 7;  // date: length of a single segment

const int showSecs = 2;  // display seconds: 0: no, 1: yes, 2: no seconds, but blinking dots
const int showYear = 0;  // show year: 0 no, 1: yes



SmartMatrix matrix;

const int timeSegH = timeSegW * 2 - timeSegT;
const int dateSegH = dateSegW * 2 - dateSegT;

byte currSec = 60;


void setup() {
  // set the Time library to use Teensy 3.x's RTC to keep time


  // setup matrix
  matrix.begin();

  w = matrix.getScreenWidth();
  h = matrix.getScreenHeight();

  // out-of-bound checks
  if (timeColPerc > 100) timeColPerc = 100;
  if (dateColPerc > 100) dateColPerc = 100;
  if (showSecs > 2) showSecs = 2;
  if (showYear > 1) showYear = 1;

  // calculate passive segment colours
  timeColFx.red   = (uint8_t)((uint16_t)timeCol.red   * timeColPerc / 100);
  timeColFx.green = (uint8_t)((uint16_t)timeCol.green * timeColPerc / 100);
  timeColFx.blue  = (uint8_t)((uint16_t)timeCol.blue  * timeColPerc / 100);
  dateColFx.red   = (uint8_t)((uint16_t)dateCol.red   * dateColPerc / 100);
  dateColFx.green = (uint8_t)((uint16_t)dateCol.green * dateColPerc / 100);
  dateColFx.blue  = (uint8_t)((uint16_t)dateCol.blue  * dateColPerc / 100);


  // calculate width and height of segments
  if (timeMaxH == 0 && timeStartX == 0xFF) { // auto width and auto center
    timeSegW = ( w - ((showSecs == 1) ? 9 : 5) * timeSegT ) / ((showSecs == 1) ? 6 : 4);
  } else {
    timeSegW = (timeMaxH + timeSegT) / 2;    
  }
  timeW    = timeSegW * ((showSecs == 1) ? 6 : 4) + timeSegT * ( (showSecs == 1) ? 9 : 5);                              
  timeSegH = timeSegW * 2 - timeSegT;

  if (dateMaxH == 0 && dateStartX == 0xFF) { // auto width and auto center
    dateSegW = ( w - ((showYear == 1) ? 9 : 4) * dateSegT ) / ((showYear == 1) ? 10 : 5);
  } else {
    dateSegW = (dateMaxH + dateSegT) / 2;
  }

  dateW = dateSegW * ((showYear == 1) ? 10 : 5) + dateSegT * ( (showYear == 1) ? 9 : 4);                              
  dateSegH = dateSegW * 2 - dateSegT;

  // y-offset of 2 colon points
  colonPos = (timeSegH - 2* timeSegT ) / 3;
}

void loop() {
