Hello,
Well, I've just finished my program and I don't know why it doesn't work. ![]()
If I set the RTC time at 1H50 and the alarm time at 2H00, it works perfecly fine till 2H00. At 2H00 it makes a weird little crashing sound and goes back to 1H50. However, it was supposed to play a little song and to display a led animation.
I really don't know how to fix it. Can someone give me some advaces, please?
Thanks in advance and here the code :
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX HI BUDDY : Alarm Clock XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/*
*
*/
#include <Wire.h>
#include <RTClib.h>
// Ici se trouve la configuration des differente broches auxquels sont branché les differents composants et les variables à fixer initialement
// déclaration des broches pour la gestion des lignes et des colonnes
int colonne[] = {1,2,3,4,5,6,7}; // matrice de colonne
int ligne[] = {8,9,10,11,12}; // matrice de ligne
// déclaration des broches pour la gestion du DS1307
RTC_DS1307 rtc;
// Ici se trouve tous les motifs programmer
int dheure [3][22] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 17, 31}, // OX
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 0}, // 1X
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, 21, 23} }; // 2X
int dminute [6][22] = { {0, 0, 0, 0, 0, 0, 0, 0, 31, 17, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 0X
{0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 1X
{0, 0, 0, 0, 0, 0, 0, 0, 29, 21, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 2X
{0, 0, 0, 0, 0, 0, 0, 0, 31, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 3X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, 31, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 31, 4, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 23, 21, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 23, 21, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 31, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 31, 21, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 31, 21, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} };
*/
// Liste des notes se trouvans dans la chanson
// Octave 3
#define E3 165 // Mi
#define Ab3 208 // Sol#
#define A3 220 // La
#define B3 247 // Si
// Octave 4
#define Db4 277 // Do#
#define D4 294 // Ré
#define E4 330 // Mi
#define Ab4 415 // Sol#
#define A4 440 // La
#define B4 494 // Si
// 0ctave 5
#define Db5 554 // Do#
#define D5 587 // Ré
#define E5 659 // Mi
// Mélodie : chaque note est jouée l'une après l'autre
int melody[] ={
A4, Ab4, A4, Ab4, A4, E4, A4, D4, A3, Db4,
A4, Ab4, A4, Ab4, A4, E4, A4, D4, A3, Db4,
A4, Ab4, A4, A3, Ab4, A4, A3, Ab4, A4, A3, E4, A3,
Db4, D4, E4, Db4, B3, A3, Ab3, A3, E3, A3, B3, Db4, Db4, D4,
E4, D4, Db4, B3
};
// Durée de chaque note : 4 => 1/4 de ton
// 8 => 1/8 de ton...
int noteDurations[] = {
4, 4, 4, 4, 4, 4, 4, 1, 8, 8,
4, 4, 4, 4, 4, 4, 4, 1, 8, 8,
4, 8, 4, 8, 8, 4, 8, 8, 4, 8, 8, 8,
4, 4, 4, 4, 2, 8, 8, 3, 8, 8, 8, 2, 8, 8,
2, 8, 8, 2
};
int alarm_animation[7][7]= {
{14,17,14,0,14,17,14}, // oh
{ 4, 4, 4,0,14,17,14}, // winka
{14,17,14,0, 4, 4, 4}, // winkb
{ 4, 4, 4,0, 4, 4, 4}, // zzz
{ 2, 4, 2,0, 2, 4, 2}}; // happy
// Ici se trouve le sous programme d'initialisation
void setup() {
// initialisation des sorties de la matrice 5X7.
for (int i= 0; i < 7; i++) pinMode(colonne[i], OUTPUT);
for (int i= 0; i < 5; i++) pinMode(ligne[i], OUTPUT);
//place tous les potentiels de colonne à 1 pour eteindre tous les points
for (int i= 0; i < 7; i++) digitalWrite(colonne[i], HIGH);
// initialisation du buzzer
pinMode(A2,OUTPUT);
// initialisation du DS1307
Serial.begin(57600);
rtc.begin();
rtc.adjust(DateTime(2016, 5, 19, 21, 24, 0));
}
// Ici se trouve l'ensemble des sous programmes
void affiche_colonne(byte motif,int col){
int masque=1;
digitalWrite(colonne[col],0);
for (int j=0;j<5;j++) {
digitalWrite(ligne[j],(masque & motif));
masque = masque<<1;
}
}
void efface_colonne(int col){
digitalWrite(colonne[col],1);
}
void affiche_heure(int D, int U, int d, int u){
int vitesse = 20;
for(int defile=19; defile>=0; defile--){
for (int tps=0; tps<vitesse; tps++ ){
for(int indice=0 ;indice<7; indice++){
affiche_colonne(dheure[D][indice+defile] + uheure[U][indice+defile] + dminute[d][indice+defile] + uminute[u][indice+defile], indice);
delay (2);
efface_colonne(indice);
}
}
}
}
// sous programme qui affiche l'animation de l'alarme
void affiche_alarm_animation(int a){
for(int repeat = 0; repeat<5; repeat ++){
for (int i=0; i<7; i++) {
affiche_colonne(alarm_animation[a][i],i);
delay(2);
efface_colonne(i);
}
}
int repeat=0;
}
// sous programme qui joue la mélodie de l'alarme
void melodie_alarm() {
for (int thisNote = 0; thisNote < 69; thisNote++) { // joue chaque note
int noteDuration = 1200/noteDurations[thisNote]; // Durée d'une note : 1200 ms divisé par la durée
tone(A2, melody[thisNote],noteDuration); // On joue la note
affiche_alarm_animation(random(1,7));
delay(noteDuration * 1.20);
noTone(A2);
affiche_alarm_animation(random(0,4));
}
}
// Ici se trouve le programme principale
void hi_buddy_main_program(int alarm_hour, int alarm_minute) { // initialisation de l'heure à la quelle on veut que l'alarme sonne.
DateTime now = rtc.now(); // sauvegarde l'heure actuelle
if ( now.hour() == alarm_hour && now.minute() == alarm_minute) { // si l'heure actuelle n'est pas égale à l'heure de l'alarme
melodie_alarm();
DateTime now = rtc.now();
}
else {
affiche_heure(now.hour()/10, now.hour()%10, now.minute()/10, now.minute()%10);
DateTime now = rtc.now();
}
}
void loop() {
hi_buddy_main_program(21,25);
}