setBrightness ???

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
JackyNiew
 
Posts: 33
Joined: Wed Jun 04, 2014 9:34 am

setBrightness ???

Post by JackyNiew »

Hello,

In the following tutorial:
https://learn.adafruit.com/arduino-clock/software#
How to manage the brightness of the display 1.2 "LED 7 Adafruit segments.
I understand that it was not "setBrightness" but how and where to place this statement?
Thank you for your answers.

Jacky

User avatar
marke3
 
Posts: 205
Joined: Sat Feb 08, 2014 5:24 pm

Re: setBrightness ???

Post by marke3 »

I use setBrightness() and it seems to work fine. For that sketch put a clockDisplay.setBrightness(10) in the loop() somewhere before the writeDisplay() is called. 10 is just an example that seems to work well in daylight hours but the range is 0 to 15. I use 0 for night time in a bedroom clock as that display can really light up a room :).

User avatar
JackyNiew
 
Posts: 33
Joined: Wed Jun 04, 2014 9:34 am

Re: setBrightness ???

Post by JackyNiew »

Thank you for your reply, I will try to apply your advice, and I re-contact you if I fail to include this statement in the sketch.

Jacky

User avatar
JackyNiew
 
Posts: 33
Joined: Wed Jun 04, 2014 9:34 am

Re: setBrightness ???

Post by JackyNiew »

Hello Marke3,

I inserted "clockDisplay.setBrightness (5);" and it works perfectly. Thanks again.
Now I am looking for ways to improve the Sketch to have the time update, during the passage "Summer time" "Winter time".
If you with a solution to offer me this would be great, because after much research on this subject, I have found nothing.

Best regards,
Jacky

User avatar
marke3
 
Posts: 205
Joined: Sat Feb 08, 2014 5:24 pm

Re: setBrightness ???

Post by marke3 »

Glad it worked.

Summer time can be complicated. I'm lucky where I live because it changes on the 1st Sunday in October and the 1st Sunday in March. That's pretty easy to code. The first thing would be to find if there are simple rules where you live.

You also have to look at what your clock usage will be. If it's on all the time you can have a simple 'if' to check if it's the right time to change and if so, do it. However, you risk missing the change if your clock gets turned off.

Rules and usage can vary a lot and I suspect that's why it's hard to find anything definitive.

User avatar
JackyNiew
 
Posts: 33
Joined: Wed Jun 04, 2014 9:34 am

Re: setBrightness ???

Post by JackyNiew »

Thanks Marke3.

Here in France, it is last Sunday of March and last Sunday of October.
The clock is never turned off.
At the I will content myself with an update of the passage summer time, winter time even on a fixed date. This will avoid reloading the sketch with +1 and +2.

User avatar
JackyNiew
 
Posts: 33
Joined: Wed Jun 04, 2014 9:34 am

Re: setBrightness ???

Post by JackyNiew »

Hello,
Always looking to improve the 7 Adafruit GPS Clock.
I would like this clock (which works perfectly) to be updated during the summer / winter time.
Currently I use the following Sketch:

Code: Select all

// Clock example using a seven segment display & GPS for time.
//
// Must have the Adafruit GPS library installed too!  See:
//   https://github.com/adafruit/Adafruit-GPS-Library
//
// Designed specifically to work with the Adafruit LED 7-Segment backpacks
// and ultimate GPS breakout/shield:
// ----> http://www.adafruit.com/products/881
// ----> http://www.adafruit.com/products/880
// ----> http://www.adafruit.com/products/879
// ----> http://www.adafruit.com/products/878
// ----> http://www.adafruit.com/products/746
//
// Adafruit invests time and resources providing this open source code, 
// please support Adafruit and open-source hardware by purchasing 
// products from Adafruit!
//
// Written by Tony DiCola for Adafruit Industries.
// Released under a MIT license: https://opensource.org/licenses/MIT
#include <SoftwareSerial.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include "Adafruit_GPS.h"


// Set to false to display time in 12 hour format, or true to use 24 hour:
#define TIME_24_HOUR      true

