Egor Spirin
Published © GPL3+

ST. VALENTINE’S DAY: HACKED

Holiday is always a good reason to make something cool. This time I wanted to play with Pro Minis and an RTC module.

IntermediateFull instructions provided5 hours3,155
ST. VALENTINE’S DAY: HACKED

Things used in this project

Hardware components

Arduino Pro Mini 328 - 3.3V/8MHz
SparkFun Arduino Pro Mini 328 - 3.3V/8MHz
×1
Jumper wires (generic)
Jumper wires (generic)
×1
7-segment display
×1
1800 mAh Li-Ion battery
×1
Photo resistor
Photo resistor
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Story

Read more

Code

Code snippet #1

Plain text
date1=(rtc.getDateStr());//Get date
date1.replace ("."," "); //Delete dots
 
day2=date1;
month2=date1;
year2=date1;
 
day2.remove(2); //Separate day, month and year
month2.remove(5);
month2.remove (0,3);
year2.remove (0,6);
 
day1=day2.toInt(); //Convert to integer
month1=month2.toInt()-1; //Subtract 1 for the easier later calculations 
year1=year2.toInt();

Code snippet #2

Plain text
if (month1+1 == 2 && day1 == 17) {event=1; state=1;} //Sudden kindness day
 
if (event == 1) {
for (int i=0; i<400; i++) {disp.write ("show");} 
for (int i=0; i<400; i++) {disp.write ("sddn");} 
for (int i=0; i<400; i++) {disp.write ("cndr");} 
} 
//Display will show: "show sddn cndr" which stands for "show sudden candor"

Code snippet #3

Plain text
//Count how many days are there in months of leap years
if ((year1 == 2016 || year1 == 2020 || year1== 2024
|| year1 == 2028 || year1 == 2032 || year1 == 2036 || year1 == 2040))
 
{ 
  
if (month1 == 1) {dur=31;} //If month1 == 1 then dur will be 0
if (month1 == 2) {dur=60;} 
if (month1 == 3) {dur=91;}
if (month1 == 4) {dur=121;}
if (month1 == 5) {dur=152;}
if (month1 == 6) {dur=182;}
if (month1 == 7) {dur=213;}
if (month1 == 8) {dur=244;}
if (month1 == 9) {dur=274;}
if (month1 == 10) {dur=305;}
if (month1 == 11) {dur=335;}
 
//Total number of days (I added 7 because I want to count from the 25th of December, 2015)
  year1= (year1-2016)*366 ; 
  num = 7 + day1 + dur + year1;
}
 
else 
//And in normal years
{ 
if (month1 == 1) {dur=31;} 
if (month1 == 2) {dur=59;} 
if (month1 == 3) {dur=90;}
if (month1 == 4) {dur=120;}
if (month1 == 5) {dur=151;}
if (month1 == 6) {dur=181;}
if (month1 == 7) {dur=214;}
if (month1 == 8) {dur=243;}
if (month1 == 9) {dur=273;}
if (month1 == 10) {dur=304;}
if (month1 == 11) {dur=334;}
 
  year1= (year1-2016)*365 ;
  num = 7 + day1 + dur + year1;
}
 
if (state == 0) {for (int i=0; i<200; i++) {disp.write (num);}}

Code snippet #4

Plain text
state=0;
event=0;
dur=0; 
digitalWrite (5,LOW);
digitalWrite (8,LOW);
digitalWrite (9,LOW);
digitalWrite (A1,LOW);
 
digitalWrite (6,LOW); 
digitalWrite (A2,LOW); 
digitalWrite (11,LOW); 
digitalWrite (13,LOW); 
digitalWrite (A0,LOW); 
digitalWrite (7,LOW); 
digitalWrite (10,LOW); 
delay (100); //Depends on your display. If it turns off fast - make this value smaller

Code snippet #5

Plain text
String date1;
 
int day1;
int month1;
int year1;
int dur;
int t;
int event;
int state;
 
String day2;
String month2;
String year2;
 
int num=0;
 
#include <SevenSeg.h>
#include <DS1302.h>
#include <LowPower.h>
 
// Init the DS1302
DS1302 rtc(4, 3, 2);
 
SevenSeg disp(6,A2,11,13,A0,7,10);
const int numOfDigits=4;
int digitPins[numOfDigits]={5,8,9,A1};
 
void setup()
{
  disp.setDigitPins (numOfDigits,digitPins);
  disp.setCommonCathode ();
  disp.setDPPin (12); 
 
 }
 
void loop() {
  
if (analogRead (A4) >50) {
 
  
date1=(rtc.getDateStr());//get date
date1.replace ("."," "); //delete dots
 
day2=date1;
month2=date1;
year2=date1;
 
day2.remove(2); //separate day, month and year
month2.remove(5);
month2.remove (0,3);
year2.remove (0,6);
 
day1=day2.toInt(); //convert to integer
month1=month2.toInt()-1;
year1=year2.toInt(); 
 
if (month1+1 == 2 && day1 == 17) {event=1; state=1;} //Sudden kindness
 
//count numbers of days in months of leap years
if ((year1 == 2016 || year1 == 2020 || year1== 2024
|| year1 == 2028 || year1 == 2032 || year1 == 2036 || year1 == 2040))
 
{ 
  
if (month1 == 1) {dur=31;} 
if (month1 == 2) {dur=60;} 
if (month1 == 3) {dur=91;}
if (month1 == 4) {dur=121;}
if (month1 == 5) {dur=152;}
if (month1 == 6) {dur=182;}
if (month1 == 7) {dur=213;}
if (month1 == 8) {dur=244;}
if (month1 == 9) {dur=274;}
if (month1 == 10) {dur=305;}
if (month1 == 11) {dur=335;}
 
  year1= (year1-2016)*366 ; //total number of days (I added 7 because I want to count from the 25th of December, 2015)
  num = 7 + day1 + dur + year1;
  
}
 
else 
//and in normal years
{ 
if (month1 == 1) {dur=31;} 
if (month1 == 2) {dur=59;} 
if (month1 == 3) {dur=90;}
if (month1 == 4) {dur=120;}
if (month1 == 5) {dur=151;}
if (month1 == 6) {dur=181;}
if (month1 == 7) {dur=214;}
if (month1 == 8) {dur=243;}
if (month1 == 9) {dur=273;}
if (month1 == 10) {dur=304;}
if (month1 == 11) {dur=334;}
 
  year1= (year1-2016)*365 ;
  num = 7 + day1 + dur + year1;
  
}
 
if (event == 1) { 
for (int i=0; i<400; i++) {disp.write ("show");} 
for (int i=0; i<400; i++) {disp.write ("sddn");} 
for (int i=0; i<400; i++) {disp.write ("cndr");}
}
 
if (state == 0) {for (int i=0; i<200; i++) {disp.write (num);}}
 
state=0;
event=0;
dur=0; 
digitalWrite (5,LOW);
digitalWrite (8,LOW);
digitalWrite (9,LOW);
digitalWrite (A1,LOW);
 
digitalWrite (6,LOW); 
digitalWrite (A2,LOW); 
digitalWrite (11,LOW); 
digitalWrite (13,LOW); 
digitalWrite (A0,LOW); 
digitalWrite (7,LOW); 
digitalWrite (10,LOW); 
delay (100);
 
}
 
else {LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);}
 
}

Github

Low-Power library

Github

DS1302 library

Credits

Egor Spirin

Egor Spirin

1 project • 0 followers
Arduino programmer. Living the code! Welcome to my blog!

Comments