Smart O’clock

Hello everybody,

This week we worked on the code of our project, the smart o’clock:

  • The first step was to download the different libraries needed: for the usage of the LCD (LiquidCrystal_I2C.h and wire.h) and for the usage of the RTC (RTClib.h); and to report all the variables.
  • The second step of the code was to give a reference of time to our RTC to be able to use this reference to start up the different parts of our alarm at the time chosen to wake up. This reference is going to be sent and posted on the screen so a real prototype of an alarm clock can be provided.

The next steps that we chose to work on this week was to turn on the light and the sound of the alarm when the chosen time is reached.

The goal of the next meeting will be to look at the code and the electrical assembly of the FSR which will be used to turn off the alarm because it will give the proof that the person is up.

See you soon,

The smart O’clock team.

Here is the code of our project:

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include “RTClib.h”

RTC_Millis RTC;

int backlightState = LOW;

long previousMillis = 0;

long interval = 1000;

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x20(Cooperate with 3 short circuit caps) for a 16 chars and 2 line display

int H = 18; //heure à laquelle il faut sonner.. entrer manuellement

int M = 19; //minute à laquelle il faut sonner.. entrer manuellement

//——————————————————————————-

int ledPin = 13;    // LED connected to digital pin 13 if ringing

int ledPin2 = 12; // not ringing

int A = 10;

int B = 0;

int mini = 20; // c’est 20/255 ! ne pas dépasser 190 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

int maxi = 180; //c’est 180/255 ! ne pas dépasser 190 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

int pas = 1; // fade in from min to max in increments of 1 points:

//——————————————————————————-

int speakerPin = 9;

int length = 15; // the number of notes

char notes[] = “ccggaagffeeddc “; // a space represents a rest

int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };

int tempo = 300;

void playTone(int tone, int duration) {

for (long i = 0; i < duration * 1000L; i += tone * 2) {

digitalWrite(speakerPin, HIGH);

delayMicroseconds(tone);

digitalWrite(speakerPin, LOW);

delayMicroseconds(tone);

}

}

void playNote(char note, int duration) {

char names[] = { ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘a’, ‘b’, ‘C’ };

int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

// play the tone corresponding to the note name

for (int i = 0; i < 8; i++) {

if (names[i] == note) {

playTone(tones[i], duration);

}

}

}

//——————————————————————————-

void setup(){

RTC.begin(DateTime(__DATE__, __TIME__));

pinMode(speakerPin, OUTPUT);

}

void loop(){

lcd.init();                      // initialize the lcd

lcd.backlight();

lcd.home();

DateTime now = RTC.now();

lcd.setCursor(0, 0);

lcd.print(“////”);

lcd.setCursor(6, 0);

lcd.print(‘/’); lcd.print(now.hour(), DEC); lcd.print(‘:’); lcd.print(now.minute(), DEC);lcd.print(‘/’);

lcd.setCursor(0, 1);

lcd.print(“///”);

lcd.setCursor(0, 2);

lcd.print(“//”);

lcd.setCursor(0, 3);

lcd.print(“/”);

lcd.setCursor(12, 3);

lcd.print(now.day(), DEC); lcd.print(‘/’);lcd.print(now.month(), DEC);lcd.print(‘/’);lcd.print(now.year(), DEC);

delay(10000);

unsigned long currentMillis = millis();

//——————————————————————————-

if (now.hour()== H&&now.minute()==M)

{

//—————————————————————LED 1

for(int fadeValue = mini ; fadeValue <= maxi; fadeValue +=pas) {

// sets the value (range from 0 to 255):

analogWrite(ledPin, fadeValue);

// wait for 30 milliseconds to see the dimming effect

delay(A+B);

}

// fade out from max to min in increments of 5 points:

for(int fadeValue = maxi ; fadeValue >= mini; fadeValue -=pas) {

// sets the value (range from 0 to 255):

analogWrite(ledPin, fadeValue);

// wait for 30 milliseconds to see the dimming effect

delay(A);

}

//—————————————————————SON

for (int i = 0; i < length; i++) {

lcd.setCursor(4, 2);

lcd.print(“Reveille toi !!”);

if (notes[i] == ‘ ‘) {

delay(beats[i] * tempo); // rest

} else {

playNote(notes[i], beats[i] * tempo);

}

// pause between notes

delay(tempo / 2);

}

}

else

{

//—————————————————————LED 2

for(int fadeValue2 = mini ; fadeValue2 <= maxi; fadeValue2 +=pas) {

analogWrite(ledPin2, fadeValue2);

delay(A);

}

for(int fadeValue2 = maxi ; fadeValue2 >= mini; fadeValue2 -=pas) {

analogWrite(ledPin2, fadeValue2);

delay(A);

}

}

//——————————————————————————-

if(currentMillis – previousMillis > interval) {

previousMillis = currentMillis;

if (backlightState == LOW)

backlightState = HIGH;

else

backlightState = LOW;

if(backlightState == HIGH)  lcd.backlight();

else lcd.noBacklight();

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s