// Offset the hours from UTC (universal time) to your local time by changing
// this value.  The GPS time will be in UTC so lookup the offset for your
// local time from a site like:
//   https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
// This value, -7, will set the time to UTC-7 or Pacific Standard Time during
// daylight savings time.
#define HOUR_OFFSET       +1

// I2C address of the display.  Stick with the default address of 0x70
// unless you've changed the address jumpers on the back of the display.
#define DISPLAY_ADDRESS   0x70


// Create display and GPS objects.  These are global variables that
// can be accessed from both the setup and loop function below.
Adafruit_7segment clockDisplay = Adafruit_7segment();
SoftwareSerial gpsSerial(8, 7);  // GPS breakout/shield will use a 
                                 // software serial connection with 
                                 // TX = pin 8 and RX = pin 7.
Adafruit_GPS gps(&gpsSerial);


void setup() {
  // Setup function runs once at startup to initialize the display and GPS.

  // Setup Serial port to print debug output.
  Serial.begin(115200);
  Serial.println("Clock starting!");

  // Setup the display.
  clockDisplay.begin(DISPLAY_ADDRESS);

  // Setup the GPS using a 9600 baud connection (the default for most
  // GPS modules).
  gps.begin(9600);

  // Configure GPS to onlu output minimum data (location, time, fix).
  gps.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);

  // Use a 1 hz, once a second, update rate.
  gps.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  
  // Enable the interrupt to parse GPS data.
  enableGPSInterrupt();
}

void loop() {
  // Loop function runs over and over again to implement the clock logic.

  // Check if GPS has new data and parse it.
  if (gps.newNMEAreceived()) {
    gps.parse(gps.lastNMEA());
  }
  
  // Grab the current hours, minutes, seconds from the GPS.
  // This will only be set once the GPS has a fix!  Make sure to add
  // a coin cell battery so the GPS will save the time between power-up/down.
  int hours = gps.hour + HOUR_OFFSET;  // Add hour offset to convert from UTC
                                       // to local time.
  // Handle when UTC + offset wraps around to a negative or > 23 value.
  if (hours < 0) {
    hours = 24+hours;
  }
  if (hours > 23) {
    hours = 24-hours;
  }
  int minutes = gps.minute;
  int seconds = gps.seconds;
  
  // Show the time on the display by turning it into a numeric
  // value, like 3:30 turns into 330, by multiplying the hour by
  // 100 and then adding the minutes.
  int displayValue = hours*100 + minutes;

  // Do 24 hour to 12 hour format conversion when required.
  if (!TIME_24_HOUR) {
    // Handle when hours are past 12 by subtracting 12 hours (1200 value).
    if (hours > 12) {
      displayValue -= 1200;
    }
    // Handle hour 0 (midnight) being shown as 12.
    else if (hours == 0) {
      displayValue += 1200;
    }
  }

  // Now print the time value to the display.
  clockDisplay.print(displayValue, DEC);

  // Add zero padding when in 24 hour mode and it's midnight.
  // In this case the print function above won't have leading 0's
  // which can look confusing.  Go in and explicitly add these zeros.
  if (TIME_24_HOUR && hours == 0) {
    // Pad hour 0.
    clockDisplay.writeDigitNum(1, 0);
  }
    // Also pad when the 10's minute is 0 and should be padded.
    if (minutes < 10) {
      clockDisplay.writeDigitNum(3, 0);
    }
   // Affichage du zéro pour les dizaines de l'heure si <10
    if (hours < 10) {
      clockDisplay.writeDigitNum(0, 0); 
  }

  // Blink the colon by turning it on every even second and off
  // every odd second.  The modulus operator is very handy here to
  // check if a value is even (modulus 2 equals 0) or odd (modulus 2
  // equals 1).
  clockDisplay.drawColon(seconds % 2 == 0);

  // Now push out to the display the new values that were set above.
  clockDisplay.writeDisplay();

  // Loop code is finished, it will jump back to the start of the loop
  // function again! Don't add any delays because the parsing needs to 
  // happen all the time!
}

SIGNAL(TIMER0_COMPA_vect) {
  // Use a timer interrupt once a millisecond to check for new GPS data.
  // This piggybacks on Arduino's internal clock timer for the millis()
  // function.
  gps.read();
}

