Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
Hand tools and fabrication machines | ||||||
| ||||||
|
I am learning Arduino fast and I want to use different modules to know how they work and gather some experience. But I want to make things that are useful (at least a little bit). So I decided to make a clock with the date displayed.
I learned how to use the RTC module, how to work with the Nokia 5110 display and learned something new about the energy saving mode in Arduino.
It was also interesting to draw the case and 3D print it.
All in all, a great experience and if you want to get started with Arduino this might be a suitable project for you.
Here is a video of how I made it:
It is in Russian, but I hope that you will still enjoy it!
/*
* 1.0
* : 1.4
* :
*/
#include <LowPower.h>
#include <Adafruit_GFX_rus.h>
#include <Adafruit_PCD8544_rus.h>
Adafruit_PCD8544 nokia = Adafruit_PCD8544(4, 3, 6, 7, 8); //CLK, DIN, DC, CE, RST
/*
* :
*
* -->
*(1)RST --> 8 pin
*(2)CE --> 7 pin
*(3)DC --> 6 pin
*(4)DIN --> 3 pin
*(5)CLK --> 4 pin
*(6)VCC --> 10 pin !!! !!!
*(7)LIGHT --> ----- ( .
* . .)
*(8)GND --> GND
*
* 2 .
*
*/
/*
* :
* IC:
* -->
* SDA --> A4
* SCL --> A5
* ==== ====
* VCC --> 3.3V
* GND --> GND
*/
extern uint8_t logo[];
#include <iarduino_RTC.h> // iarduino_RTC .
iarduino_RTC time(RTC_DS1307); // time RTC DS3231, I2C
//================= ===================
volatile int sec = 15;
volatile int minute = 8;
volatile int hour = 15;
volatile int date = 22;
volatile int Month = 6;
volatile int Year = 18;
volatile int weekDay = 5;
//==================================================
int day;
int month;
volatile boolean sleep = false;
#define powerBtn 2
#define dispPower 10
void setup() {
delay(3000); // ! 5.
// , 5
pinMode(dispPower, OUTPUT);
digitalWrite(dispPower, HIGH);
pinMode(powerBtn, INPUT_PULLUP);
delay(300); //
time.begin(); // .
time.settime(sec,minute,hour,date,Month,Year,weekDay); // : 0 , 51 , 21 , 27, , 2015 , .
nokia.begin();
nokia.clearDisplay();
nokia.setContrast(55);
nokia.drawBitmap(0, 0, logo, 84, 48, BLACK); // Pe
nokia.display();
delay(1500);
nokia.clearDisplay();
nokia.drawLine(0, 20, 84, 20, BLACK);
nokia.display();
}
//========== !!! =========
void wake_up() {
digitalWrite(dispPower, HIGH);
sleep = false;
nokia.begin();
nokia.clearDisplay();
nokia.setContrast(55);
nokia.display();
detachInterrupt(0);
nokia.drawBitmap(0, 0, logo, 84, 48, BLACK); // Pe
nokia.display();
}
//===========================================================
void loop() {
//========== ==========
if (sleep == false && digitalRead(powerBtn) == 0) {
nokia.clearDisplay();
nokia.drawBitmap(0, 0, logo, 84, 48, BLACK); // Pe
nokia.display();
delay(1000);
digitalWrite(dispPower, LOW);
sleep = true;
delay(1000);
attachInterrupt(0, wake_up, LOW);
if (sleep == true) {LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);}
}
//=========================================================================
LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF); // 250
//========== ==========
nokia.clearDisplay();
nokia.drawLine(4, 25, 80, 25, BLACK); //
time.gettime(); //
nokia.setTextSize(2); // 2
nokia.setCursor(5,5); // (5 5 y)
nokia.print(time.Hours); //
nokia.setTextSize(3); // 3
nokia.setCursor(25,2); //
nokia.print(":");
nokia.setTextSize(2);
nokia.setCursor(40,5);
nokia.print(time.minutes); //
nokia.setTextSize(1);
nokia.setCursor(68,5);
nokia.print(time.seconds); //
//=====================================
//================ ===================
nokia.setCursor(13,30);
time.gettime();
//================ ))) =================
day = time.weekday;
switch (day) {
case 0:
nokia.print(",");
break;
case 1:
nokia.print(",");
break;
case 2:
nokia.print(",");
break;
case 3:
nokia.print(",");
break;
case 4:
nokia.print(",");
break;
case 5:
nokia.print(",");
break;
case 6:
nokia.print(",");
break;
}
//====================================================
nokia.setCursor(40,30);
nokia.print(time.gettime("d.m"));
nokia.setCursor(10,40);
month = time.month;
switch (month) {
case 1:
nokia.print(", ");
break;
case 2:
nokia.print(", ");
break;
case 3:
nokia.print(", ");
break;
case 4:
nokia.print(", ");
break;
case 5:
nokia.print(", ");
break;
case 6:
nokia.print(", ");
break;
case 7:
nokia.print(", ");
break;
case 8:
nokia.print(", ");
break;
case 9:
nokia.print(", ");
break;
case 10:
nokia.print(", ");
break;
case 11:
nokia.print(", ");
break;
case 12:
nokia.print(", ");
break;
}
nokia.print(time.gettime("Y"));
//===================================================
nokia.display();
}
Comments