User Tools

Site Tools


arduino:art-clockbell

This is an old revision of the document!


Arduino Art - Town Hall Bell clock - Real Time clock with LCD display and Bell functionality

Introduction

The scope of this project was to mimic the functionality of a Church or Town Hall Bell, which sounds on the hour with a number of “gongs” equal to the hour and with one “gong” on the half hour .

The project was originally intended for a “live sculpture”, which the project sponsor, a construction artist, wanted to present at an art exhibition. In that sense, the LCD display would remain out of sight and only a signal would be created that would drive the bell actuator, a solenoid electromagnet which would hit a bell. The reason for mentioning this, is because the clock does not have the full functionality that would normally be expected, but is rather generic. The focus of the project was on the ringing part, so the elementary clock functionality was not considered an issue at the time.

On the other hand, the programming methods for creating pulses with duration of several seconds, far beyond the period of a normal Arduino loop, may be found useful by the community. That was the main reason for deciding to publish this article.

A picture of the prototype is shown below.

Arduino Art - Clock Bell board

Components

  • Arduino nano. My favorite arduino for small-scale controller projects
  • Power supply. A low cost 5V socket power supply from hobby electronics or a mobile phone charger, capable of feeding 2A. In case of a USB phone charger, you may need to cut the cable and replace the micro-USB socket with a male 5.5×2.1 mm barrel connector
  • 16×2 LCD display QC1602A, based on the HD44780 chip
  • PCF8574A. An I2C extender chip
  • Real Time Clock (RTC) module with integrated battery, based on DS3231 or the older, lower precision DS1307
  • Various electronic components mentioned in the Schematic

Arduino Libraries and other software

LiquidCrystal I2C version 1.2 Author Frank de Brabander Maintainer Marco Schwartz Website https://github.com/marcoschwartz/LiquidCrystal_I2C which I downloaded from https://www.arduinolibraries.info/libraries/liquid-crystal-i2-c