void enableGPSInterrupt() {
  // Function to enable the timer interrupt that will parse GPS data.
  // Timer0 is already used for millis() - we'll just interrupt somewhere
  // in the middle and call the "Compare A" function above
  OCR0A = 0xAF;
  TIMSK0 |= _BV(OCIE0A);
}
To have the update of the summer / winter time, looking for I found, the Sketch "Timezone" of JChristensen:
https://github.com/JChristensen/Timezone
In the examples, I get the impression that the Sketch "WorldClock" would be very interesting.

Code: Select all

/*----------------------------------------------------------------------*
 * Timezone library example sketch.                                     *
 * Self-adjusting clock for multiple time zones.                        *
 * Jack Christensen Mar 2012                                            *
 *                                                                      *
 * Sources for DST rule information:                                    *
 * http://www.timeanddate.com/worldclock/                               *
 * http://home.tiscali.nl/~t876506/TZworld.html                         *
 *                                                                      *
 * This work is licensed under the Creative Commons Attribution-        *
 * ShareAlike 3.0 Unported License. To view a copy of this license,     *
 * visit http://creativecommons.org/licenses/by-sa/3.0/ or send a       *
 * letter to Creative Commons, 171 Second Street, Suite 300,            *
 * San Francisco, California, 94105, USA.                               *
 *----------------------------------------------------------------------*/

#include <Time.h>        //http://www.arduino.cc/playground/Code/Time
#include <Timezone.h>    //https://github.com/JChristensen/Timezone

//Australia Eastern Time Zone (Sydney, Melbourne)
TimeChangeRule aEDT = {"AEDT", First, Sun, Oct, 2, 660};    //UTC + 11 hours
TimeChangeRule aEST = {"AEST", First, Sun, Apr, 3, 600};    //UTC + 10 hours
Timezone ausET(aEDT, aEST);

//Central European Time (Frankfurt, Paris)
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120};     //Central European Summer Time
TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60};       //Central European Standard Time
Timezone CE(CEST, CET);

//United Kingdom (London, Belfast)
TimeChangeRule BST = {"BST", Last, Sun, Mar, 1, 60};        //British Summer Time
TimeChangeRule GMT = {"GMT", Last, Sun, Oct, 2, 0};         //Standard Time
Timezone UK(BST, GMT);

//US Eastern Time Zone (New York, Detroit)
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240};  //Eastern Daylight Time = UTC - 4 hours
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300};   //Eastern Standard Time = UTC - 5 hours
Timezone usET(usEDT, usEST);

//US Central Time Zone (Chicago, Houston)
TimeChangeRule usCDT = {"CDT", Second, dowSunday, Mar, 2, -300};
TimeChangeRule usCST = {"CST", First, dowSunday, Nov, 2, -360};
Timezone usCT(usCDT, usCST);

//US Mountain Time Zone (Denver, Salt Lake City)
TimeChangeRule usMDT = {"MDT", Second, dowSunday, Mar, 2, -360};
TimeChangeRule usMST = {"MST", First, dowSunday, Nov, 2, -420};
Timezone usMT(usMDT, usMST);

//Arizona is US Mountain Time Zone but does not use DST
Timezone usAZ(usMST, usMST);

//US Pacific Time Zone (Las Vegas, Los Angeles)
TimeChangeRule usPDT = {"PDT", Second, dowSunday, Mar, 2, -420};
TimeChangeRule usPST = {"PST", First, dowSunday, Nov, 2, -480};
Timezone usPT(usPDT, usPST);

TimeChangeRule *tcr;        //pointer to the time change rule, use to get the TZ abbrev
time_t utc;

void setup(void)
{
    Serial.begin(115200);
    setTime(usET.toUTC(compileTime()));
}

