LiamCamaraCooper
Published © GPL3+

Valentines Day Idea - Days Spent Together Counter (Photo)

Photo frame that counts the number of days spent together.

BeginnerFull instructions provided5,218
Valentines Day Idea - Days Spent Together Counter (Photo)

Things used in this project

Hardware components

Real Time Clock (RTC)
Real Time Clock (RTC)
DS3231
×1
Arduino KYX-5461AS 4-digit 7-segment
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino UNO
Arduino UNO
×1
Resistor 1k ohm
Resistor 1k ohm
×1

Story

Read more

Schematics

SCHEMATIC

https://www.circuito.io/app?components=512,11021]

copy and paste the link.

click add components

type;
RTC (add);

7 segment display 20mm (choose generic, don't choose sparkfun);

follow the diagram and attach each pin using the jumper cables

Code

DaysCounter.ino

C/C++
for this you will need to download arduino IDE
RTC library zip file,
seven segment zip file

save both of the libraries into the librarys folder where the arduino ide is installed.

from there open up arduino ide and click on 'sketch'
'include libraries'
'add zip libraries'

follow the code below
TO ADJUST TIME - on line 7 in the brackets it reads (2017, 12 , 9, 0, 0, 0,) you need to change the first 3 numbers
i.e 2017, 12, 9 ----> 2014, 4, 6,
what ever date you got together, enter it there.

then compile and select upload and if everything has gone to plan and you've followed the steps correctly it should display the amount of days you have been together
#include <RTClib.h>
#include <SevSeg.h>

SevSeg sevseg; //Instantiate a seven segment controller object
RTC_DS3231 rtc; 

DateTime dtBegin (2017, 12, 9, 0, 0, 0); //!!!! adjust time here!!!!!
TimeSpan tsPassed;

void showInfo(const DateTime& dt) {
  Serial.print("NOW:");
  
  Serial.print(dt.year(), DEC);
  Serial.print('/');
  Serial.print(dt.month(), DEC);
  Serial.print('/');
  Serial.print(dt.day(), DEC);
  Serial.print(' ');
  Serial.print(dt.hour(), DEC);
  Serial.print(':');
  Serial.print(dt.minute(), DEC);
  Serial.print(':');
  Serial.print(dt.second(), DEC);
  
  Serial.print("\tPASSED:");
  Serial.print(tsPassed.days(), DEC);
  Serial.print(' ');
  Serial.print(tsPassed.hours(), DEC);
  Serial.print(':');
  Serial.print(tsPassed.minutes(), DEC);
  Serial.print(':');
  Serial.print(tsPassed.seconds(), DEC);
  
  Serial.println("");
}

//=========================================
//
//=========================================
void delayWithUpdate(uint32_t parDelay){
  uint32_t started=millis();
  while (millis()< started+parDelay){
    sevseg.refreshDisplay();
  }
}
//=========================
//=========================
void setup(){
  Serial.begin(9600);
  Serial.println(__TIME__);
  
  if (! rtc.begin()) {
        Serial.println("Couldn't find RTC");
        //===Device will be frozen here.
        //?????????May be some error LED blinking would be good to use??????
        while (1);
  }
      
  delay(1000);    
  
  //!!!!! TO ADJUST A TIME:
  //1) uncomment a line below (under those comments)
  //2), upload the code again
  //3) COMMENT line back
  //4). uploand ONE MORE TIME

  
  
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));   //line to adjust time 
      

  byte numDigits = 4;
  byte digitPins[] = {7, 8, 9, 10};
  //SEG:  A B C D E F G .
  //PIN:  11  7 4 2 1 10  5 3
  //ARDU: 2 3 4 5 11  12  13  6
  //byte segmentPins[] = {2, 3, 4, 5, 11, 12, 13, 6};
  byte segmentPins[] = {2, 3, 4, 5, 11, 12, 13, 6};
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_CATHODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = true; // Use 'true' if your decimal point doesn't exist or isn't connected
  
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
  updateWithDelays, leadingZeros, disableDecPoint);
  sevseg.setBrightness(100);
  
  
  
  sevseg.setNumber(1234, 1);
  delayWithUpdate(1000);
  
  
  sevseg.setNumber(8888, 1);
  delayWithUpdate(1000);
  
}
//=========================
//=========================
void loop(){
  sevseg.refreshDisplay();
  
  DateTime now = rtc.now();
  
  tsPassed = now-dtBegin;
  
  static uint32_t nextReportMillis=0;
  static uint16_t prevDaysPassed=0;
  
  if (tsPassed.days() != prevDaysPassed){
    prevDaysPassed=tsPassed.days();
    sevseg.setNumber(prevDaysPassed, 0);
  }

  
  sevseg.refreshDisplay();
  
  if (millis()>nextReportMillis){
    //===PRINT SOME INFO HERE
    showInfo(now);
    nextReportMillis=millis()+5000;
  }
  
}

Credits

LiamCamaraCooper
0 projects • 4 followers

Comments