RTClib by NeiroN by JeeLabs (http://news.jeelabs.org/code/), neiroN (neiron.nxn@gmail.com) Version 1.5.4. The library supports both DS3231 and DS1307. Select the appropriate in the code.

For presenting custom characters to the LCD, I used the designs from https://lastminuteengineers.com/arduino-1602-character-lcd-tutorial/

You shall also need the RTC library MD_DS3231 by majicDesigns Version 1.2.0 for another sketch that I use to set the initial time of the real-time clock.

Schematic

Arduino Art - Bell Clock - Schematic

Handmade schematic? See why..

The Arduino Nano is connected via the I2C bus to the RTC and the PCF8574A. The PCF8574A chip demultiplexes the I2C signals and controls the 7 pins required by the LCD (D4-D7, RS, RW and E). The chip is installed below the LCD display with the purpose of keeping short the wiring between its pins and the display socket pins.

The potentiometer controls the LCD contrast. Set it to a value that provides a balance between the maximum brightness of the characters, without having the pixel background show that much.

The NPN transistor BC337 is driven by Arduino Nano pin D7 and controls a relay. This relay will drive the actuator which rings the bell.

Three micro-switches are connected to Arduino pins D4, D5 and D6. They are used for correcting the time, after it has shifted significantly from the correct time. These switches are marked H, M and S and correct hours, minutes and seconds respectively.

One header pin wired to GND and D3 serves for the wiring of an external “night-mode” switch. Details on its operation are presented below.

A peculiar circuit is built around a PNP transistor BC557C. One would immediately notice that the transistor is redundant because it always allows the flow of current without exercising any control. This is true. The reason for the existence of this circuit block is because for this project I used an existing prototype board that I have built for another project, a few months before. In that project, I was using a different library for driving the display which was also called LiquidCrystal_I2C, but it was using the pins of PCF8574A in a different manner. The wiring was similar to the one used by library LiquidCrystal_PCF8574 by Mattias Hertel http://www.mathertel.de/Arduino/LiquidCrystal_PCF8574.aspx. Pins RS, RW and E of the LCD were wired to pins P6, P5 and P4 of PCF8574A and the data pins D4, D5, D6, D7 of the LCD were wired to pins P0, P1, P2 and P3 of PCF8574A. Additionally, the LCD backlight was driven by pin P7, with a negative logic. This means that when the library wanted to activate the LCD backlight, it sent 0 to P7. The LiquidCrystal_I2C library that I am using in this project instead, activates pin P3 for backlighting, probably with a positive logic. In this new project, the display is supposed to be always on, so I did not bother to spend time on this issue and connected one end of the 4.7K resistor to ground, as a minimal immediate fix that would not disturb the existing circuit too much. Who knows, I may re-use it in the future!

Unfortunately, the old library was lost when the hard disk crashed and it was not possible to recover it. I tried several libraries that I could find on the internet but perhaps there were differences in the software that also did not work with my LCD. I guess these are problems happening when one uses unofficial Arduino libraries! I finally end up with the library of Frank de Brabander, which required rewiring of several pins, as it is shown on the schematic.

Going back to hardware issues, please note that backlighting of the LCD is performed by internal diodes, whose operating current should be less than 25mA according to the manufacturer specification. My testing showed that 5mA were enough for proper lighting. Pin A is the Anode and pin K the cathode. Note that these pins must be driven by current - not voltage. The Vf between A and K is approx. 3V, so to keep the current at a reasonable value of 5mA, we need a series resistor of (5-3)/0,005 =~ 390 Ohms. The 1N4148 in the schematic is also redundant.

To cut a long story short, if I built the circuit again, I would use a single 390 or 330 Ohm resistor from +5V to pin A of the LCD. Even better, I would buy an LCD display with a piggyback PCF8574 module, such as this or this, at almost the same price as a regular LCD and save all the wiring effort. Just set the module address, wire four pins and that's about it. Another option would be to buy an OLED module such as this. These modules are beautiful but their libraries occupy a large amount of the limited arduino RAM, leaving too little for our code. Anyway, the project sponsor liked better the old-fashioned LCD, so the issue was immediately solved.

The relay is used to drive the bell actuator. When I started the project, the sponsor have not yet decided on the bell and the associated type of actuator, so I installed an 8A/250V contact relay activated by a 5V coil. Should I have the specs of the actuator beforehand, I would design using transistors or MOSFETs. Yet the relay provides a more generic solution.

One barrel 5.5×2.1 mm connector for the PCB and alternatively a block connector are used for providing power to the board. Note that 5.5 mm refers to the outer diameter (OD) of the plug and 2.1mm to the inside diameter (ID). There are also in the market 5.5×2.5 mm. Match the socket with the plug so that they are of same specifications.

A 1N5819 schottky diode is used to allow us to program the Arduino nano via the USB cable while the circuit is powered at the same time by the power supply. I cover this issue in detail in another post.

The Arduino Nano, the RTC module and the LCD display module are not soldered directly on the board. I am using socket pins, like the ones shown at the top of the picture (those are not used in this circuit). I then insert the module header pins into the main board socket pins. Sometimes, in case the module arrives with the pins soldered on the “wrong”side of the board, I may have to de-solder them very carefully, trying to avoid damage to the PCB. The de-soldered pins are thrown away, the board holes are opened with a small drill bit and finally, new header pins are soldered at the proper side of the module board.

Software

The most notable thing in the code is the measure of time. Several issues that caused drifting were discovered using an oscilloscope and the code was developed in order to ensure precise timing.

When the time is exactly on the hour, the system produces a number of “hour” pulses. Especially for hours after 12 (p.m for USA), 12 is subtracted from the 24hour number. So at 13:00 the bell sounds once, at 14:00 the bells sound twice, etc.

The value of TIME_BELL_ON defines the time the relay will be at the ON state. Because we want to send a short pulse to the actuator, such as a mini solenoid electromagnet, 300 milliseconds are OK. The value of TIME_BELL_ON is multiplied by 100 to produce the number of milliseconds.

The value of TIME_BELL_OFF defines the time the relay will be at the ON state. We want the bell to reverberate for a while, so the value of 30 produces 3000 milliseconds which is 3 seconds.

  Example for ringing  hour 02:00:00 and 14:00:00 (num_bells = 2)
        ______________            ______________
        I            I            I            I
        I            I            I            I
  ______I            I____________I            I____________
  
         <--bell_on--><---bell_off-><--bell_on--><--bell_off->
        <------------------ ring_on = true ----------------->

The Real Time Clock module synchronizes time every minute. The synchronization takes place 10 seconds before completing a minute. I selected 10 seconds before because usually programmed events take place exactly on the hour and I wished to avoid several things happenning at the same time.

One safety feature is that, if the clock has sounded the hour and for some reason the synchronization sets the time back, the same hour will not sound again.

Finally, the Night Mode keeps the device silent after hours. This means that if Night Mode is active, the bell will sound only at normal working hours. Night Mode is the default mode, provided that the pin headers are not wired together. The silent hours are defined in array silent_hours[].

A copy of the code is shown at the end of this document. I will try to post same on Github when I find the time

Operation

Install a CR2032 coin battery into the RTC socket.

When powering the device for the first time, the RTC will have an undefined date and time. Load any example sketch that will allow you to set it manually. I used the one provided with the MD_3231 library. Most important is to set the date, because we will not be able to correct it via the switches.

Of course, it will not be possible to set the exact time with this method. You will definitely be off, at least by a few seconds.

After setting the RTC, load the sketch of the project. The date will appear at the first line and the time at the second line. You can now fix the time precisely using the switches.

Here is how the switches operate:

  • The Hour and Minute switches increase the value of hour and minute respectively by one.
  • When the Seconds switch is pressed, the seconds value is reset to zero.
  • When the two pins of the Night Mode header are not wired together, Night Mode will be active. A Lock symbol appears in the far right column of the first line of the display. The bell will not sound at silent hours.

When the two pins of Night Mode are wired together, Night Mode is deactivated. A bell symbol appears in the far right column of the first line of the display to signify that the bell will sound each and every hour during day and night.

The last column of the second line of the LCD presents a music note symbol if the current hour is non-silent. No symbol appears for silent hours.

Ideas for future enhancements

  1. Implement Daylight Saving
  2. Modify switch operation so that both date and time can be adjusted. Better debouncing is required. Three switches will suffice, one for item (year-month-day-hour-min-sec) selection and two for Up and Down. The selected item should blink.

Conclusion

Although at first the concept appeared easy - a simple clock and something to do on the hour - it proved to be a detailed work, needing to examine several Arduino features regarding the handling of timer functions and timer interrupts, as well as the system behaviour during the loops. Minor time drifts would add up and cause significant variations over time. Several solutions were examined originally, even the use of two arduinos, one to handle time and the second to handle ringing. Another solution was to implement custom hardware for ringing.

Yet, since the whole project involved the notion of “time”, enough time was invested to implement it with the most simple architecture.

Finally, after lots of testing and debugging, the prototype was ready to be delivered to the project sponsor and subsequently to the open source community.

Have fun!

If you have any feedback, please contact me via this contact form

Source Code

arduino_art_clock_bell.ino
/*
 * 10/9/2017 = 27/9/2019
 * CLOCK BELL project
 * 
 * Maintains time, synchronized with a Real Time Clock (RTC) and 
 * rings a bell on the hour and on half hours
 * 
 * Modification so that triggered events may last not seconds but deci seconds
 * 
 * Example for ringing  hour 02:00:00 and 14:00:00 (num_bells = 2)
 *       ______________            ______________
 *       I            I            I            I
 *       I            I            I            I
 * ______I            I____________I            I____________
 * 
 *       <--bell_on--><---bell_off-><--bell_on--><--bell_off->
 *       <------------------ ring_on = true ----------------->
 *       
 *  Daylight Saving DST is still not supported     
 *       
 *  To display characters on the LCD display I use the libary     
 *  LiquidCrystal I2C version 1.2 Author Frank de Brabander
 *  Maintainer Marco Schwartz Websitehttps://github.com/marcoschwartz/LiquidCrystal_I2C
 *  which I downloaded from https://www.arduinolibraries.info/libraries/liquid-crystal-i2-c     
 *  WARNING: This library uses the pins of the PCF8574 driver differently than other libraries 
 *  I have used in the past. I had to modify my wiring between PCF8574 and the LCD display. 
 *  Currently, you can buy LCD displays which include a PCF8574 module at almost the same 
 *  price as the LCD itself. Prefer this to save a lot of wiring. If the library does not work
 *  properly, try the library LiquidCrystal_PCF8574 by Mattias Hertel
 *       http://www.mathertel.de/Arduino/LiquidCrystal_PCF8574.aspx
 *       
 *      
 *  27/2/2019 Added NightMode, meaning that if active, the bell will not ring     
 *  on late night hours (actually on selected hours, but NightMode was a catchy phrase!!).
 *  
 *  When the last character of the first line shows a Lock symbol, this means that 
 *  clock is in silent mode and will not ring on silent hours.
 *  If the bell character is shown, the bell will sound for all hours
 *  
 *  When the last character of the second line shows a music/note symbol
 *  this means that this is not a silent hour. If it is blank, it is a silent hour.
 *  
 *  
 */
 
// To use an I2C LCD 2 lines by 16 columns, at I2C address 0x38 
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
 
#define LCD_ADDRESS 0x38
 
#include "RTClib.h"  //RTClib by NeiroN
//DS1307 rtc;
DS3231 rtc;
 
DateTime now;
 
#define LED_PIN  LED_BUILTIN // LED that flashes every sec. If you want to  use another pin rather than the built-in led, set it here
#define BELL_PIN 7          // Output that controls the bell
#define BELL_HALF_PIN 7     // Output that controls the half hour bell. Can be same as hour pin
 
 
// Input switches
#define SET_HOURS_PIN 6      // Pressing the button increases hours by one
#define SET_MINUTES_PIN 5    // Pressing the button once increases minutes by one
#define SET_SECONDS_PIN 4   // Pressing the button once sets seconds to zero
 
// The name NIGHT_MODE_PIN was probably taken by some library and caused error
// Had to name it NIGHT_PIN
#define NIGHT_PIN 3  // If set to LOW, by connecting the two pin headers, night mode will be inactive
 
#define DEBOUNCING_TIME 2    // Debouncing time for reading switches in msec
 
#define CLOCK_CORRECTION 0  // msec If crystal gains or lags, we can fix the clock making it run faster (negative value) or slower (positive value)
 
/*
 * One ring is composed of several bells.
 * Each bell has a bell_on time of duration SEC_BELL_ON (in sec)
 * and a bell_off time of duration SEC_BELL_OFF (in sec)
 * 
 */
#define TIME_BELL_ON 3  // times 100 milliseconds. The max achieved time is 25,5 sec for a value of 255
#define TIME_BELL_OFF 30  // times 100 milliseconds. The max achieved time is 25,5 sec for a value of 255                         
 
// Define the silent hours, i.e. those that the bell will not ring
int silent_hours[] = { 20, 21, 22, 23, 0, 1, 2, 3, 4, 5, 6, 7 };
 
// Definition of a custom bell, speaker and sound images
// from https://lastminuteengineers.com/arduino-1602-character-lcd-tutorial/
byte Bell[8] = {
0b00100,
0b01110,
0b01110,
0b01110,
0b11111,
0b00000,
0b00100,
0b00000
};
 
byte Speaker[8] = {
0b00001,
0b00011,
0b01111,
0b01111,
0b01111,
0b00011,
0b00001,
0b00000
};
 
 
byte Sound[8] = {
0b00001,
0b00011,
0b00101,
0b01001,
0b01001,
0b01011,
0b11011,
0b11000
};
 
byte Lock[8] = {
0b01110,
0b10001,
0b10001,
0b11111,
0b11011,
0b11011,
0b11111,
0b00000
};
 
// Volatile variables because they can be used in the interrupt service routine
 
// Declares the time variables and set to initial value. 
volatile int hours = 00; 
volatile int minutes = 00;
volatile int seconds = 05;  
volatile int deci_seconds = 00;
 
// In order to set the RTC, I need those
volatile int myyear;
volatile int mymonth;
volatile int myday;
 
volatile unsigned long current_time;
volatile unsigned long previous_time = millis();
volatile unsigned long deci_previous_time = millis();
 
// Variables to represent the timing of each hit of the hammer to the bell
// Values are in seconds
volatile int t_bell_on = 0;
volatile int t_bell_off = 0;
 
// Boolean to monitor if a ringing process (several bells) is active
boolean ring_on = false;
 
// Indicates that ringing is taking place for the half hour
// Used only to select the bell pin
boolean ring_30min = false;
 
boolean bell_on = false; // Indicates that we are at the HIGH period of the bell pulse
boolean bell_off = false;// Indicates that we are at the LOW period of the bell pulse
 
int num_bells = 0;
 
int correction = CLOCK_CORRECTION;
int interval = 100 + correction;
 
boolean night_mode = true; // Indicates if night mode is set, by reading the input pin
 
LiquidCrystal_I2C lcd(LCD_ADDRESS,16,2);  
 
void setup()
{
 
 
  lcd.init();
  lcd.backlight();
 
  pinMode(LED_PIN, OUTPUT);
  pinMode(BELL_PIN, OUTPUT);
  digitalWrite(BELL_PIN, LOW);
  pinMode(BELL_HALF_PIN, OUTPUT);
  digitalWrite(BELL_HALF_PIN, LOW);  
 
  pinMode(SET_HOURS_PIN, INPUT_PULLUP);
  pinMode(SET_MINUTES_PIN, INPUT_PULLUP);
  pinMode(SET_SECONDS_PIN, INPUT_PULLUP);
 
  pinMode(NIGHT_PIN, INPUT_PULLUP);
 
  lcd.createChar(0, Bell);
  lcd.createChar(1, Speaker);
  lcd.createChar(2, Sound);
  lcd.createChar(3, Lock);
 
  sync_from_RTC();
 
  Serial.begin(9600);
 
}
 
// Runs every interval (100msec = 1ds)
void every_interval()      
{ 
  // Handle the bell timing
  // Decrement all bell timers. We do not care if they are active or not
  if (t_bell_on > 0)
    t_bell_on --;
 
  if (t_bell_off > 0)
    t_bell_off --;  
 
  deci_seconds ++;
  if (deci_seconds >= 10) {   
    deci_seconds = 0;       
    every_second();     
  }   
  return;
}
 
 
void every_second()
{
    seconds ++;        
    if (seconds >= 60) { 
      seconds = 0;    
      minutes ++;           
      if (minutes >= 60) {
        minutes = 0;
        hours ++;       
        if (hours >= 24) {
          hours = 0;
        }
      }   
    } 
   //  IT IS WRONG TO PLACE HERE show_time_on_lcd(); . IT DISTURBS TIMING
   //  IT STEELS TIME (approx 4msec) FROM TIME_BELL_ON
   //  LCD handling must be placed in loop2()       
}
 
 
// Presents the time on the LCD
void show_time_on_lcd()
{
 
  // print date on line 1 of LCD
  lcd.setCursor(2,0);
  if (myday < 10)
    lcd.print("0");  
  lcd.print(myday);
  lcd.print(".");
  if (mymonth < 10);
    lcd.print("0");
  lcd.print(mymonth);
  lcd.print(".");
  lcd.print(myyear);
 
  // print hour on line 2 of LCD   
  lcd.setCursor(3,1);
  if (hours < 10)
    lcd.print("0");
  lcd.print(hours);
  lcd.print(":");
  if (minutes < 10)
    lcd.print("0");
  lcd.print(minutes);
  lcd.print(":");
  if (seconds < 10)
    lcd.print("0");
  lcd.print(seconds); 
 
  // Prints an indication for Night Mode
  lcd.setCursor(15,0);
  if (night_mode)
    lcd.write(byte(3)); // Lock symbol
  else
    lcd.write(byte(0));  // Bell symbol
 
  // Prints an indication if the hour is in the list of silent hours
  lcd.setCursor(15,1);
  if (silent_hour(hours))
    lcd.print(" ");  
  else
    lcd.write(byte(2));   // Sound symbol 
 
  return; 
}
 
/*
 * Do not use loop() for user code, because it handles timing.
 * Use loop2() instead
 */
void loop()
{
  current_time = millis();
  if (current_time - previous_time >= interval) {
    every_interval(); 
    previous_time = current_time;  
  }
 
  // do the normal work
  loop2();   
}
 
 
 
// User code goes here
void loop2()
{
  // Synchronize with RTC every minute at xx:50:00:00
  // Close to the end of the minute to avoid interacting with 
  // actions that normally occur at xx:00:00:00
  if (seconds == 50 && deci_seconds == 0) {
    sync_from_RTC();
 
  }
 
  if (ring_on)
    process_ringing();
  else {
    if (seconds == 0  && deci_seconds == 0) {
      // Addition for night mode 
      if (minutes == 0)
         if (!night_mode)
           ring(hours);
         else  if (!silent_hour(hours))
            ring(hours);
         else {
            // be silent             
         }
 
      else {
        if (minutes == 30)
          if (!night_mode)
            ring_half();
          else  if (!silent_hour(hours))
            ring_half();
         else {
            // be silent             
         } 
 
      }     
    }        
  }
 
  // LCD handling
  static int previous_seconds;
  if (seconds != previous_seconds) {
    show_time_on_lcd();
    previous_seconds = seconds;
  }
 
  // Set time manually via switches
  read_switches();
 
  return;
}
 
void read_switches() 
{
  if (digitalRead(SET_HOURS_PIN) == LOW) {
    delay(DEBOUNCING_TIME);
    if (digitalRead(SET_HOURS_PIN) == LOW) {
      hours = (hours + 1) % 24;
    }
    while (digitalRead(SET_HOURS_PIN) == LOW){ 
    }
    set_RTC();
  }  
 
  if (digitalRead(SET_MINUTES_PIN) == LOW) {
    delay(DEBOUNCING_TIME);
    if (digitalRead(SET_MINUTES_PIN) == LOW) {
      minutes = (minutes + 1) % 60;
    }  
    while (digitalRead(SET_MINUTES_PIN) == LOW) {  
    }
    set_RTC();
  }  
 
  if (digitalRead(SET_SECONDS_PIN) == LOW) {
    delay(DEBOUNCING_TIME);
    if (digitalRead(SET_SECONDS_PIN) == LOW) {
      seconds = 00; 
      deci_seconds = 0; 
    }  
    while (digitalRead(SET_SECONDS_PIN) == LOW) {  
    }
    set_RTC();
  } 
 
  if (digitalRead(NIGHT_PIN) == LOW) {
     night_mode = false; // Headers are connected, bells ring all round the clock    
  } else {
    night_mode = true;
  }
  return;   
}
 
void set_RTC()
{
 
  rtc.adjust(DateTime(myyear, mymonth, myday, hours, minutes, seconds));
  return;
}
 
void start_bell()
{
  int bell_pin;
  if (ring_30min)
    bell_pin = BELL_HALF_PIN;
  else
    bell_pin = BELL_PIN;  
  digitalWrite(bell_pin, HIGH);
  digitalWrite(LED_PIN, HIGH);
  bell_on = true;
  bell_off = false;
  t_bell_on = TIME_BELL_ON; 
  return;
}
 
void stop_bell()
{
  int bell_pin;
  if (ring_30min)
    bell_pin = BELL_HALF_PIN;
  else
    bell_pin = BELL_PIN;  
  digitalWrite(bell_pin, LOW);
  digitalWrite(LED_PIN, LOW);
  bell_on = false;
  bell_off = true;
  t_bell_off = TIME_BELL_OFF; 
  return;
}
 
/* Rings the bell, depending on the hour provided.
   The hours variable works on the 24 hour format
   but we want to ring the bell as per the 12 hour
 
   Skips ringing if previous hours is same.
   This condition may happen if we have a ring and after some time,
   the RTC synchronizes the internal clock and we go back to xx:00:00
   This functionality is only for full hours. Half hours and 01:00:00 are 
   totally separated
 
*/ 
void ring(int num_hours)
{
  static int previous_hours = 0;
 
  // protect from setting back hours via switches or sync with RTC
  if (num_hours == previous_hours) 
    return;
 
  previous_hours = num_hours;  
  ring_on = true;
  if (num_hours > 12)
    num_bells = num_hours - 12;
  else if (num_hours == 0) 
    num_bells = 12;
  else  
    num_bells = num_hours;
  start_bell();  
  return;  
}
 
// Ring at half hour
void ring_half()
{
  // Is there a way to protect from syncing back to xx:30:00 ????
 
  ring_30min = true; 
  ring_on = true;
  num_bells = 1;
  start_bell();
  return;
}
 
void process_ringing()
{
  if (bell_on && t_bell_on <= 0)
    stop_bell();
 
  if (bell_off && t_bell_off <= 0) {
    num_bells --;
    if (num_bells > 0)
      start_bell();
    else {
      bell_off = false;
      ring_on = false; 
      ring_30min = false;   
    }
  }
  return;
}
 
void send_time_to_serial()
{
  Serial.print("Time: "); 
  if (hours , 10)
    Serial.print("0");
  Serial.print(hours);
  Serial.print(":");
  if (minutes < 10)
    Serial.print("0");
  Serial.print(minutes);
  Serial.print(":");
  if (seconds < 10)
    Serial.print("0");
  Serial.println(seconds);  
}
 
// Presents variables on LCD for debugging
void show_state_on_lcd()
{
  // Clear line 1
  lcd.setCursor(0,1);
  lcd.print("                ");
 
  lcd.setCursor(0,1);
  lcd.print("R:");
    if (ring_on) {
      lcd.print("ON");
      lcd.print(" B=");
      lcd.print(num_bells);
      lcd.print(" TB=");
      lcd.print(t_bell_on);
      lcd.print(" TBO=");
      lcd.print(t_bell_off);      
 
    }  
    else
      lcd.print("OFF");
 
 
}
 
void sync_from_RTC()
{
  now = rtc.now();
 
  myyear = now.year();
  mymonth = now.month();
  myday = now.day();
  hours = now.hour();
  minutes = now.minute();
  seconds = now.second();  
}
 
// checks if an int value is included in an array of ints
boolean in_int_array(int value, const int *arr, int num_elements) {
 
  for (int i=0; i< num_elements ; ++i ) {
    if (value == arr[i])
      return true;       
  }
  return false;  
}
 
// check if a given hour is silent
boolean silent_hour(int this_hour) {
 
  if (in_int_array(this_hour, silent_hours, sizeof(silent_hours)/sizeof(int)))
    return true;
  else
    return false;  
}
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
arduino/art-clockbell.1552657337.txt.gz · Last modified: 2019/03/15 15:42 by Ilias Iliopoulos