void loop(void)
{
    Serial.println();
    utc = now();
    printTime(ausET.toLocal(utc, &tcr), tcr -> abbrev, "Sydney");
    printTime(CE.toLocal(utc, &tcr), tcr -> abbrev, "Paris");
    printTime(UK.toLocal(utc, &tcr), tcr -> abbrev, " London");
    printTime(utc, "UTC", " Universal Coordinated Time");
    printTime(usET.toLocal(utc, &tcr), tcr -> abbrev, " New York");
    printTime(usCT.toLocal(utc, &tcr), tcr -> abbrev, " Chicago");
    printTime(usMT.toLocal(utc, &tcr), tcr -> abbrev, " Denver");
    printTime(usAZ.toLocal(utc, &tcr), tcr -> abbrev, " Phoenix");
    printTime(usPT.toLocal(utc, &tcr), tcr -> abbrev, " Los Angeles");
    delay(10000);
}

//Function to return the compile date and time as a time_t value
time_t compileTime(void)
{
#define FUDGE 25        //fudge factor to allow for compile time (seconds, YMMV)

    char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
    char chMon[3], *m;
    int d, y;
    tmElements_t tm;
    time_t t;

    strncpy(chMon, compDate, 3);
    chMon[3] = '\0';
    m = strstr(months, chMon);
    tm.Month = ((m - months) / 3 + 1);

    tm.Day = atoi(compDate + 4);
    tm.Year = atoi(compDate + 7) - 1970;
    tm.Hour = atoi(compTime);
    tm.Minute = atoi(compTime + 3);
    tm.Second = atoi(compTime + 6);
    t = makeTime(tm);
    return t + FUDGE;        //add fudge factor to allow for compile time
}

//Function to print time with time zone
void printTime(time_t t, char *tz, char *loc)
{
    sPrintI00(hour(t));
    sPrintDigits(minute(t));
    sPrintDigits(second(t));
    Serial.print(' ');
    Serial.print(dayShortStr(weekday(t)));
    Serial.print(' ');
    sPrintI00(day(t));
    Serial.print(' ');
    Serial.print(monthShortStr(month(t)));
    Serial.print(' ');
    Serial.print(year(t));
    Serial.print(' ');
    Serial.print(tz);
    Serial.print(' ');
    Serial.print(loc);
    Serial.println();
}

//Print an integer in "00" format (with leading zero).
//Input value assumed to be between 0 and 99.
void sPrintI00(int val)
{
    if (val < 10) Serial.print('0');
    Serial.print(val, DEC);
    return;
}

//Print an integer in ":00" format (with leading zero).
//Input value assumed to be between 0 and 99.
void sPrintDigits(int val)
{
    Serial.print(':');
    if(val < 10) Serial.print('0');
    Serial.print(val, DEC);
}
There is even the "Timezone" // Central European Time (Frankfurt, Paris). The one that concerns me.

But as I have already pointed out on the Forum. I am not able to integrate this Sketch "Timezone" "Worldclock" into the Sketch "clock_sevenseg_gps".

I'm a pilot of Boeing 747-400, I know how to do a lot of things, but I'm not really comfortable with the C language.

Could someone help me get this update for the summer / winter time.
In advance a huge thank you.

Jacky

User avatar
marke3
 
Posts: 205
Joined: Sat Feb 08, 2014 5:24 pm

Re: setBrightness ???

Post by marke3 »

Wouldn't want your mind wandering while at the controls so...

Try this logic. I use it in just an RTC context and it needed a little bending to fit the GPS data but it seems to work OK.

I use some functions from RTClib so you'll have to add that to your #includes:

Code: Select all

