#include "U8glib.h"
#include <SPI.h>
#include <Wire.h>
#include "RTClib.h"
// setup u8g object
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C
//
const int buzzerPin = 7; // Connect the buzzer to Pin 7
const int bellDuration = 100; // Bell duration in milliseconds
int melody[] = { // Define the bell sound
262, 330, 392, 523, 392, 330, 262
};
int noteDuration[] = { // Define the note duration
2000
};
int duration = 1000; // Set the duration of the sound in milliseconds
int pause = 250; // Set the pause between the sounds in milliseconds
// Setup RTC
RTC_DS1307 RTC;
char monthString[37] = { "JanFebMarAprMayJunJulAugSepOctNovDec" };
int monthIndex[122] = { 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33 };
String thisMonth = "";
String thisTime = "";
String thisDay = "";
int clockCentreX = 64; // used to fix the centre the analog clock
int clockCentreY = 32; // used to fix the centre the analog clock
//
//TMP36 Pin Variables
boolean useTMP36 = true; // set this to false if you don not use TMP36
//boolean useTMP36 = false;
#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter!
int tempPin = 1; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
int tempReading; // the analog reading from the sensor
//
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_profont15);
//u8g.setFont(u8g_font_6x10);
//
//***** RTC ********
DateTime now = RTC.now();
// display date at bottom of screen
thisDay = String(now.day(), DEC) + "/";
thisMonth = "";
for (int i = 0; i <= 2; i++) {
thisMonth += monthString[monthIndex[now.month() - 1] + i];
}
thisDay = thisDay + thisMonth + "/";
thisDay = thisDay + String(now.year(), DEC);
const char* newDay = (const char*)thisDay.c_str();
u8g.drawStr(30, 60, newDay);
// *******************
// display time in digital format
u8g.drawStr(35, 35, "A.W.A.R.D.");
thisTime = "";
thisTime = String(now.hour()) + ":";
if (now.minute() < 10) { thisTime = thisTime + "0"; } // add leading zero if required
thisTime = thisTime + String(now.minute()) + ":";
if (now.second() < 10) { thisTime = thisTime + "0"; } // add leading zero if required
thisTime = thisTime + String(now.second());
const char* newTime = (const char*)thisTime.c_str();
u8g.drawStr(42, 10, newTime);
// *******************
//
}
void setup(void) {
Serial.begin(9600);
// If you want to set the aref to something other than 5v
analogReference(EXTERNAL);
Wire.begin();
RTC.begin();
if (!RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
//RTC.adjust(DateTime(2023, 5, 11, 9, 2, 0));
}
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while (u8g.nextPage());
// rebuild the picture after some delay
delay(50);
// Check the time and ring the bell if necessary
if (thisTime == "10:25:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
for (int i = 0; i < 8; i++) {
int note = melody[i]; // Get the current note frequency
int duration = noteDuration[i]; // Get the current note duration
tone(buzzerPin, note, duration); // Play the current note on the buzzer
delay(duration); // Wait for the note duration
}
noTone(buzzerPin); // Stop playing sound on the buzzer
delay(500); // Wait for a short time before playing the melody again
}
if (thisTime == "13:59:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
for (int i = 0; i < 8; i++) {
int note = melody[i]; // Get the current note frequency
int duration = noteDuration[i]; // Get the current note duration
tone(buzzerPin, note, duration); // Play the current note on the buzzer
delay(duration); // Wait for the note duration
}
noTone(buzzerPin); // Stop playing sound on the buzzer
delay(1000); // Wait for a short time before playing the melody again
}
if (thisTime == "10:25:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
for (int i = 0; i < 8; i++) {
int note = melody[i]; // Get the current note frequency
int duration = noteDuration[i]; // Get the current note duration
tone(buzzerPin, note, duration); // Play the current note on the buzzer
delay(duration); // Wait for the note duration
}
noTone(buzzerPin); // Stop playing sound on the buzzer
delay(500); // Wait for a short time before playing the melody again
}
if (thisTime == "10:25:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
for (int i = 0; i < 8; i++) {
int note = melody[i]; // Get the current note frequency
int duration = noteDuration[i]; // Get the current note duration
tone(buzzerPin, note, duration); // Play the current note on the buzzer
delay(duration); // Wait for the note duration
}
noTone(buzzerPin); // Stop playing sound on the buzzer
delay(500); // Wait for a short time before playing the melody again
}
if (thisTime == "10:25:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
for (int i = 0; i < 8; i++) {
int note = melody[i]; // Get the current note frequency
int duration = noteDuration[i]; // Get the current note duration
tone(buzzerPin, note, duration); // Play the current note on the buzzer
delay(duration); // Wait for the note duration
}
noTone(buzzerPin); // Stop playing sound on the buzzer
delay(500); // Wait for a short time before playing the melody again
}
if (thisTime == "10:25:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
for (int i = 0; i < 8; i++) {
int note = melody[i]; // Get the current note frequency
int duration = noteDuration[i]; // Get the current note duration
tone(buzzerPin, note, duration); // Play the current note on the buzzer
delay(duration); // Wait for the note duration
}
noTone(buzzerPin); // Stop playing sound on the buzzer
delay(500); // Wait for a short time before playing the melody again
}
if (thisTime == "10:25:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
// Play the emergency alarm sound
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
// Wait for one second before playing the sound again
delay(1000); // 1000 milliseconds = 1 second
}
{
if (thisTime == "10:25:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
// Play the emergency alarm sound
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
// Wait for one second before playing the sound again
delay(1000); // 1000 milliseconds = 1 second
}
{
if (thisTime == "10:25:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
// Play the emergency alarm sound
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
// Wait for one second before playing the sound again
delay(1000); // 1000 milliseconds = 1 second
}
{
if (thisTime == "22:36:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
// Play the emergency alarm sound
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
// Wait for one second before playing the sound again
delay(1000); // 1000 milliseconds = 1 second
}
{
if (thisTime == "10:00:00") {
// Ring the bell for 3 seconds
digitalWrite(buzzerPin, HIGH);
delay(bellDuration);
digitalWrite(buzzerPin, LOW);
// Play the emergency alarm sound
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 880, duration); // 880Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
tone(buzzerPin, 1760, duration); // 1760Hz tone for 0.5 second
delay(pause); // Pause for 0.25 second
// Wait for one second before playing the sound again
delay(1000); // 1000 milliseconds = 1 second
}
{
delay(1000);
}
}
}
}
}
}