Display Time on 7-Segment LED Backpack

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
cmhippy
 
Posts: 15
Joined: Tue Feb 04, 2014 9:17 pm

Display Time on 7-Segment LED Backpack

Post by cmhippy »

Hello to All
I'm not using any external time source. Not even the Processing SyncArduinoClock, yet.
The code I'm using is the following but I'm sure there is a more efficient way to simply display time on the LED. There are many examples using RTCs and it's library but I couldn't find any using setTime in conjunction with the LED/Backpack. Eventually I intend to display time and temperature using the MPL3115A2 and log the data to a SD card shield. But that will be later.
Thanks in advance.
Chris
Here's the code:

Code: Select all

#include <Time.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

Adafruit_7segment matrix;

time_t t;
tmElements_t tm;

int seconds, minutes, hours;

void setup()
{
  matrix.begin(0x70);
  matrix.setBrightness(0);
  
  tm.Second = 0;
  tm.Minute = 51;
  tm.Hour = 23;
  tm.Day = 26;
  tm.Month = 11;
  tm.Year = CalendarYrToTm(2014);
  
  t = makeTime(tm);
}

void loop(void)
{
   minutes = minute(t);
   hours = hour(t);
   
   matrix.writeDigitNum(0, (hours / 10) % 10, false);
   matrix.writeDigitNum(1, (hours % 10), false);
   matrix.drawColon(true);
   matrix.writeDigitNum(3, (minutes / 10) % 10, false);
   matrix.writeDigitNum(4, minutes % 10, false);
   matrix.writeDisplay();
   ++t;
   delay(1000);
}
Last edited by adafruit_support_mike on Thu Nov 27, 2014 3:39 am, edited 1 time in total.
Reason: added CODE tags to preserve formatting

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Display Time on 7-Segment LED Backpack

Post by adafruit_support_mike »

You're doing it right.

You can do gymnastics with the values for the sake of packing everything into a single write() call, but the code underneath will just unpack the digits and write them one at a time anyway.

The code above will probably run a little faster because it just puts the numbers where you want them, and it has the strong virtue of being easy to read and understand.

If you find yourself using that sequence of operations a lot, wrap a function around it and send a couple of simple values to that.

cmhippy
 
Posts: 15
Joined: Tue Feb 04, 2014 9:17 pm

Re: Display Time on 7-Segment LED Backpack

Post by cmhippy »

Mike,

Thank you very much! Actually uplifting! LOL

Happy Thanksgiving

Chris

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

Return to “Other Arduino products from Adafruit”