#include "RTClib.h"
(download it if you haven't got it already https://github.com/adafruit/RTClib ).

Then the sketch needs to adjust the hours variable if summertime is current. Directly after the hours variable is declared around line 88 add:

Code: Select all

  if (ifSummertime(gps.year, gps.month, gps.day, hours, gps.minute)) {
    hours += 1;
  }
That's the bit so you don't have to keep going into the sketch to adjust HOUR_OFFSET every six months. Finally, you need to add the ifSummertime function at the end:

Code: Select all

/* ifSummertime function identifies if current time is in proscribed
 * summer time period. It finds the last Sunday in a month
 * in the current year using the while loops. That logic can be easily
 * adjusted for different rules. It needs some handy functions from RTClib
 * so that must be included.
 */
boolean ifSummertime(uint8_t y, uint8_t mo, uint8_t d, uint8_t h, uint8_t mi) {
  // Find last Sunday in March for summertime start date
  DateTime startDate = DateTime(2000 + y, 3, 25, 2, 0, 0);  // 2000+ to align GPS YY with RTClib YYYY
  while(startDate.dayOfTheWeek() > 0) {
    startDate = startDate + TimeSpan(1, 0, 0, 0);           // if not Sunday, try the next day
  }
  // Find last Sunday in October for summertime end date
  DateTime endDate = DateTime(2000 + y, 10, 25, 2, 0, 0);
  while(endDate.dayOfTheWeek() > 0) {
    endDate = endDate + TimeSpan(1, 0, 0, 0);
  }
  DateTime current = DateTime(2000 + y, mo, d, h, mi, 0);
  if ((current.unixtime() > startDate.unixtime()) && (current.unixtime() < endDate.unixtime())) {
    return 1; 
  }
  else {
    return 0;
  }
}
It's not very efficient as it is establishing the summertime period and checking current time against it every time through the loop. It would be better to do that much less frequently and set a flag or something but what the heck, it works and I doubt the microprocessor minds. :)

User avatar
JackyNiew
 
Posts: 33
Joined: Wed Jun 04, 2014 9:34 am

Re: setBrightness ???

Post by JackyNiew »

Hello Marke3,

Decidedly you are the only one offering me solutions. And I thank you ...
As soon as I get, a little free time I will test what you propose ...

I have to mount a 2nd clock with the same display and the DS1307 in place of the GPS module; To perform the tests. For I understood that with the Sketch using the DS1307 there was the possibility to adjust the time, the month and the year. This will prevent me from waiting for the last Sunday of March, in the case of the GPS sketch.

I keep you informed of my tests. Thanks again.
Jacky

User avatar
JackyNiew
 
Posts: 33
Joined: Wed Jun 04, 2014 9:34 am

Re: setBrightness ???

Post by JackyNiew »

Hello Marke3,

I have just asked you again.
For my test from the Sketch with the DS1307 which is below:

Code: Select all

// Clock example using a seven segment display & DS1307 real-time clock.
//
// Must have the Adafruit RTClib library installed too!  See:
//   https://github.com/adafruit/RTClib
//
// Designed specifically to work with the Adafruit LED 7-Segment backpacks
// and DS1307 real-time clock breakout:
// ----> http://www.adafruit.com/products/881
// ----> http://www.adafruit.com/products/880
// ----> http://www.adafruit.com/products/879
// ----> http://www.adafruit.com/products/878
// ----> https://www.adafruit.com/products/264
//
// Adafruit invests time and resources providing this open source code, 
// please support Adafruit and open-source hardware by purchasing 
// products from Adafruit!
//
// Written by Tony DiCola for Adafruit Industries.
// Released under a MIT license: https://opensource.org/licenses/MIT
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include "RTClib.h"


// Set to false to display time in 12 hour format, or true to use 24 hour:
#define TIME_24_HOUR      true

// I2C address of the display.  Stick with the default address of 0x70
// unless you've changed the address jumpers on the back of the display.
#define DISPLAY_ADDRESS   0x70


// Create display and DS1307 objects.  These are global variables that
// can be accessed from both the setup and loop function below.
Adafruit_7segment clockDisplay = Adafruit_7segment();
RTC_DS1307 rtc = RTC_DS1307();

// Keep track of the hours, minutes, seconds displayed by the clock.
// Start off at 0:00:00 as a signal that the time should be read from
// the DS1307 to initialize it.
int hours = 0;
int minutes = 0;
int seconds = 0;

// Remember if the colon was drawn on the display so it can be blinked
// on and off every second.
bool blinkColon = false;


void setup() {
  // Setup function runs once at startup to initialize the display
  // and DS1307 clock.

  // Setup Serial port to print debug output.
  Serial.begin(115200);
  Serial.println("Clock starting!");

  // Setup the display.
  clockDisplay.begin(DISPLAY_ADDRESS);

  // Setup the DS1307 real-time clock.
  rtc.begin();

  // Set the DS1307 clock if it hasn't been set before.
  bool setClockTime = !rtc.isrunning();
  // Alternatively you can force the clock to be set again by
  // uncommenting this line:
  //setClockTime = true;
  if (setClockTime) {
    Serial.println("Setting DS1307 time!");
    // This line sets the DS1307 time to the exact date and time the
    // sketch was compiled:
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // Alternatively you can set the RTC with an explicit date & time, 
    // for example to set January 21, 2014 at 3am you would uncomment:
    //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

void loop() {
  // Loop function runs over and over again to implement the clock logic.
  
  // Check if it's the top of the hour and get a new time reading
  // from the DS1307.  This helps keep the clock accurate by fixing
  // any drift.
  if (minutes == 0) {
    // Get the time from the DS1307.
    DateTime now = rtc.now();
    // Print out the time for debug purposes:
    Serial.print("Read date & time from DS1307: ");
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    // Now set the hours and minutes.
    hours = now.hour();
    minutes = now.minute();
  }

  // Show the time on the display by turning it into a numeric
  // value, like 3:30 turns into 330, by multiplying the hour by
  // 100 and then adding the minutes.
  int displayValue = hours*100 + minutes;

  // Do 24 hour to 12 hour format conversion when required.
  if (!TIME_24_HOUR) {
    // Handle when hours are past 12 by subtracting 12 hours (1200 value).
    if (hours > 12) {
      displayValue -= 1200;
    }
    // Handle hour 0 (midnight) being shown as 12.
    else if (hours == 0) {
      displayValue += 1200;
    }
  }
  // clockDisplay.setBrightness (5);

  // Now print the time value to the display.
  clockDisplay.print(displayValue, DEC);

  // Add zero padding when in 24 hour mode and it's midnight.
  // In this case the print function above won't have leading 0's
  // which can look confusing.  Go in and explicitly add these zeros.
  if (TIME_24_HOUR && hours == 0) {
    // Pad hour 0.
    clockDisplay.writeDigitNum(1, 0);
    // Also pad when the 10's minute is 0 and should be padded.
    if (minutes < 10) {
      clockDisplay.writeDigitNum(3, 0);
    }
  }

  // Blink the colon by flipping its value every loop iteration
  // (which happens every second).
  blinkColon = !blinkColon;
  clockDisplay.drawColon(blinkColon);

  // Now push out to the display the new values that were set above.
  clockDisplay.writeDisplay();

  // Pause for a second for time to elapse.  This value is in milliseconds
  // so 1000 milliseconds = 1 second.
  delay(1000);

  // Now increase the seconds by one.
  seconds += 1;
  // If the seconds go above 59 then the minutes should increase and
  // the seconds should wrap back to 0.
  if (seconds > 59) {
    seconds = 0;
    minutes += 1;
    // Again if the minutes go above 59 then the hour should increase and
    // the minutes should wrap back to 0.
    if (minutes > 59) {
      minutes = 0;
      hours += 1;
      // Note that when the minutes are 0 (i.e. it's the top of a new hour)
      // then the start of the loop will read the actual time from the DS1307
      // again.  Just to be safe though we'll also increment the hour and wrap
      // back to 0 if it goes above 23 (i.e. past midnight).
      if (hours > 23) {
        hours = 0;
      }
    }
  }

  // Loop code is finished, it will jump back to the start of the loop
  // function again!
}
Where should I insert your Code, below?

Code: Select all

    /* ifSummertime function identifies if current time is in proscribed
     * summer time period. It finds the last Sunday in a month
     * in the current year using the while loops. That logic can be easily
     * adjusted for different rules. It needs some handy functions from RTClib
     * so that must be included.
     */
    boolean ifSummertime(uint8_t y, uint8_t mo, uint8_t d, uint8_t h, uint8_t mi) {
      // Find last Sunday in March for summertime start date
      DateTime startDate = DateTime(2000 + y, 3, 25, 2, 0, 0);  // 2000+ to align GPS YY with RTClib YYYY
      while(startDate.dayOfTheWeek() > 0) {
        startDate = startDate + TimeSpan(1, 0, 0, 0);           // if not Sunday, try the next day
      }
      // Find last Sunday in October for summertime end date
      DateTime endDate = DateTime(2000 + y, 10, 25, 2, 0, 0);
      while(endDate.dayOfTheWeek() > 0) {
        endDate = endDate + TimeSpan(1, 0, 0, 0);
      }
      DateTime current = DateTime(2000 + y, mo, d, h, mi, 0);
      if ((current.unixtime() > startDate.unixtime()) && (current.unixtime() < endDate.unixtime())) {
        return 1;
      }
      else {
        return 0;
      }
    }
I think I do not need to put the line:

Code: Select all

      if (ifSummertime(gps.year, gps.month, gps.day, hours, gps.minute)) {
        hours += 1;
      }
Since in this case for the test, I use the DS1307 and not the GPS module.
I'm sorry to be as bad in programming ...

Thanks in advance...
Jacky

User avatar
marke3
 
Posts: 205
Joined: Sat Feb 08, 2014 5:24 pm

Re: setBrightness ???

Post by marke3 »

Apologies, I didn't notice you posted again.

This program is slightly different because you maintain the current time on your own hardware (the DS1307) rather than query someone else's hardware (the GPS satellites). Because Adafruit is so darn good, the two programs (both written by Tony DiCola) are very easy to work with.
Where should I insert your Code, below?
The function I gave you does need to be modified. It doesn't need to add 2000 to the year anymore.

Code: Select all

/* ifSummertime function identifies if current time is in proscribed
 * summer time period. It finds the last Sunday in a month
 * in the current year using the while loops. That logic can be easily
 * adjusted for different rules.
 */
boolean ifSummertime(uint16_t y, uint8_t mo, uint8_t d, uint8_t h, uint8_t mi) {
  // Find last Sunday in March for summertime start date
  DateTime startDate = DateTime(y, 3, 25, 2, 0, 0);
  while(startDate.dayOfTheWeek() > 0) {
    startDate = startDate + TimeSpan(1, 0, 0, 0);           // if not Sunday, try the next day
  }
  // Find last Sunday in October for summertime end date
  DateTime endDate = DateTime(y, 10, 25, 2, 0, 0);
  while(endDate.dayOfTheWeek() > 0) {
    endDate = endDate + TimeSpan(1, 0, 0, 0);
  }
  DateTime current = DateTime(y, mo, d, h, mi, 0);
  if ((current.unixtime() > startDate.unixtime()) && (current.unixtime() < endDate.unixtime())) {
    return 1; 
  }
  else {
    return 0;
  }
}
You can, again, add it in at the end, after the loop().
I think I do not need to put the line:
You do need to have this if statement if you don't want to change your clock time by modifying code twice each year. But with the different hardware approach, you'll need a couple of new modifications in the clock_sevenseg_ds1307 sketch.

1. Change the parameters from the GPS ones to the RTC. The statement should now be:

Code: Select all

  if (ifSummertime(now.year, now.month, now.day, hours, now.minute)) {
    hours += 1;
  }
2. Insert it after line 105 where the hours variable is set to a new reading from the clock.
3. The DS1307 handles roll over of 24 to 0 hours but if you are adjusting it, you'll need to do that yourself. Because the GPS sketch needed to do that that we can just lift code from there (thank you Mr DiCola :). So directly after the if statement you just added, insert:

Code: Select all

  // Handle when Summertime offset wraps around to a negative or > 23 value.
  if (hours < 0) {
    hours = 24+hours;
  }
  if (hours > 23) {
    hours = 24-hours;
  }
Note, the serial debugging messages are before the summertime adjustment so will show the time on the clock, but the display shows the adjusted time. I haven't had the chance to test it yet as most of my processors seem to be running seasonal decorations...

User avatar
JackyNiew
 
Posts: 33
Joined: Wed Jun 04, 2014 9:34 am

Re: setBrightness ???

Post by JackyNiew »

Thanks Marke3,

I will try to integrate your explanations and I will keep you informed ...

Once again ; thank you.
Jacky

Locked
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”