{"id":437,"date":"2013-11-04T00:59:19","date_gmt":"2013-11-03T23:59:19","guid":{"rendered":"http:\/\/eiseler.synology.me\/wordpress\/?p=437"},"modified":"2013-11-04T00:59:20","modified_gmt":"2013-11-03T23:59:20","slug":"grove-tick-tock-shield-kit","status":"publish","type":"post","link":"http:\/\/eiseler.de\/wordpress\/?p=437","title":{"rendered":"Grove Tick Tock Shield Kit"},"content":{"rendered":"<p>Giving the <a href=\"http:\/\/www.seeedstudio.com\/wiki\/Tick_Tock_Shield_Kit\">Tick Tock Shield Kit<\/a> by Grove a try, I made same changes to the real time clock code. First I wanted to automaticaly change the brightness not only at the start of the code. And second I wanted the date to displayed to. Now it displays alternately with the temperature. (To set the date, do this once when hour and minutes are set, see comment there. This should be enough, no need to alter with the buttons). Had to change the library too. So find all the code here. RealTimeClock2:<\/p>\n<pre class=\"brush: c; gutter: false\">\/****************************************************************************\/\r\n\/\/  Demo function:\r\n\/\/\r\n\/\/  Author:Frankie.Chu\r\n\/\/  Date:23 September, 2012\r\n\/\/\r\n\/\/  This library is free software; you can redistribute it and\/or\r\n\/\/  modify it under the terms of the GNU Lesser General Public\r\n\/\/  License as published by the Free Software Foundation; either\r\n\/\/  version 2.1 of the License, or (at your option) any later version.\r\n\/\/\r\n\/\/  This library is distributed in the hope that it will be useful,\r\n\/\/  but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n\/\/  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r\n\/\/  Lesser General Public License for more details.\r\n\/\/\r\n\/\/  You should have received a copy of the GNU Lesser General Public\r\n\/\/  License along with this library; if not, write to the Free Software\r\n\/\/  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r\n\/\/\r\n\/\/  Modified record:\r\n\/\/  Johannes, added function for auto brighness and showing date 11\/2013\r\n\/\/\r\n\/*******************************************************************************\/\r\n\r\n#include &quot;Wire.h&quot;\r\n#include &lt;TimerOne.h&gt;\r\n#include &lt;MsTimer2.h&gt;\r\n#include &lt;EEPROM.h&gt;\r\n#include &quot;TM1636.h&quot;\r\n#include &quot;TickTockShield.h&quot;\r\n\r\n#define ON 1\r\n#define OFF 0\r\n\r\n\/\/definitions of global variables\r\nboolean flag_update;\/\/1 = update the time on the 4-digit display\r\nunsigned char halfsecond;\/\/each time the timer2 interrupts,halfsecond plus one.\r\nboolean flag_clockpoint = 1;\/\/change between 0 and 1 every 500ms. If it is 1,\r\n\/\/the clockpoint is on.Else the clockpoint is off.\r\nboolean flag_2s;\/\/2 seconds flag.1 = to the end of 2 seconds so as to set \r\n\/\/flag_display_time\r\nboolean flag_10s;\/\/10 seconds flag.1 = to the end of 10 seconds so as to \r\n\/\/display temperature\r\nboolean flag_display_time = 1;\/\/1 = can display time that get from the RTC\r\nuint8_t counter_times = 20;\/\/20*halfsecond = 10seconds.\r\n\/\/If it is 20,to count for 10s,so display time for 10s.\r\n\/\/If it is 4,to count for 2s,so display the temperture for 2s\r\nboolean flag_500ms_blink;\/\/when adjusting the time or the alarm,the hour or minute\r\n\/\/displayed on the 4-digit display will blink every 500ms.\r\nboolean flag_scan_again;\/\/1 = can scan key again at the state of SYSTEM_NORAML\r\n\/\/To avoid the mistake of entering the state of SYSTEM_ADJUSTING \r\n\/\/again when pressing MENU for 3s to confirm the setting.\r\nuint8_t counter_500ms;\/\/when counter_500 reach 6,flag_scan_again is set 1.\r\n\r\nboolean flag_temp_shown; \/\/ added by Johannes\r\n\r\n\/*status definitions for the tick shield control system*\/\r\nuint8_t system_states;\r\n#define SYSTEM_NORAML    0 \/\/default status,and the system will turn to &quot;normal&quot; status \r\n#define SYSTEM_ADJUSTING 1 \/\/triggered when key MENU is pressed at the &quot;normal&quot; status.\r\n#define SYSTEM_ALARMING  2\r\n\r\n\/\/--Declare a TickTockShield Class object--\/\/\r\nTickTockShield ticktockshield;\r\n\r\nextern int8_t disp[4];\/\/external global array defined in TickTockShield.cpp\r\n\r\nextern byte g_hand;\/\/external global variable.\r\n\/\/the clock hand, HOUR shows that it is adjusting the hour, \r\n\/\/MINUTE shows that it is adjusting the minute.\r\n\r\nvoid setup() \r\n{\r\n#ifdef DEBUG\r\n  Serial.begin(9600);\r\n#endif\r\n  ticktockshield.init();\r\n\r\n  \/*Run the 4 LEDs from left to right*\/\r\n  ticktockshield.runLED();\r\n  if(isFirstLoad())\/\/if it is the first time to load the firmware?\r\n  {\r\n    ticktockshield.setAlarm(12,0);\/\/Yes,the alarm clock is initialized to 12:00\r\n    \/\/and the data in the EEPROM.\r\n  }\r\n  else ticktockshield.getAlarm();\/\/No,read the alarm clock stored in EEPROM\r\n  \/*When system starts, adjust the brightness of the digital tube \r\n   \t\t\taccording to the ambient light intensity.*\/\r\n  uint8_t lightlevel; \r\n  lightlevel = ticktockshield.getLightLevel();\r\n  ticktockshield.adjustBrightness(lightlevel);\r\n  \/*Read the ambient temperature and display on the digital tube.*\/\r\n  ticktockshield.displayTemperature(ticktockshield.getTemperature());\r\n  delay(1000);\r\n  MsTimer2::set(500, Timer2ISR);\/\/Timer2 generates an interrupt every 500ms\r\n  MsTimer2::start();\/\/Timer2 starts counting\r\n}\r\nvoid loop() \r\n{\r\n  clockStart();\r\n}\r\n\/****************************************************************\/\r\n\/*Function:Implement the function of a clock with an alarm clock, and *\/\r\n\/*\t\t\tthe buttons can adjust the clock.*\/\r\nvoid clockStart()\r\n{\r\n  if(system_states == SYSTEM_NORAML)\/\/if it is normal states?\r\n  {\r\n    \/*Yes, the clock will update every 500ms,and check whether the Menu is pressed *\/\r\n    \/*to enter SYSTEM_ADJUSTING state and check if it should be enter SYSTEM_ALARMING state.*\/\r\n    if(flag_update)\/\/if update flag is not zero?\r\n    { \r\n      flag_update = 0;\r\n      if(flag_clockpoint)\r\n      {\r\n        tm1636.point(POINT_ON);\r\n      }\r\n      else tm1636.point(POINT_OFF); \r\n      ticktockshield.getTime();\r\n      if(ticktockshield.isAlarmEnable())\r\n      {\r\n        tm1636.point(POINT_ON);\r\n        ticktockshield.displayTime();\r\n        system_states = SYSTEM_ALARMING;\r\n        return;\r\n      }\r\n      if(flag_display_time)ticktockshield.displayTime();\r\n\r\n      if(flag_2s)\r\n      {\r\n        flag_2s = 0;\r\n        flag_display_time = 1;\r\n\r\n        counter_times = 20;\r\n        halfsecond = 0;\r\n      }\r\n      if(flag_10s)\r\n      {\r\n        flag_10s = 0;\r\n        flag_display_time = 0;\r\n\r\n        if(flag_temp_shown == 0){\r\n          tm1636.point(POINT_OFF);\r\n          ticktockshield.displayTemperature(ticktockshield.getTemperature());\r\n          flag_temp_shown = 1;\r\n        } \r\n        else {\r\n\r\n          \/\/ Johannes: Set the new brightness; bug fixed 7 - lightlevel as parameter\r\n          uint8_t lightlevel; \r\n          lightlevel = ticktockshield.getLightLevel();\r\n          ticktockshield.adjustBrightness(7 - lightlevel);\r\n\r\n          tm1636.point(POINT_ON);\r\n          ticktockshield.displayDate(); \r\n          flag_temp_shown = 0;\r\n\r\n        }\r\n\r\n        counter_times = 4;\r\n        halfsecond = 0;\r\n\r\n        \/*\r\n        int8_t temp[4];\r\n         temp[0] = ticktockshield.g_dayOfMonth\/10;\r\n         temp[1] = g_dayOfMonth%10;\r\n         temp[2] = g_month\/10;\r\n         temp[3] = g_month%10;\r\n         \ttm1636.display(temp);\r\n         *\/\r\n      }\r\n      if((flag_scan_again)&amp;&amp;(KEY_MENU == ticktockshield.scanKey()))\r\n      {\r\n        ticktockshield.writeToAdjustArea();\r\n        ticktockshield.processKey();\r\n        system_states = SYSTEM_ADJUSTING;\r\n      }\r\n\r\n    }\r\n  }\r\n  else if(system_states == SYSTEM_ADJUSTING)\r\n  {\r\n    ticktockshield.scanKey();\r\n    ticktockshield.processKey();\r\n    ticktockshield.processSystemStatus();\r\n    if(ticktockshield.getQuitReq())\r\n    {\r\n      system_states = SYSTEM_NORAML;\r\n      counter_500ms = 0;\r\n      flag_scan_again = 0;\r\n    }\r\n    else flag_scan_again = 1;\r\n  }\r\n  else if(system_states == SYSTEM_ALARMING)\r\n  {\r\n    \/*It will sound alarm for a minute untill the &quot;MENU&quot; key is pressed*\/\r\n    if(ticktockshield.isAlarmEnable())\r\n    {\r\n      ticktockshield.alarming();\r\n    }\r\n    else \r\n    {\r\n      ticktockshield.turnOffAlarm();\r\n      system_states = SYSTEM_NORAML;\r\n    }\r\n    if(KEY_MENU == ticktockshield.scanKey())\r\n    {\r\n      ticktockshield.turnOffAlarm();\r\n      system_states = SYSTEM_NORAML;\r\n    }\r\n  }\r\n}\r\n\r\n\/\/--------------------------------------\r\nboolean isFirstLoad()\r\n{\r\n  unsigned char mark[] = &quot;ALARM&quot;;\r\n  unsigned char temp_data[5];\r\n  for(unsigned char i = 0;i &lt; 5;i ++)\r\n  {\r\n    temp_data[i] = EEPROM.read(i);\r\n    if(temp_data[i] != mark[i])\r\n    {\r\n      EEPROM.write(0,mark[0]);\r\n      EEPROM.write(1,mark[1]);\r\n      EEPROM.write(2,mark[2]);\r\n      EEPROM.write(3,mark[3]);\r\n      EEPROM.write(4,mark[4]);\r\n      return true;\r\n    }\r\n  }\r\n  return false;\r\n}\r\n\r\n\/*Function:It is timer 2 interrupt service routine.Timer2 generates an interrupt*\/\r\n\/*  every 500ms.And every time it interrupts,this function will be executed.*\/\r\nvoid Timer2ISR()\r\n{\r\n  halfsecond ++;\r\n  if(halfsecond  == counter_times)\r\n  {\r\n    halfsecond  = 0;\r\n    if(counter_times == 4)flag_2s = 1;\r\n    else if(counter_times == 20)flag_10s = 1;\r\n  }\r\n  flag_update = 1;\r\n  flag_clockpoint = (~flag_clockpoint) &amp; 0x01;\/\/change between 0 and 1 every 500ms.\r\n  flag_500ms_blink = ~flag_500ms_blink;\r\n  if(ticktockshield.isAdjustingTime())\r\n  {\r\n    if(g_hand == HOUR)\r\n    {\r\n      if(flag_500ms_blink)\r\n      {\r\n        disp[0] = INDEX_BLANK;\r\n        disp[1] = INDEX_BLANK;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      if(flag_500ms_blink)\r\n      {\r\n        disp[2] = INDEX_BLANK;\r\n        disp[3] = INDEX_BLANK;\r\n      }\r\n    }\r\n    tm1636.display(disp);\r\n  }\r\n  counter_500ms ++;\r\n  if(counter_500ms == 6)\r\n  {\r\n    counter_500ms = 0;\r\n    flag_scan_again = 1;\r\n  }\r\n\r\n}<\/pre>\n<p>TickTockShield.h:<\/p>\n<pre class=\"brush: c; gutter: true\">#ifndef TICKTOCKSHIELD_H_\r\n#define TICKTOCKSHIELD_H_\r\n\r\n#include &quot;TM1636.h&quot;\r\n\r\n#define DS1307_I2C_ADDRESS 0x68\r\n\r\n\/\/debug configuration\r\n#define DEBUG 0\r\n\/\/-------pin definition of keys---------------\/\/\r\n#define KEY_MENU\t11\r\n#define KEY_UP\t\t10\r\n#define KEY_DOWN\t9\r\n\r\n\/\/-------pin definition of LEDs---------------\/\/\r\n#define LED_CLOCK_ADJUST\t5\r\n#define LED_ALARM_ADJUST\t4\r\n#define LED_ALARM_ENABLE\t3\r\n#define LED_BRIGHT_ADJUST\t2\r\n\r\n#define ALARM_BUZZER\t\t6\r\n\r\n\/\/-------pin definition of sensors-------------\/\/\r\n#define TEMPERATURE_SENSOR\tA0\r\n#define LIGHT_SENSOR\t\tA1\r\n\r\n#define LED_ON\t1\r\n#define LED_OFF 0\r\n\r\n#define HOUR\t0\r\n#define MINUTE\t1\r\n\/*Direction of the LEDs to run*\/\r\n#define LEFT_TO_RIGHT 0\r\n#define RIGHT_TO_LEFT 1\r\n\/\/-------Status bit definition of the Status flag----\/\/\r\n\/*volatile typedef enum{\r\n  SS_NO_INPUT = 0,\/\/no keys input\r\n  SS_CLOCKH_ADJUST,\/\/adjust the hour of the clock\r\n  SS_CLOCKM_ADJUST,\t\/\/adjust the minute of the clock\r\n  SS_ALARMH_ADJUST,\t\/\/adjust the hour of the alarm\r\n  SS_ALARMM_ADJUST,\t\/\/adjust the minute of the alarm\r\n  SS_ALARM_ENABLE,  \/\/to enable or disable the alarm\r\n  SS_BRIGHT_ADJUST,\t\/\/adjust the brightness of the 4-digit display\r\n  SS_CONFIRM_EXIT,  \/\/It will confirm the setting and exit after pressing the MENU button for more than 3s\r\n  \t\t\t\t\t\/\/or after pressing it again at the status of adjust brightness.\r\n  SS_QUIT,\t\t\t\/\/It will exit without saving any setting if no button is pressed within 5s.\r\n}keyStatusType;*\/\r\n\/\/extern keyStatusType system_status;\r\n\r\n#define SS_NO_INPUT \t\t0\/\/no keys input\r\n#define SS_CLOCKH_ADJUST\t1\/\/adjust the hour of the clock\r\n#define SS_CLOCKM_ADJUST\t2\/\/adjust the minute of the clock\r\n#define SS_ALARMH_ADJUST\t3\/\/adjust the hour of the alarm\r\n#define SS_ALARMM_ADJUST\t4\/\/adjust the minute of the alarm\r\n#define SS_ALARM_ENABLE  \t5\/\/to enable or disable the alarm\r\n#define SS_BRIGHT_ADJUST\t6\/\/adjust the brightness of the 4-digit display\r\n#define SS_CONFIRM_EXIT  \t7\/\/It will confirm the setting and exit after pressing the MENU button for more than 3s\r\n\t\t\t\t\t\t\t \/\/or after pressing it again at the status of adjust brightness.\r\n#define SS_QUIT\t\t\t\t8\/\/It will exit without saving any setting if no button is pressed within 5s.\r\n\r\n#define KEY_PRESSED 1\r\n#define KEY_RELEASE 2\r\n\r\n#define RESISTOR_CONNECT_THERMISTOR\t10000\r\nstruct AlarmStruct\r\n{\r\n  byte hour;\r\n  byte minute;\r\n  boolean flag_enable;\r\n};\r\nclass TickTockShield\r\n{\r\npublic:\r\n  void init();\r\n  void setLed(unsigned char led_status, int pinLED);\r\n  void turnOffLED();\r\n  void turnOnLED();\r\n  void runLED(byte = 1, byte = LEFT_TO_RIGHT);\r\n  int16_t scanKey();\r\n  void processKey();\r\n  void processSystemStatus();\r\n  void quit();\r\n  void saveChanges();\r\n  inline void modifyAlarmFlag();\r\n  void adjustClock(uint8_t hand);\r\n  void adjustAlarm(uint8_t hand);\r\n  void adjustBrightness();\r\n  void adjustBrightness(uint8_t grayscale);\r\n  int8_t getTemperature();\r\n  void displayTemperature(int8_t temperature);\r\n  float getLightIntensity();\r\n  uint8_t getLightLevel();\r\n  void ringOn();\r\n  void ringOff();\r\n  void alarming();\r\n  void turnOffAlarm();\r\n  boolean isAlarmEnable();\r\n  boolean compareWithAlarm();\r\n  inline void alarmDisable();\r\n  void setAlarm(struct AlarmStruct alarm_);\r\n  void setAlarm(uint8_t hour,uint8_t minute,uint8_t = 0);\r\n  void getAlarm();\r\n\r\n  void writeToAdjustArea();\r\n  void writeToNormalArea();\r\n  void writeTime();\r\n  void getTime();\r\n  void displayTime();\r\n  void displayDate();  \/\/added by Johannes\r\n  void display(int8_t DispData []);\r\n  void clearTime(uint8_t hand);\r\n  byte decToBcd(byte val);\r\n  byte bcdToDec(byte val);\r\n  byte getQuitReq(){return flag_require_quit;}\r\n  boolean isAdjustingTime();\r\nprivate:\r\n  \/*Globle variables in the class*\/\r\n  byte g_second, g_minute, g_hour;\r\n  \/*when the clock is being adjusted, these two variables save the temporary data.*\/\r\n  byte g_minute_temp,g_hour_temp;\r\n  byte g_dayOfWeek;\r\n  byte g_dayOfMonth, g_month, g_year;\r\n  AlarmStruct alarm;\r\n  byte g_brightness;\r\n  byte g_brightness_temp;\r\n  \/*when the alarm is being adjusted, this variable save the temporary data.*\/\r\n  AlarmStruct alarm_temp;\r\n  int16_t pre_pin_number;\/\/pin number of the key pressed before\r\n  int16_t key_pin_pressed;\/\/pin number of the key pressed now\r\n  uint8_t tempKeyValue;\r\n  uint8_t stateMenu;\r\n  uint8_t stateUp;\r\n  uint8_t stateDown;\r\n\r\n  uint8_t system_status;\r\n  byte flag_require_quit;\r\n  boolean flag_adjust_time;\r\n  boolean flag_alarm_over;\r\n\r\n  void keyInit();\r\n  void ledInit();\r\n  void sensorInit();\r\n  void buzzerInit();\r\n};\r\nextern TM1636 tm1636;\r\n\r\n#endif<\/pre>\n<p>TickTockShield.cpp<\/p>\n<pre class=\"brush: cpp; gutter: false\">#include &quot;TickTockShield.h&quot;\r\n#include &lt;Arduino.h&gt;\r\n#include &lt;EEPROM.h&gt;\r\n#include &lt;Wire.h&gt;\r\n#include &lt;TimerOne.h&gt;\r\n#include &quot;TM1636.h&quot;\r\n\r\nTM1636 tm1636(7,8);\r\nvoid timerIsr();\r\n\/*global variables also used in timer interrupt serve routine *\/\r\nuint8_t key_menu_status;\r\nuint16_t count_10ms_pressed;\r\nuint16_t count_10ms_release;\r\nboolean flag_pressed_3s;\r\nboolean flag_release_10s;\r\nboolean alarm_on_off;\r\n\r\nint8_t disp[4];\r\nint8_t disp_buff[4];\r\nbyte g_hand;\r\n\r\n\/\/--------------------------------\/\/\r\nvoid TickTockShield::init()\r\n{\r\n\tg_brightness = BRIGHT_TYPICAL;\r\n  tm1636.set(g_brightness);\r\n  tm1636.init();\r\n  keyInit();\r\n  ledInit();\r\n  sensorInit();\r\n\tbuzzerInit();\r\n  Wire.begin();\r\n\tpre_pin_number = -1;\r\n\tTimer1.initialize(100000); \/\/ set a timer of length 100000 microseconds \r\n\t\t\/\/(or 0.1 sec - or 10Hz =&gt; the led will blink 5 times, 5 cycles of on-and-off, per second)\r\n  Timer1.attachInterrupt( timerIsr ); \/\/ attach the service routine here\r\n}\r\n\r\nvoid TickTockShield::keyInit()\r\n{\r\n  \/\/Set all three keys to be input and internal pull-up\r\n\r\n  pinMode(KEY_MENU, INPUT);\r\n  digitalWrite(KEY_MENU, HIGH);\r\n  pinMode(KEY_UP, INPUT);\r\n  digitalWrite(KEY_UP, HIGH);\r\n  pinMode(KEY_DOWN, INPUT);\r\n  digitalWrite(KEY_DOWN, HIGH);\r\n}\r\nvoid TickTockShield::ledInit()\r\n{\r\n  pinMode(LED_CLOCK_ADJUST, OUTPUT);\r\n  pinMode(LED_ALARM_ADJUST, OUTPUT);\r\n  pinMode(LED_BRIGHT_ADJUST, OUTPUT);\r\n  pinMode(LED_ALARM_ENABLE, OUTPUT);\r\n\tturnOffLED();\r\n}\r\nvoid TickTockShield::sensorInit()\r\n{\r\n  pinMode(TEMPERATURE_SENSOR, INPUT);\r\n  pinMode(LIGHT_SENSOR, INPUT);\r\n}\r\nvoid TickTockShield::buzzerInit()\r\n{\r\n\tpinMode(ALARM_BUZZER, OUTPUT);\r\n  pinMode(ALARM_BUZZER, OUTPUT);\r\n}\r\nvoid TickTockShield::setLed(unsigned char led_status, int pinLED)\r\n{\r\n\tdigitalWrite(pinLED, led_status);\r\n}\r\n\/********************************\/\r\nvoid TickTockShield::turnOffLED()\r\n{\r\n\tsetLed(LOW,LED_CLOCK_ADJUST);\r\n\tsetLed(LOW,LED_ALARM_ADJUST);\r\n\tsetLed(LOW,LED_BRIGHT_ADJUST);\r\n\tsetLed(LOW,LED_ALARM_ENABLE);\r\n}\r\n\/********************************\/\r\nvoid TickTockShield::turnOnLED()\r\n{\r\n\tsetLed(HIGH,LED_CLOCK_ADJUST);\r\n\tsetLed(HIGH,LED_ALARM_ADJUST);\r\n\tsetLed(HIGH,LED_BRIGHT_ADJUST);\r\n\tsetLed(HIGH,LED_ALARM_ENABLE);\r\n}\r\n\r\n\/*******************************\/\r\nvoid TickTockShield::runLED(byte speed, byte direction)\r\n{\r\n\tif((speed &gt; 0)&amp;&amp;(speed &lt; 11))\/\/If the value of speed is valid?\r\n\t{\r\n\t\tturnOffLED();\r\n\t\tuint8_t shifter = 0x01;\r\n\t\tif(LEFT_TO_RIGHT == direction)\r\n\t\t{\r\n\t\t\tfor(uint8_t i = 0;i &lt; 4;i ++)\r\n\t\t\t{\r\n\t\t\t\tif(shifter&amp;0x01) setLed(LED_ON,  LED_CLOCK_ADJUST);\r\n\t\t\t\telse\t\t\t\t\t\t setLed(LED_OFF, LED_CLOCK_ADJUST);\r\n\t\t\t\tif(shifter&amp;0x02) setLed(LED_ON,  LED_ALARM_ADJUST);\r\n\t\t\t\telse\t\t\t\t\t   setLed(LED_OFF, LED_ALARM_ADJUST);\r\n\t\t\t\tif(shifter&amp;0x04) setLed(LED_ON,  LED_ALARM_ENABLE);\r\n\t\t\t\telse\t\t\t\t\t\t setLed(LED_OFF, LED_ALARM_ENABLE);\r\n\t\t\t\tif(shifter&amp;0x08) setLed(LED_ON,  LED_BRIGHT_ADJUST);\r\n\t\t\t\telse\t\t\t\t\t\t setLed(LED_OFF, LED_BRIGHT_ADJUST);\r\n\t\t\t\tshifter &lt;&lt;= 1;\r\n\t\t\t\tdelay(500\/speed);\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tfor(uint8_t i = 0;i &lt; 4;i ++)\r\n\t\t\t{\r\n\t\t\t\tif(shifter&amp;0x01) setLed(LED_ON,  LED_BRIGHT_ADJUST);\r\n\t\t\t\telse\t\t\t\t\t\t setLed(LED_OFF, LED_BRIGHT_ADJUST);\r\n\t\t\t\tif(shifter&amp;0x02) setLed(LED_ON,  LED_ALARM_ENABLE);\r\n\t\t\t\telse\t\t\t\t\t   setLed(LED_OFF, LED_ALARM_ENABLE);\r\n\t\t\t\tif(shifter&amp;0x04) setLed(LED_ON,  LED_ALARM_ADJUST);\r\n\t\t\t\telse\t\t\t\t\t\t setLed(LED_OFF, LED_ALARM_ADJUST);\r\n\t\t\t\tif(shifter&amp;0x08) setLed(LED_ON,  LED_CLOCK_ADJUST);\r\n\t\t\t\telse\t\t\t\t\t\t setLed(LED_OFF, LED_CLOCK_ADJUST);\r\n\t\t\t\tshifter &lt;&lt;= 1;\r\n\t\t\t\tdelay(500\/speed);\r\n\t\t\t}\r\n\t\t}\r\n\t\tturnOffLED();\r\n\t}\r\n}\r\n\/\/--------------------------------\/\/\r\n\/\/-Return:the pin number of the key pressed\r\n\/\/--------------------------------\/\/\r\n\/\/\r\nint16_t TickTockShield::scanKey()\r\n{\r\n\tint16_t pin_number = 0;\r\n\tstatic boolean pre_key_menu_level = HIGH;\r\n\tboolean cur_key_menu_level;\r\n\tif(digitalRead(KEY_MENU) == LOW)\r\n\t{\r\n\t\tdelay(30);\r\n\t\tif(digitalRead(KEY_MENU) == LOW)\r\n\t\t{\r\n\t\t\tcur_key_menu_level = LOW;\r\n\t\t\tpin_number = KEY_MENU;\r\n\t\t}\r\n\t\telse cur_key_menu_level = HIGH;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tcur_key_menu_level = HIGH;\r\n\t}\r\n\tif(pre_key_menu_level &gt; cur_key_menu_level)\r\n\t{\r\n\r\n\t\tkey_menu_status = KEY_PRESSED;\r\n\t\tif(system_status &lt; 7)system_status ++;\r\n\t\tcount_10ms_pressed = 0;\r\n\t\tflag_pressed_3s = 0;\r\n\t#ifdef DEBUG\r\n\t\tSerial.print(&quot;system_status = &quot;);\r\n\t  Serial.println(system_status);\r\n\t\tSerial.println(&quot;Key_Menu pressed&quot;);\r\n\t#endif\r\n\t}\r\n\telse if(pre_key_menu_level &lt; cur_key_menu_level)\r\n\t{\r\n\t\tkey_menu_status = KEY_RELEASE;\r\n\t\tcount_10ms_release = 0;\r\n\t\tflag_release_10s = 0;\r\n\t#ifdef DEBUG\r\n\t\tSerial.println(&quot;Key_Menu release&quot;);\r\n  #endif\r\n\t}\r\n\tpre_key_menu_level = cur_key_menu_level;\r\n\r\n\tif(digitalRead(KEY_UP) == LOW)\r\n\t{\r\n\t\tdelay(20);\r\n\t\tif(digitalRead(KEY_UP) == LOW)\r\n\t\t{\r\n\t\t\tpin_number = KEY_UP;\r\n\t\t\tcount_10ms_release = 0;\r\n\t\t\tflag_release_10s = 0;\r\n\t\t#ifdef DEBUG\r\n\t\t\tSerial.println(&quot;Key_UP pressed&quot;);\r\n\t\t#endif\r\n\t\t}\r\n\r\n\t}\r\n\telse if(digitalRead(KEY_DOWN) == LOW)\r\n\t{\r\n\t\tdelay(20);\r\n\t\tif(digitalRead(KEY_DOWN) == LOW)\r\n\t\t{\r\n\t\t\tpin_number = KEY_DOWN;\r\n\t\t\tcount_10ms_release = 0;\r\n\t\t\tflag_release_10s = 0;\r\n\t\t#ifdef DEBUG\r\n\t\t\tSerial.println(&quot;KEY_DOWN pressed&quot;);\r\n\t\t#endif\r\n\t\t}\r\n\t}\r\n\tif(pin_number == 0)pin_number = -1;\r\n\tkey_pin_pressed = pin_number;\r\n\treturn key_pin_pressed;\r\n}\r\n\/*************************************************\/\r\n\/*Function:*\/\r\n\/*Return:   void*\/\r\nvoid TickTockShield::processKey()\r\n{\r\n\tif((key_pin_pressed &gt; 0)&amp;&amp;(pre_pin_number != key_pin_pressed))\r\n\t{\r\n\t\tringOn();\r\n\t\tdelay(100);\r\n\t\tringOff();\r\n\t}\r\n\tpre_pin_number = key_pin_pressed;\r\n\tif(flag_pressed_3s)\r\n\t{\r\n\t\tflag_pressed_3s = 0;\r\n\t\tsystem_status = SS_CONFIRM_EXIT;\r\n\t#ifdef DEBUG\r\n\t\tSerial.print(&quot;system_status = &quot;);\r\n\t  Serial.println(system_status);\r\n\t\tSerial.println(&quot;Press for 3s...&quot;);\r\n\t#endif\r\n\t}\r\n\tif(flag_release_10s)\r\n\t{\r\n\t\tflag_release_10s = 0;\r\n\t\tsystem_status = SS_QUIT;\r\n\t#ifdef DEBUG\r\n\t\tSerial.print(&quot;system_status = &quot;);\r\n\t  Serial.println(system_status);\r\n\t\tSerial.println(&quot;Release for 5s&quot;);\r\n\t#endif\r\n\t}\t\r\n}\r\nvoid TickTockShield::processSystemStatus()\r\n{\r\n\tswitch(system_status)\r\n\t{\r\n\t\tcase SS_NO_INPUT:\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\t\t\t\t\t\t\t\t\t\t\r\n\t\tcase SS_CLOCKH_ADJUST:adjustClock(HOUR);\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\t\r\n\t\tcase SS_CLOCKM_ADJUST:adjustClock(MINUTE);\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\t\r\n\t\tcase SS_ALARMH_ADJUST:adjustAlarm(HOUR);\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\t\r\n\t\tcase SS_ALARMM_ADJUST:adjustAlarm(MINUTE);\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\t\r\n\t\tcase SS_ALARM_ENABLE: flag_adjust_time = 0;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tmodifyAlarmFlag();\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\t\r\n\t\tcase SS_BRIGHT_ADJUST:adjustBrightness();\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\t\r\n\t\tcase SS_CONFIRM_EXIT: saveChanges();\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tsystem_status = SS_NO_INPUT;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\t\r\n\t\tcase SS_QUIT:\t\t\t\t\tquit();\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tsystem_status = SS_NO_INPUT;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\r\n\t\tdefault:break;\t\r\n\t}\r\n\r\n}\r\nvoid TickTockShield::quit()\r\n{\r\n\tflag_require_quit = 1;\r\n\tflag_adjust_time = 0;\r\n\ttm1636.set(g_brightness);\r\n\tturnOffLED();\r\n\tif(alarm.flag_enable)\r\n\t\tsetLed(HIGH,LED_ALARM_ENABLE);\r\n\telse setLed(LOW,LED_ALARM_ENABLE);\r\n\r\n}\r\nvoid TickTockShield::saveChanges()\r\n{\r\n\tg_hour   = g_hour_temp;\r\n\tg_minute = g_minute_temp;\r\n\r\n    \/\/ added by Johannes\r\n    \/\/ do this once to set the date\r\n \/\/   g_dayOfMonth = 3;\r\n \/\/   g_month = 11;\r\n\r\n\twriteTime();\r\n\r\n\talarm.hour        = alarm_temp.hour;\r\n\talarm.minute      = alarm_temp.minute;\r\n\talarm.flag_enable = alarm_temp.flag_enable;\r\n\tsetAlarm(alarm);\r\n\r\n\tg_brightness \t\t\t= g_brightness_temp;\r\n\ttm1636.set(g_brightness);\r\n\r\n\tflag_alarm_over = 0;\r\n\tquit();\r\n}\r\ninline void TickTockShield::modifyAlarmFlag()\r\n{\r\n\tturnOffLED();\r\n\tif(key_pin_pressed == KEY_UP)\r\n\t{\r\n\t\talarm_temp.flag_enable = ~alarm_temp.flag_enable;\r\n\t}\r\n\tif(alarm_temp.flag_enable)\r\n\t{\r\n\t\tsetLed(HIGH,LED_ALARM_ENABLE);\r\n\t}\r\n\telse\r\n\t{\r\n\t\tsetLed(LOW,LED_ALARM_ENABLE);\r\n\t}\r\n\tdisp[0] = alarm_temp.hour\/10;\r\n\tdisp[1] = alarm_temp.hour%10;\r\n\tdisp[2] = alarm_temp.minute\/10;\r\n\tdisp[3] = alarm_temp.minute%10;\r\n\ttm1636.display(disp);\r\n}\r\nvoid TickTockShield::adjustClock(uint8_t hand)\r\n{\r\n\tturnOffLED();\r\n\tsetLed(HIGH,LED_CLOCK_ADJUST);\r\n\tif(hand == HOUR)\r\n\t{\r\n\t\tg_hand = HOUR;\r\n\t\tif(key_pin_pressed == KEY_DOWN)\r\n\t\t{\r\n\t\t\tif(g_hour_temp&gt; 0)\r\n\t\t\t\tg_hour_temp--;\r\n\t\t}\r\n\t\telse if(key_pin_pressed == KEY_UP)\r\n\t\t{\r\n\t\t\tif(g_hour_temp&lt; 23)\r\n\t\t\t\tg_hour_temp++;\r\n\t\t\telse g_hour_temp = 0;\r\n\t\t}\r\n\t}\r\n\telse\r\n\t{\r\n\t\tg_hand = MINUTE;\r\n\t\tif(key_pin_pressed == KEY_DOWN)\r\n\t\t{\r\n\t\t\tif(g_minute_temp&gt; 0)\r\n\t\t\t\tg_minute_temp--;\r\n\t\t}\r\n\t\telse if(key_pin_pressed == KEY_UP)\r\n\t\t{\r\n\t\t\tif(g_minute_temp&lt; 59)\r\n\t\t\t\tg_minute_temp++;\r\n\t\t\telse g_minute_temp = 0;\r\n\t\t}\r\n\t}\r\n\tdisp[0] = g_hour_temp\/10;\r\n\tdisp[1] = g_hour_temp%10;\r\n\tdisp[2] = g_minute_temp\/10;\r\n\tdisp[3] = g_minute_temp%10;\r\n\/\/\ttm1636.display(disp);\r\n}\r\nvoid TickTockShield::adjustAlarm(uint8_t hand)\r\n{\r\n\tturnOffLED();\r\n\tsetLed(HIGH,LED_ALARM_ADJUST);\r\n\tif(hand == HOUR)\r\n\t{\r\n\t\tg_hand = HOUR;\r\n\t\tif(key_pin_pressed == KEY_DOWN)\r\n\t\t{\r\n\t\t\tif(alarm_temp.hour&gt; 0)\r\n\t\t\t\talarm_temp.hour--;\r\n\t\t}\r\n\t\telse if(key_pin_pressed == KEY_UP)\r\n\t\t{\r\n\t\t\tif(alarm_temp.hour&lt; 23)\r\n\t\t\t\talarm_temp.hour++;\r\n\t\t\telse alarm_temp.hour = 0;\r\n\t\t}\r\n\t}\r\n\telse\r\n\t{\r\n\t\tg_hand = MINUTE;\r\n\t\tif(key_pin_pressed == KEY_DOWN)\r\n\t\t{\r\n\t\t\tif(alarm_temp.minute&gt; 0)\r\n\t\t\t\talarm_temp.minute--;\r\n\t\t}\r\n\t\telse if(key_pin_pressed == KEY_UP)\r\n\t\t{\r\n\t\t\tif(alarm_temp.minute&lt; 59)\r\n\t\t\t\talarm_temp.minute++;\r\n\t\t\telse alarm_temp.minute = 0;\r\n\t\t}\r\n\t}\r\n\tdisp[0] = alarm_temp.hour\/10;\r\n\tdisp[1] = alarm_temp.hour%10;\r\n\tdisp[2] = alarm_temp.minute\/10;\r\n\tdisp[3] = alarm_temp.minute%10;\r\n\/\/\ttm1636.display(disp);\r\n}\r\n\/***********************************\/\r\nvoid TickTockShield::adjustBrightness()\r\n{\r\n\tturnOffLED();\r\n\tsetLed(HIGH,LED_BRIGHT_ADJUST);\r\n\tif(key_pin_pressed == KEY_DOWN)\r\n\t{\r\n\t\tif(g_brightness_temp&gt; 0)\r\n\t\t\tg_brightness_temp--;\r\n\t}\r\n\telse if(key_pin_pressed == KEY_UP)\r\n\t{\r\n\t\tif(g_brightness_temp&lt; 7)\r\n\t\t\tg_brightness_temp++;\r\n\t}\r\n\ttm1636.set(g_brightness_temp);\r\n\tdisp[0] = alarm_temp.hour\/10;\r\n\tdisp[1] = alarm_temp.hour%10;\r\n\tdisp[2] = alarm_temp.minute\/10;\r\n\tdisp[3] = alarm_temp.minute%10;\r\n\ttm1636.display(disp);\r\n}\r\nvoid TickTockShield::adjustBrightness(uint8_t grayscale)\r\n{\r\n\tg_brightness = grayscale;\r\n\ttm1636.set(g_brightness);\r\n}\r\n\/****************************************************************\/\r\n\/*Return:int8_t,Temperature that range from -40 to 125 degrees.\t\t\t\t\t*\/\r\nint8_t TickTockShield::getTemperature()\r\n{\r\n\tfloat temperature,resistance;\r\n\tint a;\r\n\tint B = 3975;\r\n\ta = analogRead(TEMPERATURE_SENSOR);\r\n\tresistance   = (float)(1023-a)*RESISTOR_CONNECT_THERMISTOR\/a; \r\n\ttemperature  = 1\/(log(resistance\/RESISTOR_CONNECT_THERMISTOR)\/B+1\/298.15)-273.15;\r\n\treturn (int8_t)temperature;\r\n}\r\n\/**********************************************************************\/\r\n\/*Function:   Display the temperature on the 4-digit display\t\t\t\t\t\t\t\t\t\t*\/\r\n\/*Parameter:-int8_t temperature,Temperature that range from -40 to 125 degrees. *\/\r\n\/*Return:\t  void\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t*\/\r\nvoid TickTockShield::displayTemperature(int8_t temperature)\r\n{\r\n  int8_t temp[4];\r\n  if(temperature &lt; 0)\r\n\t{\r\n\t\ttemp[0] = INDEX_NEGATIVE_SIGN;\r\n\t\ttemperature = abs(temperature);\r\n\t}\r\n\telse if(temperature &lt; 100)temp[0] = INDEX_BLANK;\r\n\telse temp[0] = temperature\/100;\r\n\ttemperature %= 100;\r\n\ttemp[1] = temperature \/ 10;\r\n\ttemp[2] = temperature % 10;\r\n\ttemp[3] = 12;\t          \/\/index of &#039;C&#039; for celsius degree symbol.\r\n\ttm1636.display(temp);\r\n}\r\n\r\nfloat TickTockShield::getLightIntensity()\r\n{\r\n  int sensorValue = analogRead(LIGHT_SENSOR);\r\n  float rsensor;\r\n  rsensor=(float)(1023-sensorValue)*10\/sensorValue;\r\n\treturn rsensor;\r\n}\r\n\r\nuint8_t TickTockShield::getLightLevel()\r\n{\r\n\tuint16_t resistance;\r\n\tuint8_t light_level;\r\n\tresistance = (uint16_t)getLightIntensity();\r\n\tif(resistance &lt; 10) light_level = 0;\r\n\telse if(resistance &lt; 50)light_level = 1;\r\n\telse if(resistance &lt; 80)light_level = 2;\r\n\telse if(resistance &lt; 110)light_level = 3;\r\n\telse if(resistance &lt; 140)light_level = 4;\r\n\telse if(resistance &lt; 170)light_level = 5;\r\n\telse if(resistance &lt; 200)light_level = 6;\r\n\telse light_level = 7;\r\n\treturn light_level;\r\n}\r\n\r\nvoid TickTockShield::ringOn()\r\n{\r\n\tdigitalWrite(ALARM_BUZZER, HIGH);\r\n}\r\nvoid TickTockShield::ringOff()\r\n{\r\n\tdigitalWrite(ALARM_BUZZER, LOW);\r\n}\r\nvoid TickTockShield::alarming()\r\n{\r\n\tif(alarm_on_off)ringOn();\r\n\telse ringOff();\r\n}\r\nvoid TickTockShield::turnOffAlarm()\r\n{\r\n\tringOff();\r\n\tflag_alarm_over = 1;\r\n}\r\nboolean TickTockShield::isAlarmEnable()\r\n{\r\n\tif(compareWithAlarm())\r\n\t{\r\n\t\tif(!flag_alarm_over)\r\n\r\n\t\t\treturn true;\r\n\t}\r\n\telse flag_alarm_over = 0;\r\n\treturn false;\r\n}\r\n\/*******************************\/\r\nboolean TickTockShield::compareWithAlarm()\r\n{\r\n\tif(alarm.flag_enable &gt; 0)\r\n\t{\r\n\t\tif((alarm.hour == g_hour)&amp;&amp;(alarm.minute == g_minute))\r\n\t\t{\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\treturn false;\r\n}\r\n\r\ninline void TickTockShield::alarmDisable()\r\n{}\r\nvoid TickTockShield::setAlarm(struct AlarmStruct alarm_)\r\n{\r\n\tEEPROM.write(5,alarm_.hour);\r\n\tEEPROM.write(6,alarm_.minute);\r\n\tEEPROM.write(7,alarm_.flag_enable);\r\n\r\n}\r\nvoid TickTockShield::setAlarm(uint8_t hour,uint8_t minute,uint8_t flag_enable)\r\n{\r\n\tEEPROM.write(5,hour);\r\n\tEEPROM.write(6,minute);\r\n\tEEPROM.write(7,flag_enable);\r\n}\r\n\r\n\/************************************************************\/\r\n\/*Function:Read the alarm clock information from the built-in EEPROM  *\/\r\n\/*Return:   void\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   *\/\r\nvoid TickTockShield::getAlarm()\r\n{\r\n\talarm.hour        = EEPROM.read(5);\r\n\talarm.minute      = EEPROM.read(6);\r\n\talarm.flag_enable = EEPROM.read(7);\r\n#ifdef DEBUG\r\n\tSerial.print(&quot;alarm = &quot;);\r\n  Serial.print(alarm.hour);\r\n\tSerial.print(&quot; : &quot;);\r\n\tSerial.print(alarm.minute);\r\n#endif\r\n\tif(alarm.flag_enable)\r\n\t\tsetLed(HIGH,LED_ALARM_ENABLE);\r\n\telse setLed(LOW,LED_ALARM_ENABLE);\r\n}\r\n\/***********************************************************\/\r\n\/*Function:write data to the global variables in Ajust Area \t\t\t\t\t  *\/\r\n\/*Return:   void\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   *\/\r\nvoid TickTockShield::writeToAdjustArea()\r\n{\r\n\tg_hour_temp       = g_hour;\r\n\tg_minute_temp     = g_minute;\r\n\tg_brightness_temp = g_brightness;\r\n\talarm_temp.hour        = alarm.hour;\r\n\talarm_temp.minute      = alarm.minute;\r\n\talarm_temp.flag_enable = alarm.flag_enable;\r\n\tflag_require_quit = 0;\r\n\tflag_adjust_time = 1;\r\n\tpre_pin_number = -1;\r\n\ttm1636.point(POINT_ON);\r\n\tturnOffLED();\r\n}\r\n\r\n\/***********************************************************\/\r\n\/*Function:write data to the global variables in Normal Area    \t\t\t  *\/\r\n\/*Return:   void\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   *\/\r\nvoid TickTockShield::writeToNormalArea()\r\n{\r\n\tg_hour       = g_hour_temp;\r\n\tg_minute     = g_minute_temp;\r\n\tg_brightness = g_brightness_temp;\r\n\talarm.hour        = alarm_temp.hour;\r\n\talarm.minute      = alarm_temp.minute;\r\n\talarm.flag_enable = alarm_temp.flag_enable;\r\n}\r\n\r\n\/************************************************************\/\r\n\/*Frunction: Write the time that includes the date to the RTC chip\t\t\t*\/\r\n\/*Return:\t  void\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t*\/\r\nvoid TickTockShield::writeTime()\r\n{\r\n\tWire.beginTransmission(DS1307_I2C_ADDRESS);\r\n\tWire.write((byte)0x00);\r\n\tWire.write(decToBcd(g_second)); \t \/\/ 0 to bit 7 starts the clock\r\n\tWire.write(decToBcd(g_minute));\r\n\tWire.write(decToBcd(g_hour)); \t \/\/ If you want 12 hour am\/pm you need to set\r\n\t\t\t\t\t\t\t\t\t\/\/ bit 6 (also need to change readDateDs1307)\r\n\tWire.write(decToBcd(g_dayOfWeek));\r\n\tWire.write(decToBcd(g_dayOfMonth));\r\n\tWire.write(decToBcd(g_month));\r\n\tWire.write(decToBcd(g_year));\r\n\tWire.endTransmission();\r\n}\r\n\/************************************************\/\r\n\/*Frunction: Read time from RTC\t\t\t\t\t\t\t\t\t\t\t*\/\r\n\/*Parameter:A 2-byte array that tells the hour and\t\t\t*\/ \r\n\/\/\t\t\tminute at the end of the function.\r\n\r\nvoid TickTockShield::getTime()\r\n{\r\n    \/\/ Reset the register pointer\r\n\tWire.beginTransmission(DS1307_I2C_ADDRESS);\r\n\tWire.write((byte)0x00);\r\n\tWire.endTransmission();  \r\n\tWire.requestFrom(DS1307_I2C_ADDRESS, 7);\r\n\t\/\/ A few of these need masks because certain bits are control bits\r\n\tg_second\t   = bcdToDec(Wire.read() &amp; 0x7f);\r\n\tg_minute\t   = bcdToDec(Wire.read());\r\n\tg_hour\t     = bcdToDec(Wire.read() &amp; 0x3f);\/\/ Need to change this if 12 hour am\/pm\r\n\tg_dayOfWeek  = bcdToDec(Wire.read());\r\n\tg_dayOfMonth = bcdToDec(Wire.read());\r\n\tg_month      = bcdToDec(Wire.read());\r\n\tg_year\t     = bcdToDec(Wire.read());\r\n}\r\nvoid TickTockShield::displayTime()\r\n{\r\n  unsigned char time[4];\r\n  time[0] = g_hour\/10;\r\n  time[1] = g_hour%10;\r\n  time[2] = g_minute\/10;\r\n  time[3] = g_minute%10;\r\n  tm1636.display((int8_t*)time);\r\n}\r\nvoid TickTockShield::displayDate()\r\n{\r\n    unsigned char time[4];\r\n    time[0] = g_dayOfMonth\/10;\r\n    time[1] = g_dayOfMonth%10;\r\n    time[2] = g_month\/10;\r\n    time[3] = g_month%10;\r\n    tm1636.display((int8_t*)time); \/\/added by Johannes\r\n}\r\n\r\nvoid TickTockShield::display(int8_t DispData [])\r\n{\r\n\ttm1636.display(DispData);\r\n}\r\n\r\nvoid TickTockShield::clearTime(uint8_t hand)\r\n{\r\n\tunsigned char time[4];\r\n\tif(hand == HOUR)\r\n\t{\r\n\t\ttime[0] = INDEX_BLANK;\r\n  \ttime[1] = INDEX_BLANK;\r\n  \ttime[2] = g_minute\/10;\r\n  \ttime[3] = g_minute%10;\r\n\t}\r\n\telse \r\n\t{\r\n\t\ttime[0] = g_hour\/10;\r\n\t  time[1] = g_hour%10;\r\n\t  time[2] = INDEX_BLANK;\r\n\t  time[3] = INDEX_BLANK;\r\n\t}\r\n\ttm1636.display((int8_t*)time);\r\n}\r\n\/\/ Convert normal decimal numbers to binary coded decimal\r\nbyte TickTockShield::decToBcd(byte val)\r\n{\r\n\treturn ( (val\/10*16) + (val%10) );\r\n}\r\n\r\n\/\/ Convert binary coded decimal to normal decimal numbers\r\nbyte TickTockShield::bcdToDec(byte val)\r\n{\r\n\treturn ( (val\/16*10) + (val%16) );\r\n}\r\n\r\nboolean TickTockShield::isAdjustingTime()\r\n{\r\n\tif(flag_adjust_time)return true;\r\n\telse return false;\r\n}\r\n\/\/\/ --------------------------\r\n\/\/\/ Custom ISR Timer Routine\r\n\/\/\/ --------------------------\r\nvoid timerIsr()\r\n{\r\n\talarm_on_off = (~alarm_on_off) &amp; 0x01;\r\n  if(key_menu_status == KEY_PRESSED)\r\n \t{\r\n \t\tcount_10ms_pressed ++;\r\n\t\tif(count_10ms_pressed == 30)\r\n\t\t{\r\n\t\t\tflag_pressed_3s = 1;\r\n\t\t\tkey_menu_status = 0;\r\n\t\t}\r\n \t}\r\n\telse if(key_menu_status == KEY_RELEASE)\r\n\t{\r\n\t\tcount_10ms_release ++;\r\n\t\tif(count_10ms_release == 100)\r\n\t\t{\r\n\t\t\tflag_release_10s = 1;\r\n\t\t\tkey_menu_status = 0;\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-437\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/eiseler.de\/wordpress\/?p=437&amp;share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\"><span>Facebook<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-437\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/eiseler.de\/wordpress\/?p=437&amp;share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-437\" class=\"share-linkedin sd-button share-icon\" href=\"http:\/\/eiseler.de\/wordpress\/?p=437&amp;share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\"><span>LinkedIn<\/span><\/a><\/li><li class=\"share-pocket\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-pocket sd-button share-icon\" href=\"http:\/\/eiseler.de\/wordpress\/?p=437&amp;share=pocket\" target=\"_blank\" title=\"Click to share on Pocket\"><span>Pocket<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Giving the Tick Tock Shield Kit by Grove a try, I made same changes to the real time clock code. First I wanted to automaticaly change the brightness not only at the start of the code. And second I wanted &hellip; <a href=\"http:\/\/eiseler.de\/wordpress\/?p=437\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-437\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/eiseler.de\/wordpress\/?p=437&amp;share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\"><span>Facebook<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-437\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/eiseler.de\/wordpress\/?p=437&amp;share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-437\" class=\"share-linkedin sd-button share-icon\" href=\"http:\/\/eiseler.de\/wordpress\/?p=437&amp;share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\"><span>LinkedIn<\/span><\/a><\/li><li class=\"share-pocket\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-pocket sd-button share-icon\" href=\"http:\/\/eiseler.de\/wordpress\/?p=437&amp;share=pocket\" target=\"_blank\" title=\"Click to share on Pocket\"><span>Pocket<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[6],"tags":[],"class_list":["post-437","post","type-post","status-publish","format-standard","hentry","category-arduino"],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8zAuQ-73","jetpack-related-posts":[{"id":432,"url":"http:\/\/eiseler.de\/wordpress\/?p=432","url_meta":{"origin":437,"position":0},"title":"Just a short test of the Grove I2C Color Sensor","date":"03\/11\/2013","format":false,"excerpt":"Just made a short test of the grove color sensor. Tested some Lego. Red, green and blue works well as you can see, but didn't manage to measure the difference between red, orange and yellow. Here is the short movie: http:\/\/www.youtube.com\/watch?v=wJNKoKqLqFA And here the source: \/* Groove Color Sensor and\u2026","rel":"","context":"In &quot;Arduino&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/img.youtube.com\/vi\/wJNKoKqLqFA\/0.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1036,"url":"http:\/\/eiseler.de\/wordpress\/?p=1036","url_meta":{"origin":437,"position":1},"title":"Connect Raspberry Pi & Arduino USB bidirectional","date":"25\/10\/2018","format":false,"excerpt":"How to connect an Arduino to a raspberry pi via USB bidirectional. The raspberry reads all from the serial and prints it. Next it reads a textile from a webpage and sends the text (one word) to serial, next a random car to the Arduino. Arduino got a LCD attached\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":340,"url":"http:\/\/eiseler.de\/wordpress\/?p=340","url_meta":{"origin":437,"position":2},"title":"Easy Arduino LED Clock","date":"31\/03\/2013","format":false,"excerpt":"How to build an easy arduino clock. Why building a clock, since one can buy all kind of clocks? Two causes, first for the fun of it and second I can build the functions as I like and how they work. I also plan to add more functions from time\u2026","rel":"","context":"In &quot;Arduino&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/eiseler.de\/wordpress\/wp-content\/uploads\/2013\/03\/IMG_4312-Kopie-300x257.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":726,"url":"http:\/\/eiseler.de\/wordpress\/?p=726","url_meta":{"origin":437,"position":3},"title":"C51 4 Bits Electronic Clock from banggood, instructions","date":"25\/03\/2017","format":false,"excerpt":"The \"C51 4 Bits Electronic Clock Electronic Production Suite DIY Kit\" from banggood (link: link) is a nice kit and it is pretty forward to assemble it. Just follow the printing on the board. Only thing I did wrong was the resistance cascade. Watch for it, it is important to\u2026","rel":"","context":"In &quot;Tipps &amp; Tricks&quot;","img":{"alt_text":"","src":"https:\/\/i1.wp.com\/eiseler.de\/wordpress\/wp-content\/uploads\/2017\/03\/IMG_2070-300x234.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":10,"url":"http:\/\/eiseler.de\/wordpress\/?p=10","url_meta":{"origin":437,"position":4},"title":"iLOE quo vadis?","date":"17\/10\/2012","format":false,"excerpt":"As people ask for feature requests for iLOE, I thaught it might be a good idea to write a few words about the road map. By now there are so many changes in xcode and in a lot of libraries, that it would take a very long time just to\u2026","rel":"","context":"In &quot;iOS App&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":473,"url":"http:\/\/eiseler.de\/wordpress\/?p=473","url_meta":{"origin":437,"position":5},"title":"X-MAS Special - Was ein Geek alles braucht","date":"04\/12\/2013","format":false,"excerpt":"X-MAS Special - Was ein Geek alles braucht Weihnachten steht vor der T\u00fcr, deshalb heute ein Special was ein geek unbedingt braucht: PC, Smartphone und Pad: Laufen als Grundausstattung, deshalb keine Deatillierung hier. NAS (Network Attached Server):\u00a0 Mit minimalen Stromverbrauch und einfacher Bedienung kann das mittlerweile (fast) jeder bedienen. Geliefert\u2026","rel":"","context":"In &quot;Arduino&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/eiseler.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=437"}],"version-history":[{"count":4,"href":"http:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/437\/revisions"}],"predecessor-version":[{"id":441,"href":"http:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/437\/revisions\/441"}],"wp:attachment":[{"href":"http:\/\/eiseler.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/eiseler.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=437"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/eiseler.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}