Components and supplies
Pushbutton switch 12mm
Arduino Nano R3
Capacitor 100 µF
Resistor 10k ohm
Project description
Code
Door bell
arduino
1//----------------------------------------------------------------------- 2//-- Arduino DoorBell V1.1 01/2017 3//-- 48 songs 4//-- 5//-- Modif texte en memoire pgm 6//-- 7//-- 8//-- 9//-- Schoumacher P. 10//-- Inspired by R.HUTIN MicroSysteme 9/1981 11//-- Arduino Duemilanove or Diecimila 12//-- ATmega328 13//------------------------------------------------------------------------ 14 15 16#include <avr/pgmspace.h> 17#include <avr/sleep.h> 18#include <EEPROM.h> 19 20#define YES 1 21#define NO 0 22#define MIN_SONG 0 23#define MAX_SONG 47 24#define SPEAKER_PIN_OUT PCINT20 25#define SERIAL_SPEED 115200 26#define EXTERN_INTERRPT_PIN PCINT18 //INT0 PD2 27#define EEPROM_ADRESS 0 28 29 30char CurrentSong=0; 31char buffer[80]; 32volatile int Flg_Play_Song = NO; 33 34#define SERIALDEBUG 35#define WITHTITLE 36 37const char WAKE_UP[] PROGMEM = " ==>Wake-up"; 38const char SLEEP_MODE[] PROGMEM =" ==>Sleep Mode \ 39"; 40const char EXTERN_INTERRUPT[] PROGMEM ="(->Extern_Interrupt)\ 41"; 42 43#ifdef WITHTITLE 44const char title_0[] PROGMEM ="LA MARSEILLAISE"; 45const char title_1[] PROGMEM ="L'INTERNATIONALE"; 46const char title_2[] PROGMEM ="GOD SAVE THE QUEEN"; 47const char title_3[] PROGMEM ="LA TOULOUSAINE"; 48const char title_4[] PROGMEM ="LE CHANT DES PARTISANS"; 49const char title_5[] PROGMEM ="AVE MARIA"; 50const char title_6[] PROGMEM ="ALLELUIA DE PAQUES"; 51const char title_7[] PROGMEM ="MINUIT CHETIENS"; 52const char title_8[] PROGMEM ="AH;VOUS DIRAI-JE MAMAN"; 53const char title_9[] PROGMEM ="PLAISIR D'AMOUR"; 54const char title_10[] PROGMEM ="SE CANTO"; 55const char title_11[] PROGMEM ="LE TEMPS DES CERISES"; 56const char title_12[] PROGMEM ="ENVOI DE FLEURS"; 57const char title_13[] PROGMEM ="LA PAIMPLAISE"; 58const char title_14[] PROGMEM ="O MAGALI"; 59const char title_15[] PROGMEM ="CHANT DES ADIEUX"; 60const char title_16[] PROGMEM ="AU CLAIR DE LA LUNE"; 61const char title_17[] PROGMEM ="LA MERE MICHEL"; 62const char title_18[] PROGMEM ="IL ETAIT UN PETIT NAVIRE"; 63const char title_19[] PROGMEM ="LE ROI DAGOBERT"; 64const char title_20[] PROGMEM ="MALBROUGH"; 65const char title_21[] PROGMEM ="FRERES JACQUES"; 66const char title_22[] PROGMEM ="MON BEAU SAPIN"; 67const char title_23[] PROGMEM ="JOYEUX ANNIVERSAIRE"; 68const char title_24[] PROGMEM ="PETIT PAPA NOEL"; 69const char title_25[] PROGMEM ="LA MER"; 70const char title_26[] PROGMEM ="LES FEUILLES MORTES"; 71const char title_27[] PROGMEM ="PETITE FLEUR"; 72const char title_28[] PROGMEM ="Y A D'LA JOIE"; 73const char title_29[] PROGMEM ="TOUT VA TRES BIEN"; 74const char title_30[] PROGMEM ="PARLEZ MOI D'AMOUR"; 75const char title_31[] PROGMEM ="DE PROFONDIS MORPIONIBUS"; 76const char title_32[] PROGMEM ="MARCHE DES SOLDATS DE FAUST"; 77const char title_33[] PROGMEM ="MARCHE D'AIDA"; 78const char title_34[] PROGMEM ="AIR DU TOREADOR DE CARMEN"; 79const char title_35[] PROGMEM ="MARCHE NUPTIALE DU -SONGE D'UNE NUIT D'ETE -"; 80const char title_36[] PROGMEM ="HYMNE A LA NUIT D'HIPPOLYTE ET ARICIE"; 81const char title_37[] PROGMEM ="MARCHE DES ROIS DE L'ARLESIENNE"; 82const char title_38[] PROGMEM ="CHOEUR DES FIANCAILLES DE LOHENGRIN"; 83const char title_39[] PROGMEM ="HEURE EXQUISE DE LA VEUVE JOYEUSE"; 84const char title_40[] PROGMEM ="MARCHE TURQUE - MOZART -"; 85const char title_41[] PROGMEM ="HYMNE A LA JOIE - BEETHOVEN -"; 86const char title_42[] PROGMEM ="ETUDE - DITE TRISTESSE - CHOPIN -"; 87const char title_43[] PROGMEM ="REVERIE - SHUMANN -"; 88const char title_44[] PROGMEM ="LA TRUITE - SCHUBERT -"; 89const char title_45[] PROGMEM ="REVE D'AMOUR - LISZT -"; 90const char title_46[] PROGMEM ="TAMBOURIN - RAMEAU -"; 91const char title_47[] PROGMEM ="BERCEUSE - BRAHMS -"; 92 93const char* const title_table[] PROGMEM = {title_0 , title_1 , title_2 , title_3 , title_4 , title_5 , title_6 , title_7 , title_8 , title_9 , 94 title_10, title_11, title_12, title_13, title_14, title_15, title_16, title_17, title_18, title_19, 95 title_20, title_21, title_22, title_23, title_24, title_25, title_26, title_27, title_28, title_29, 96 title_30, title_31, title_32, title_33, title_34, title_35, title_36, title_37, title_38, title_39, 97 title_40, title_41, title_42, title_43, title_44, title_45, title_46, title_47 98 }; 99 100#endif 101 102const unsigned char ArrayMusic[] PROGMEM = { 103 0x20,/* 0 LA MARSEILLAISE */ 104 0x89,0x07,0x89,0x16,0x89,0x07,0x66,0x27, 105 0x66,0x27,0x5b,0x2c,0x5b,0x2c,0x44,0x58, 106 0x51,0x18,0x66,0x27,0x3c,0x41,0x44,0xa1, 107 0x51,0x0c,0x4c,0x27,0x5b,0x0b,0x66,0x75, 108 109 0x20,/* 1 L'INTERNATIONALE */ 110 0x66,0x15,0x4c,0x57,0x51,0x1b,0x44,0x21, 111 0x4c,0x1d,0x66,0x15,0x7a,0x12,0x5b,0x61, 112 0x73,0x4d,0x44,0x61,0x4c,0x1d,0x51,0x1b, 113 0x5b,0x18,0x66,0x15,0x73,0x13,0x7a,0x6e, 114 115 0x20,/* 2 GOD SAVE THE QUEEN */ 116 0x4c,0x4a,0x4c,0x4a,0x44,0x53,0x51,0x69, 117 0x4c,0x25,0x44,0x53,0x3c,0x5e,0x3c,0x5e, 118 0x38,0x63,0x3c,0x8d,0x44,0x29,0x4c,0x4a, 119 0x44,0x53,0x4c,0x4a,0x51,0x46,0x4c,0x95, 120 121 0x1e,/* 3 LA TOULOUSAINE */ 122 0x4c,0x9c,0x51,0x25,0x5b,0x0b,0x66,0x62, 123 0x7a,0x10,0x7a,0x18,0x7a,0x08,0x89,0x1d, 124 0x5b,0x21,0x5b,0x0b,0x66,0x27,0x51,0x25, 125 0x51,0x0c,0x4c,0x68,0x66,0x4e, 126 127 0x1e,/* 4 LE CHANT DES PARTISANS */ 128 0x66,0x2d,0x4c,0x3c,0x4c,0x2d,0x44,0x11, 129 0x3c,0x4c,0x3c,0x39,0x44,0x11,0x4c,0x3c, 130 0x4c,0x2d,0x51,0x0e,0x5b,0x32,0x66,0x16, 131 0x51,0x1c,0x5b,0x32,0x66,0x5a, 132 133 0x1a,/* 5 AVE MARIA */ 134 0x66,0x35,0x4c,0x8f,0x4c,0x47,0x51,0x87, 135 0x51,0x43,0x5b,0x3c,0x5b,0x3c,0x5b,0x3c, 136 0x44,0xa0,0x51,0x43,0x4c,0x8f,0x4c,0x47, 137 0x51,0x87, 138 139 0x1a,/* 6 ALLELUIA DE PAQUES */ 140 0x4c,0x1d,0x4c,0x3a,0x44,0x20,0x4c,0x1d, 141 0x51,0x1b,0x4c,0x1d,0x44,0x41,0x44,0x20, 142 0x66,0x41,0x44,0x41,0x40,0x22,0x44,0x61, 143 0x4c,0x57, 144 145 0x16,/* 7 MINUIT CHETIENS */ 146 0x7a,0x1b,0x7a,0x29,0x66,0x10,0x66,0x62, 147 0x66,0x20,0x5b,0x24,0x5b,0x24,0x73,0x2b, 148 0x5b,0x12,0x4c,0x57,0x66,0x62, 149 150 0x1c,/* 8 AH,VOUS DIRAI-JE MAMAN */ 151 0x9a,0x0e,0x9a,0x0e,0x66,0x15,0x66,0x15, 152 0x5b,0x18,0x5b,0x18,0x66,0x2b,0x73,0x13, 153 0x73,0x13,0x7a,0x12,0x7a,0x12,0x89,0x10, 154 0x89,0x10,0x9a,0x1d, 155 156 0x1e,/* 9 PLAISIR D'AMOUR */ 157 0x66,0x23,0x4c,0x8e,0x44,0xa0,0x3c,0xff, 158 0x3c,0x3b,0x38,0x7e,0x38,0x3f,0x3c,0x3b, 159 0x44,0x35,0x3c,0x3b,0x44,0xff,0x66,0x23, 160 0x5b,0x78,0x51,0x86,0x4c,0x2f, 161 162 0x18,/* 10 SE CANTO */ 163 0x89,0x24,0x66,0x31,0x66,0x31,0x51,0x1e, 164 0x5b,0x1b,0x66,0x31,0x66,0x31,0x66,0x18, 165 0x5b,0x1b,0x51,0x7b,0x51,0x3d,0x5b,0x6e, 166 167 0x1e,/* 11 LE TEMPS DES CERISES */ 168 0x89,0x10,0x66,0x16,0x66,0x16,0x66,0x16, 169 0x66,0x2d,0x66,0x16,0x5b,0x19,0x5b,0x19, 170 0x5b,0x19,0x5b,0x32,0x5b,0x19,0x51,0x1c, 171 0x51,0x1c,0x51,0x1c,0x51,0x39, 172 173 0x1e,/* 12 ENVOI DE FLEURS */ 174 0x66,0x15,0x66,0x15,0x5b,0x18,0x51,0x1b, 175 0x4c,0x3a,0x44,0x20,0x4c,0x1d,0x51,0x1b, 176 0x5b,0x18,0x66,0x2b,0x66,0x15,0x73,0x13, 177 0x66,0x15,0x5b,0x18,0x7a,0x24, 178 179 0x20,/* 13 LA PAIMPLAISE */ 180 0x44,0x50,0x4c,0x23,0x51,0x43,0x51,0x43, 181 0x44,0x28,0x4c,0x23,0x51,0x43,0x51,0x43, 182 0x66,0x1a,0x5b,0x1e,0x51,0x43,0x51,0x21, 183 0x51,0x21,0x5b,0x1e,0x66,0x1a,0x5b,0x78, 184 185 0x1c,/* 14 O MAGALI */ 186 0x51,0x1b,0x51,0x1b,0x51,0x1b,0x51,0x36, 187 0x5b,0x18,0x44,0x41,0x4c,0x1d,0x51,0x1b, 188 0x5b,0x18,0x66,0x15,0x5b,0x18,0x5b,0x18, 189 0x5b,0x18,0x5b,0x30, 190 191 0x1c,/* 15 CHANT DES ADIEUX */ 192 0x89,0x23,0x66,0x46,0x66,0x17,0x66,0x2e, 193 0x51,0x3b,0x5b,0x4f,0x66,0x17,0x5b,0x34, 194 0x51,0x3b,0x66,0x46,0x66,0x17,0x51,0x3b, 195 0x44,0x46,0x3c,0xec, 196 197 0x16,/* 16 AU CLAIR DE LA LUNE */ 198 0x4c,0x20,0x4c,0x20,0x4c,0x20,0x44,0x24, 199 0x3c,0x52,0x44,0x49,0x4c,0x20,0x3c,0x29, 200 0x44,0x24,0x44,0x24,0x4c,0x82, 201 202 0x16,/* 17 LA MERE MICHEL */ 203 0x4c,0x2d,0x4c,0x0f,0x4c,0x1e,0x4c,0x1e, 204 0x4c,0x1e,0x66,0x16,0x4c,0x1e,0x44,0x21, 205 0x3c,0x4c,0x44,0x43,0x4c,0x5a, 206 207 0x1a,/* 18 IL ETAIT UN PETIT NAVIRE */ 208 0x3c,0x29,0x3c,0x29,0x3c,0x29,0x66,0x31, 209 0x3c,0x52,0x38,0x2b,0x3c,0x29,0x3c,0x52, 210 0x44,0x24,0x44,0x24,0x44,0x24,0x44,0x24, 211 0x66,0x31, 212 213 0x1c,/* 19 LE ROI DAGOBERT */ 214 0x3c,0x1b,0x3c,0x36,0x44,0x18,0x44,0x30, 215 0x4c,0x15,0x4c,0x41,0x44,0x49,0x3c,0x1b, 216 0x38,0x1d,0x3c,0x1b,0x44,0x18,0x4c,0x15, 217 0x44,0x18,0x4c,0x41, 218 219 0x20,/* 20 MALBROUGH */ 220 0x89,0x0b,0x51,0x27,0x51,0x13,0x51,0x27, 221 0x5b,0x11,0x4c,0x3e,0x51,0x13,0x4c,0x14, 222 0x51,0x13,0x5b,0x23,0x5b,0x11,0x5b,0x11, 223 0x66,0x0f,0x5b,0x11,0x51,0x3b,0x66,0x1f, 224 225 0x1c,/* 21 FRERES JACQUES */ 226 0x66,0x33,0x5b,0x39,0x51,0x40,0x66,0x33, 227 0x66,0x33,0x5b,0x39,0x51,0x40,0x66,0x33, 228 0x51,0x40,0x4c,0x44,0x44,0xa2,0x51,0x40, 229 0x4c,0x44,0x44,0xa2, 230 231 0x1e,/* 22 MON BEAU SAPIN */ 232 0x66,0x38,0x4c,0x38,0x4c,0x12,0x4c,0x4a, 233 0x44,0x53,0x3c,0x46,0x3c,0x17,0x3c,0x8b, 234 0x4c,0x25,0x44,0x29,0x3c,0x2f,0x38,0x63, 235 0x51,0x46,0x44,0x53,0x4c,0x4a, 236 237 0x18,/* 23 JOYEUX ANNIVERSAIRE */ 238 0x66,0x14,0x66,0x14,0x5b,0x2d,0x66,0x28, 239 0x4c,0x36,0x51,0x66,0x66,0x14,0x66,0x14, 240 0x5b,0x2d,0x66,0x28,0x44,0x3c,0x4c,0x6c, 241 242 0x1a,/* 24 PETIT PAPA NOEL */ 243 0x66,0x2f,0x4c,0x3e,0x4c,0x3e,0x4c,0x3e, 244 0x44,0x46,0x4c,0xbc,0x4c,0x1f,0x44,0x23, 245 0x3c,0x4f,0x3c,0x4f,0x3c,0x4f,0x38,0x53, 246 0x3c,0xed, 247 248 0x20,/* 25 LA MER */ 249 0x66,0x23,0x4c,0xca,0x51,0x1f,0x4c,0x21, 250 0x44,0x25,0x3c,0x7f,0x4c,0x21,0x44,0x4b, 251 0x51,0x1f,0x5b,0x1c,0x66,0x19,0x3c,0xff, 252 0x44,0x25,0x3c,0x2a,0x38,0x2c,0x32,0x4b, 253 254 0x20,/* 26 LES FEUILLES MORTES */ 255 0x5b,0x11,0x51,0x1d,0x4c,0x0a,0x38,0xff, 256 0x66,0x0f,0x5b,0x19,0x51,0x0a,0x3c,0xf0, 257 0x73,0x0d,0x66,0x17,0x5b,0x08,0x44,0xd6, 258 0x7a,0x0d,0x6d,0x16,0x61,0x08,0x4c,0x54, 259 260 0x1e,/* 27 PETITE FLEUR */ 261 0x73,0x30,0x73,0x18,0x7a,0x9f,0x61,0x1c, 262 0x51,0x22,0x44,0x28,0x38,0x30,0x3c,0x2d, 263 0x4c,0xfc,0x7a,0x16,0x5b,0x24,0x51,0x22, 264 0x4c,0x24,0x5b,0x1e,0x51,0xcc, 265 266 0x1e,/* 28 Y A D'LA JOIE */ 267 0x51,0x16,0x44,0x1a,0x51,0x70,0x89,0x0d, 268 0x7a,0x0f,0x6d,0x10,0x66,0x11,0x5b,0x14, 269 0x51,0x16,0x4c,0x17,0x44,0x1a,0x44,0x1a, 270 0x51,0x16,0x44,0x1a,0x51,0x70, 271 272 0x1e,/* 29 TOUT VA TRES BIEN */ 273 0x44,0x1a,0x51,0x16,0x5b,0x14,0x66,0x35, 274 0x51,0x16,0x5b,0x1e,0x66,0x09,0x6d,0x10, 275 0x7a,0x0f,0x89,0x1a,0x89,0x28,0x44,0x1a, 276 0x51,0x16,0x5b,0x14,0x66,0x23, 277 278 0x1c,/* 30 PARLEZ MOI D'AMOUR */ 279 0x51,0x52,0x51,0x29,0x5b,0x49,0x5b,0x24, 280 0x66,0xa3,0x66,0x20,0x5b,0x24,0x66,0x20, 281 0x5b,0x24,0x51,0x29,0x5b,0x24,0x66,0x20, 282 0x7a,0x52,0x7a,0x52, 283 284 0x1e,/* 31 DE PROFONDIS MORPIONIBUS */ 285 0x7a,0x3c,0x66,0x23,0x5b,0x28,0x51,0xb3, 286 0x3c,0x77,0x44,0x35,0x3c,0x3c,0x51,0xb3, 287 0x5b,0x3c,0x51,0x16,0x4c,0x2f,0x5b,0x28, 288 0x66,0x35,0x5b,0x14,0x51,0x59, 289 290 0x20,/* 32 MARCHE DES SOLDATS DE FAUST */ 291 0x66,0x51,0x89,0x1e,0x66,0x28,0x5b,0x0f, 292 0x51,0x11,0x66,0x0d,0x5b,0x1e,0x5b,0x0f, 293 0x44,0x79,0x51,0x66,0x66,0x28,0x7a,0x22, 294 0x6d,0x0c,0x66,0x0d,0x7a,0x0b,0x6d,0x19, 295 296 0x1c,/* 33 MARCHE D'AIDA */ 297 0x89,0x20,0x66,0x82,0x5b,0x10,0x89,0x0a, 298 0x5b,0x10,0x51,0x36,0x51,0x36,0x51,0x36, 299 0x51,0x12,0x4c,0x13,0x66,0x0e,0x51,0x5b, 300 0x5b,0x10,0x66,0x2b, 301 302 0x1c,/* 34 AIR DU TOREADOR DE CARMEN */ 303 0x44,0x41,0x3c,0x36,0x44,0x10,0x51,0x36, 304 0x51,0x36,0x51,0x29,0x5b,0x0c,0x51,0x29, 305 0x4c,0x0e,0x51,0x6d,0x4c,0x3a,0x5b,0x24, 306 0x44,0x10,0x51,0x6d, 307 308 0x1c,/* 35 MARCHE NUPTIALE DU -SONGE D'UNE NUIT D'ETE -*/ 309 0x38,0x57,0x3c,0x3d,0x51,0x0f,0x44,0x24, 310 0x4c,0x20,0x56,0x1d,0x66,0x18,0x73,0x15, 311 0x7a,0x0f,0x73,0x05,0x66,0x18,0x9a,0x0c, 312 0x66,0x06,0x5b,0x37, 313 314 0x20,/* 36 HYMNE A LA NUIT D'HIPPOLYTE ET ARICIE */ 315 0x7a,0x42,0x89,0x75,0x66,0x4e,0x7a,0x42, 316 0x9a,0x34,0x73,0x8b,0x7a,0x21,0x89,0x1d, 317 0x7a,0x42,0x9a,0x68,0x4c,0x68,0x4c,0x34, 318 0x51,0x31,0x5b,0x2c,0x66,0x27,0x6d,0x94, 319 320 0x1a,/* 37 MARCHE DES ROIS DE L'ARLESIENNE */ 321 0x66,0x26,0x89,0x1c,0x66,0x3a,0x5b,0x16, 322 0x56,0x22,0x5b,0x0a,0x56,0x22,0x66,0x0a, 323 0x44,0x58,0x56,0x16,0x4c,0x34,0x44,0x3a, 324 0x40,0x3e, 325 326 0x1e,/* 38 CHOEUR DES FIANCAILLES DE LOHENGRIN */ 327 0x89,0x2e,0x66,0x2e,0x66,0x0f,0x66,0x7b, 328 0x89,0x2e,0x5b,0x34,0x6d,0x0e,0x66,0x7b, 329 0x89,0x2e,0x66,0x1e,0x4c,0x29,0x4c,0x52, 330 0x51,0x27,0x5b,0x22,0x66,0x3d, 331 332 0x1e,/* 39 HEURE EXQUISE DE LA VEUVE JOYEUSE*/ 333 0x89,0x33,0x66,0x22,0x5b,0x4c,0x51,0x2a, 334 0x89,0x33,0x66,0x22,0x5b,0x4c,0x51,0x2a, 335 0x4c,0x88,0x51,0x80,0x5b,0xe5,0x89,0x33, 336 0x5b,0x26,0x51,0x55,0x4c,0x2d, 337 338 0x1c,/* 40 MARCHE TURQUE - MOZART -*/ 339 0x89,0x08,0x9a,0x07,0xa4,0x06,0x9a,0x07, 340 0x82,0x22,0x73,0x09,0x82,0x09,0x89,0x08, 341 0x82,0x09,0x66,0x2b,0x61,0x0b,0x73,0x09, 342 0x6d,0x0a,0x66,0x0b, 343 344 0x1e,/* 41 HYMNE A LA JOIE - BEETHOVEN -*/ 345 0x51,0x1b,0x51,0x1b,0x4c,0x1d,0x44,0x20, 346 0x44,0x20,0x4c,0x1d,0x51,0x1b,0x5b,0x18, 347 0x66,0x15,0x66,0x15,0x5b,0x18,0x51,0x1b, 348 0x51,0x29,0x5b,0x0c,0x5b,0x30, 349 350 0x1a,/* 42 ETUDE - DITE TRISTESSE - CHOPIN - */ 351 0x89,0x28,0x66,0x6a,0x6d,0x32,0x66,0x35, 352 0x5b,0xb4,0x51,0x43,0x51,0x43,0x5b,0x3c, 353 0x51,0xca,0x4c,0x47,0x4c,0x47,0x51,0x43, 354 0x3c,0xb3, 355 356 0x1e,/* 43 REVERIE - SHUMANN - */ 357 0x9a,0x2d,0x73,0x5b,0x7a,0x1c,0x73,0x1e, 358 0x5b,0x26,0x4c,0x2d,0x38,0x3c,0x38,0x79, 359 0x3c,0x39,0x44,0x33,0x4c,0x2d,0x38,0x3c, 360 0x66,0x22,0x5b,0x26,0x56,0x51, 361 362 0x1e,/* 44 LA TRUITE - SCHUBERT -*/ 363 0x66,0x16,0x4c,0x1e,0x4c,0x1e,0x3c,0x26, 364 0x3c,0x26,0x4c,0x3c,0x66,0x16,0x66,0x16, 365 0x66,0x43,0x66,0x16,0x44,0x21,0x4c,0x1e, 366 0x51,0x1c,0x5b,0x19,0x66,0x43, 367 368 0x20,/* 45 REVE D'AMOUR - LISZT -*/ 369 0x89,0x15,0x51,0x69,0x51,0x69,0x51,0xb0, 370 0x51,0x23,0x51,0x46,0x51,0x23,0x4c,0x4a, 371 0x51,0x23,0x51,0x69,0x7a,0x2f,0x7a,0x17, 372 0x7a,0x17,0x6d,0x1a,0x66,0x1c,0x51,0x46, 373 374 0x1e,/* 46 TAMBOURIN - RAMEAU -*/ 375 0x89,0x09,0x7a,0x0a,0x73,0x0a,0x7a,0x0a, 376 0x89,0x11,0x5b,0x1a,0x5b,0x1a,0x66,0x17, 377 0x73,0x14,0x7a,0x13,0x89,0x09,0x7a,0x0a, 378 0x73,0x0a,0x66,0x0b,0x5b,0x1a, 379 380 0x1a,/* 47 BERCEUSE - BRAHMS -*/ 381 0x7a,0x1e,0x7a,0x0a,0x66,0x62,0x7a,0x1e, 382 0x7a,0x0a,0x66,0x62,0x7a,0x14,0x66,0x18, 383 0x4c,0x41,0x51,0x3d,0x5b,0x37,0x5b,0x37, 384 0x66,0x31, 385 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff 386 }; 387 388int frequence[][2]= 389{ 390 {0x32,784}, 391 {0x35,740}, 392 {0x38,698}, 393 {0x3C,659}, 394 {0x40,622}, 395 {0x44,587}, 396 {0x48,554}, 397 {0x4C,523}, 398 {0x51,494}, 399 {0x56,466}, 400 {0x5B,440}, 401 {0x61,415}, 402 {0x66,392}, 403 {0x6D,370}, 404 {0x73,349}, 405 {0x7A,330}, 406 {0x82,311}, 407 {0x89,294}, 408 {0x92,277}, 409 {0x9A,262}, 410 {0xA4,247}, 411 {0xAE,233}, 412 {0xB8,220}, 413 {0xC3,208}, 414 {0xC7,196}, 415 {0x00, 0}, 416 {-1 , -1} 417}; 418/* 419****-------------------------------------------------------------------- 420 421****-------------------------------------------------------------------- 422*/ 423int Get_Frequency(int val) 424{ 425 int i=0; 426 427 for(i=0;frequence[i][0]!= -1;i++) 428 { 429 if( frequence[i][0] == val ) 430 return(frequence[i][1]); 431 } 432 433 sprintf(buffer,"ERROR Get_Frequency=%x ",val); 434 PrintSerial(buffer); 435 436 return(0); 437} 438 439/* 440****-------------------------------------------------------------------- 441 442****-------------------------------------------------------------------- 443*/ 444unsigned char music( int off ) 445{ 446 return( pgm_read_byte_near( ArrayMusic + off ) ); 447} 448 449 450#ifdef WITHTITLE 451/* 452****-------------------------------------------------------------------- 453 454****-------------------------------------------------------------------- 455*/ 456void Get_Tittle(short off) 457{ 458 char buff[80]; 459 strcpy_P(buff, (char*)pgm_read_word(&(title_table[off]))); 460 461 sprintf(buffer,"****[ %s ]****",(buff)); 462 463} 464#endif 465 466/* 467****-------------------------------------------------------------------- 468 469****-------------------------------------------------------------------- 470*/ 471int Walk_Music(char song) 472{ 473 int offset=0; 474 int fnd=song; 475 476 for(fnd=0;fnd < song;fnd++) 477 offset = offset + music(offset) + 1; 478 479 return(++offset); 480} 481/* 482****-------------------------------------------------------------------- 483 484****-------------------------------------------------------------------- 485*/ 486int Get_Offset_Of_Song_Start(char song) 487{ 488 int offset=0; 489 490 offset = Walk_Music(song); 491 492 sprintf(buffer,"Get_Offset_Of_Song_Start=%d ",offset); 493 PrintSerial(buffer); 494 495 return(offset); 496} 497 498/* 499****-------------------------------------------------------------------- 500 501****-------------------------------------------------------------------- 502*/ 503int Get_Number_Of_Music_Note(char song) 504{ 505 int len=0; 506 507 int offset = Walk_Music(song); 508 len = music( --offset ); 509 510 sprintf(buffer,"Get_Number_Of_Music_Note=%x ",len); 511 PrintSerial(buffer); 512 513 return(len); 514} 515 516 517/* 518****-------------------------------------------------------------------- 519 520****-------------------------------------------------------------------- 521*/ 522void Play_Song() 523{ 524 525 if( CurrentSong < MIN_SONG || CurrentSong > MAX_SONG ) 526 CurrentSong = MIN_SONG; 527 528 sprintf(buffer,"Play_Song=(%d) ",CurrentSong); 529 PrintSerial(buffer); 530 531#ifdef WITHTITLE 532 Get_Tittle(CurrentSong); 533 PrintSerial(buffer); 534#endif 535 536 537 Read_Song(CurrentSong); 538 539 540} 541 542/* 543****-------------------------------------------------------------------- 544 545****-------------------------------------------------------------------- 546*/ 547void Set_Next_Song() 548{ 549 CurrentSong++; 550} 551 552/* 553****-------------------------------------------------------------------- 554 555****-------------------------------------------------------------------- 556*/ 557void Read_Song( char song ) 558{ 559 int offset=0; 560 int maxnote=0; 561 int frq; //frequency 562 int lgt; //length frequency 563 564 565 if( song < MIN_SONG || song > MAX_SONG ) 566 song = MIN_SONG; 567 568 offset = Get_Offset_Of_Song_Start( song ); 569 maxnote = Get_Number_Of_Music_Note( song ); 570 571 //sprintf(buffer,"offset=%x maxnote=%x",offset,maxnote); 572 //PrintSerial(buffer); 573 574 if( maxnote > 0 ) 575 { 576 do{ 577 578 sprintf(buffer,"song(%d) => %x,%x ",song,music(offset),music(offset+1)); 579 PrintSerial(buffer); 580 581 frq = Get_Frequency( music(offset) ); 582 lgt = music(offset+1); 583 584 offset+=2; 585 586 tone(SPEAKER_PIN_OUT,frq); 587 delay( lgt * 8); 588 589 maxnote = maxnote -2; 590 591 }while( maxnote > 0 ); 592 } 593 594 noTone(SPEAKER_PIN_OUT); 595} 596 597/* 598****-------------------------------------------------------------------- 599 600****-------------------------------------------------------------------- 601*/ 602void Extern_Interrupt() 603{ 604 noInterrupts(); 605 606 if( Flg_Play_Song == NO ) 607 Flg_Play_Song = YES; 608 609 interrupts(); 610} 611 612/* 613****-------------------------------------------------------------------- 614 615****-------------------------------------------------------------------- 616*/ 617void Save_Current_Song() 618{ 619 620 if( CurrentSong < MIN_SONG || CurrentSong > MAX_SONG ) 621 CurrentSong = MIN_SONG; 622 623 EEPROM.write(EEPROM_ADRESS,CurrentSong); 624} 625 626/* 627****-------------------------------------------------------------------- 628 629****-------------------------------------------------------------------- 630*/ 631void Load_Current_Song() 632{ 633 CurrentSong = EEPROM.read(EEPROM_ADRESS); 634 635 if( CurrentSong < MIN_SONG || CurrentSong > MAX_SONG ) 636 { 637 CurrentSong = MIN_SONG; 638 Save_Current_Song(); 639 } 640} 641/* 642****-------------------------------------------------------------------- 643 644****-------------------------------------------------------------------- 645*/ 646void setup() 647{ 648 // put your setup code here, to run once: 649 Serial.begin(SERIAL_SPEED); 650 651 Load_Current_Song(); 652 653 PrintSerial("DoorBell V1.0: Schoumacher Patrice 2017/01"); 654 PrintSerial(" : Inspired by R.HUTIN MicroSysteme 9/1981"); 655 656 sprintf(buffer,"Taille EEPROM=%d",EEPROM.length()); 657 PrintSerial(buffer); 658 659 sprintf(buffer," ->Current_Song=%d ",CurrentSong); 660 PrintSerial(buffer); 661 662 sprintf(buffer," SPEAKER_PIN_OUT=%d ",SPEAKER_PIN_OUT); 663 PrintSerial(buffer); 664 sprintf(buffer," EXTERN_INTERRPT_PIN=%d ",EXTERN_INTERRPT_PIN); 665 PrintSerial(buffer); 666 667 pinMode(LED_BUILTIN, OUTPUT); 668 Intern_Led(LOW); 669 670 pinMode(SPEAKER_PIN_OUT, OUTPUT); // no song HP 671 pinMode(EXTERN_INTERRPT_PIN, INPUT_PULLUP); // External interrupt Pin 2 672 673 attachInterrupt(digitalPinToInterrupt(EXTERN_INTERRPT_PIN), Extern_Interrupt, FALLING); 674 675 set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep Mode => save battery 676 677} 678 679void Intern_Led(int val) 680{ 681 digitalWrite(LED_BUILTIN, val); 682} 683/* 684****-------------------------------------------------------------------- 685 686****-------------------------------------------------------------------- 687*/ 688void PrintSerial(const char *text) 689{ 690#ifdef SERIALDEBUG 691 Serial.println(text); 692 Serial.flush(); // while (!(UCSR0A & _BV(TXC0))); // wait for empty serial print bufferer 693 #endif 694} 695 696/* 697****-------------------------------------------------------------------- 698For decrease memory impact with string 699****-------------------------------------------------------------------- 700*/ 701void PrintSerialF(const char *text) 702{ 703#ifdef SERIALDEBUG 704 Serial.print((const __FlashStringHelper *) text); 705 Serial.flush(); 706 #endif 707} 708/* 709****-------------------------------------------------------------------- 710 711****-------------------------------------------------------------------- 712*/ 713void loop() { 714 715 Load_Current_Song(); 716 717 if( Flg_Play_Song == YES ) 718 { 719 Intern_Led(HIGH); 720 Flg_Play_Song = NO; 721 722 Play_Song(); 723 724 Set_Next_Song(); 725 726 Save_Current_Song(); 727 Intern_Led(LOW); 728 } 729 730 PrintSerialF(SLEEP_MODE); 731 732 sleep_mode(); // Sleep mode activ until external interrupt 733 sleep_disable(); 734 735 PrintSerialF(EXTERN_INTERRUPT); 736 737 PrintSerialF(WAKE_UP); 738 739} 740
Door bell
arduino
1//----------------------------------------------------------------------- 2//-- Arduino DoorBell V1.1 01/2017 3//-- 48 songs 4//-- 5//-- Modif texte en memoire pgm 6//-- 7//-- 8//-- 9//-- Schoumacher P. 10//-- Inspired by R.HUTIN MicroSysteme 9/1981 11//-- Arduino Duemilanove or Diecimila 12//-- ATmega328 13//------------------------------------------------------------------------ 14 15 16#include <avr/pgmspace.h> 17#include <avr/sleep.h> 18#include <EEPROM.h> 19 20#define YES 1 21#define NO 0 22#define MIN_SONG 0 23#define MAX_SONG 47 24#define SPEAKER_PIN_OUT PCINT20 25#define SERIAL_SPEED 115200 26#define EXTERN_INTERRPT_PIN PCINT18 //INT0 PD2 27#define EEPROM_ADRESS 0 28 29 30char CurrentSong=0; 31char buffer[80]; 32volatile int Flg_Play_Song = NO; 33 34#define SERIALDEBUG 35#define WITHTITLE 36 37const char WAKE_UP[] PROGMEM = " ==>Wake-up"; 38const char SLEEP_MODE[] PROGMEM =" ==>Sleep Mode \ 39"; 40const char EXTERN_INTERRUPT[] PROGMEM ="(->Extern_Interrupt)\ 41"; 42 43#ifdef WITHTITLE 44const char title_0[] PROGMEM ="LA MARSEILLAISE"; 45const char title_1[] PROGMEM ="L'INTERNATIONALE"; 46const char title_2[] PROGMEM ="GOD SAVE THE QUEEN"; 47const char title_3[] PROGMEM ="LA TOULOUSAINE"; 48const char title_4[] PROGMEM ="LE CHANT DES PARTISANS"; 49const char title_5[] PROGMEM ="AVE MARIA"; 50const char title_6[] PROGMEM ="ALLELUIA DE PAQUES"; 51const char title_7[] PROGMEM ="MINUIT CHETIENS"; 52const char title_8[] PROGMEM ="AH;VOUS DIRAI-JE MAMAN"; 53const char title_9[] PROGMEM ="PLAISIR D'AMOUR"; 54const char title_10[] PROGMEM ="SE CANTO"; 55const char title_11[] PROGMEM ="LE TEMPS DES CERISES"; 56const char title_12[] PROGMEM ="ENVOI DE FLEURS"; 57const char title_13[] PROGMEM ="LA PAIMPLAISE"; 58const char title_14[] PROGMEM ="O MAGALI"; 59const char title_15[] PROGMEM ="CHANT DES ADIEUX"; 60const char title_16[] PROGMEM ="AU CLAIR DE LA LUNE"; 61const char title_17[] PROGMEM ="LA MERE MICHEL"; 62const char title_18[] PROGMEM ="IL ETAIT UN PETIT NAVIRE"; 63const char title_19[] PROGMEM ="LE ROI DAGOBERT"; 64const char title_20[] PROGMEM ="MALBROUGH"; 65const char title_21[] PROGMEM ="FRERES JACQUES"; 66const char title_22[] PROGMEM ="MON BEAU SAPIN"; 67const char title_23[] PROGMEM ="JOYEUX ANNIVERSAIRE"; 68const char title_24[] PROGMEM ="PETIT PAPA NOEL"; 69const char title_25[] PROGMEM ="LA MER"; 70const char title_26[] PROGMEM ="LES FEUILLES MORTES"; 71const char title_27[] PROGMEM ="PETITE FLEUR"; 72const char title_28[] PROGMEM ="Y A D'LA JOIE"; 73const char title_29[] PROGMEM ="TOUT VA TRES BIEN"; 74const char title_30[] PROGMEM ="PARLEZ MOI D'AMOUR"; 75const char title_31[] PROGMEM ="DE PROFONDIS MORPIONIBUS"; 76const char title_32[] PROGMEM ="MARCHE DES SOLDATS DE FAUST"; 77const char title_33[] PROGMEM ="MARCHE D'AIDA"; 78const char title_34[] PROGMEM ="AIR DU TOREADOR DE CARMEN"; 79const char title_35[] PROGMEM ="MARCHE NUPTIALE DU -SONGE D'UNE NUIT D'ETE -"; 80const char title_36[] PROGMEM ="HYMNE A LA NUIT D'HIPPOLYTE ET ARICIE"; 81const char title_37[] PROGMEM ="MARCHE DES ROIS DE L'ARLESIENNE"; 82const char title_38[] PROGMEM ="CHOEUR DES FIANCAILLES DE LOHENGRIN"; 83const char title_39[] PROGMEM ="HEURE EXQUISE DE LA VEUVE JOYEUSE"; 84const char title_40[] PROGMEM ="MARCHE TURQUE - MOZART -"; 85const char title_41[] PROGMEM ="HYMNE A LA JOIE - BEETHOVEN -"; 86const char title_42[] PROGMEM ="ETUDE - DITE TRISTESSE - CHOPIN -"; 87const char title_43[] PROGMEM ="REVERIE - SHUMANN -"; 88const char title_44[] PROGMEM ="LA TRUITE - SCHUBERT -"; 89const char title_45[] PROGMEM ="REVE D'AMOUR - LISZT -"; 90const char title_46[] PROGMEM ="TAMBOURIN - RAMEAU -"; 91const char title_47[] PROGMEM ="BERCEUSE - BRAHMS -"; 92 93const char* const title_table[] PROGMEM = {title_0 , title_1 , title_2 , title_3 , title_4 , title_5 , title_6 , title_7 , title_8 , title_9 , 94 title_10, title_11, title_12, title_13, title_14, title_15, title_16, title_17, title_18, title_19, 95 title_20, title_21, title_22, title_23, title_24, title_25, title_26, title_27, title_28, title_29, 96 title_30, title_31, title_32, title_33, title_34, title_35, title_36, title_37, title_38, title_39, 97 title_40, title_41, title_42, title_43, title_44, title_45, title_46, title_47 98 }; 99 100#endif 101 102const unsigned char ArrayMusic[] PROGMEM = { 103 0x20,/* 0 LA MARSEILLAISE */ 104 0x89,0x07,0x89,0x16,0x89,0x07,0x66,0x27, 105 0x66,0x27,0x5b,0x2c,0x5b,0x2c,0x44,0x58, 106 0x51,0x18,0x66,0x27,0x3c,0x41,0x44,0xa1, 107 0x51,0x0c,0x4c,0x27,0x5b,0x0b,0x66,0x75, 108 109 0x20,/* 1 L'INTERNATIONALE */ 110 0x66,0x15,0x4c,0x57,0x51,0x1b,0x44,0x21, 111 0x4c,0x1d,0x66,0x15,0x7a,0x12,0x5b,0x61, 112 0x73,0x4d,0x44,0x61,0x4c,0x1d,0x51,0x1b, 113 0x5b,0x18,0x66,0x15,0x73,0x13,0x7a,0x6e, 114 115 0x20,/* 2 GOD SAVE THE QUEEN */ 116 0x4c,0x4a,0x4c,0x4a,0x44,0x53,0x51,0x69, 117 0x4c,0x25,0x44,0x53,0x3c,0x5e,0x3c,0x5e, 118 0x38,0x63,0x3c,0x8d,0x44,0x29,0x4c,0x4a, 119 0x44,0x53,0x4c,0x4a,0x51,0x46,0x4c,0x95, 120 121 0x1e,/* 3 LA TOULOUSAINE */ 122 0x4c,0x9c,0x51,0x25,0x5b,0x0b,0x66,0x62, 123 0x7a,0x10,0x7a,0x18,0x7a,0x08,0x89,0x1d, 124 0x5b,0x21,0x5b,0x0b,0x66,0x27,0x51,0x25, 125 0x51,0x0c,0x4c,0x68,0x66,0x4e, 126 127 0x1e,/* 4 LE CHANT DES PARTISANS */ 128 0x66,0x2d,0x4c,0x3c,0x4c,0x2d,0x44,0x11, 129 0x3c,0x4c,0x3c,0x39,0x44,0x11,0x4c,0x3c, 130 0x4c,0x2d,0x51,0x0e,0x5b,0x32,0x66,0x16, 131 0x51,0x1c,0x5b,0x32,0x66,0x5a, 132 133 0x1a,/* 5 AVE MARIA */ 134 0x66,0x35,0x4c,0x8f,0x4c,0x47,0x51,0x87, 135 0x51,0x43,0x5b,0x3c,0x5b,0x3c,0x5b,0x3c, 136 0x44,0xa0,0x51,0x43,0x4c,0x8f,0x4c,0x47, 137 0x51,0x87, 138 139 0x1a,/* 6 ALLELUIA DE PAQUES */ 140 0x4c,0x1d,0x4c,0x3a,0x44,0x20,0x4c,0x1d, 141 0x51,0x1b,0x4c,0x1d,0x44,0x41,0x44,0x20, 142 0x66,0x41,0x44,0x41,0x40,0x22,0x44,0x61, 143 0x4c,0x57, 144 145 0x16,/* 7 MINUIT CHETIENS */ 146 0x7a,0x1b,0x7a,0x29,0x66,0x10,0x66,0x62, 147 0x66,0x20,0x5b,0x24,0x5b,0x24,0x73,0x2b, 148 0x5b,0x12,0x4c,0x57,0x66,0x62, 149 150 0x1c,/* 8 AH,VOUS DIRAI-JE MAMAN */ 151 0x9a,0x0e,0x9a,0x0e,0x66,0x15,0x66,0x15, 152 0x5b,0x18,0x5b,0x18,0x66,0x2b,0x73,0x13, 153 0x73,0x13,0x7a,0x12,0x7a,0x12,0x89,0x10, 154 0x89,0x10,0x9a,0x1d, 155 156 0x1e,/* 9 PLAISIR D'AMOUR */ 157 0x66,0x23,0x4c,0x8e,0x44,0xa0,0x3c,0xff, 158 0x3c,0x3b,0x38,0x7e,0x38,0x3f,0x3c,0x3b, 159 0x44,0x35,0x3c,0x3b,0x44,0xff,0x66,0x23, 160 0x5b,0x78,0x51,0x86,0x4c,0x2f, 161 162 0x18,/* 10 SE CANTO */ 163 0x89,0x24,0x66,0x31,0x66,0x31,0x51,0x1e, 164 0x5b,0x1b,0x66,0x31,0x66,0x31,0x66,0x18, 165 0x5b,0x1b,0x51,0x7b,0x51,0x3d,0x5b,0x6e, 166 167 0x1e,/* 11 LE TEMPS DES CERISES */ 168 0x89,0x10,0x66,0x16,0x66,0x16,0x66,0x16, 169 0x66,0x2d,0x66,0x16,0x5b,0x19,0x5b,0x19, 170 0x5b,0x19,0x5b,0x32,0x5b,0x19,0x51,0x1c, 171 0x51,0x1c,0x51,0x1c,0x51,0x39, 172 173 0x1e,/* 12 ENVOI DE FLEURS */ 174 0x66,0x15,0x66,0x15,0x5b,0x18,0x51,0x1b, 175 0x4c,0x3a,0x44,0x20,0x4c,0x1d,0x51,0x1b, 176 0x5b,0x18,0x66,0x2b,0x66,0x15,0x73,0x13, 177 0x66,0x15,0x5b,0x18,0x7a,0x24, 178 179 0x20,/* 13 LA PAIMPLAISE */ 180 0x44,0x50,0x4c,0x23,0x51,0x43,0x51,0x43, 181 0x44,0x28,0x4c,0x23,0x51,0x43,0x51,0x43, 182 0x66,0x1a,0x5b,0x1e,0x51,0x43,0x51,0x21, 183 0x51,0x21,0x5b,0x1e,0x66,0x1a,0x5b,0x78, 184 185 0x1c,/* 14 O MAGALI */ 186 0x51,0x1b,0x51,0x1b,0x51,0x1b,0x51,0x36, 187 0x5b,0x18,0x44,0x41,0x4c,0x1d,0x51,0x1b, 188 0x5b,0x18,0x66,0x15,0x5b,0x18,0x5b,0x18, 189 0x5b,0x18,0x5b,0x30, 190 191 0x1c,/* 15 CHANT DES ADIEUX */ 192 0x89,0x23,0x66,0x46,0x66,0x17,0x66,0x2e, 193 0x51,0x3b,0x5b,0x4f,0x66,0x17,0x5b,0x34, 194 0x51,0x3b,0x66,0x46,0x66,0x17,0x51,0x3b, 195 0x44,0x46,0x3c,0xec, 196 197 0x16,/* 16 AU CLAIR DE LA LUNE */ 198 0x4c,0x20,0x4c,0x20,0x4c,0x20,0x44,0x24, 199 0x3c,0x52,0x44,0x49,0x4c,0x20,0x3c,0x29, 200 0x44,0x24,0x44,0x24,0x4c,0x82, 201 202 0x16,/* 17 LA MERE MICHEL */ 203 0x4c,0x2d,0x4c,0x0f,0x4c,0x1e,0x4c,0x1e, 204 0x4c,0x1e,0x66,0x16,0x4c,0x1e,0x44,0x21, 205 0x3c,0x4c,0x44,0x43,0x4c,0x5a, 206 207 0x1a,/* 18 IL ETAIT UN PETIT NAVIRE */ 208 0x3c,0x29,0x3c,0x29,0x3c,0x29,0x66,0x31, 209 0x3c,0x52,0x38,0x2b,0x3c,0x29,0x3c,0x52, 210 0x44,0x24,0x44,0x24,0x44,0x24,0x44,0x24, 211 0x66,0x31, 212 213 0x1c,/* 19 LE ROI DAGOBERT */ 214 0x3c,0x1b,0x3c,0x36,0x44,0x18,0x44,0x30, 215 0x4c,0x15,0x4c,0x41,0x44,0x49,0x3c,0x1b, 216 0x38,0x1d,0x3c,0x1b,0x44,0x18,0x4c,0x15, 217 0x44,0x18,0x4c,0x41, 218 219 0x20,/* 20 MALBROUGH */ 220 0x89,0x0b,0x51,0x27,0x51,0x13,0x51,0x27, 221 0x5b,0x11,0x4c,0x3e,0x51,0x13,0x4c,0x14, 222 0x51,0x13,0x5b,0x23,0x5b,0x11,0x5b,0x11, 223 0x66,0x0f,0x5b,0x11,0x51,0x3b,0x66,0x1f, 224 225 0x1c,/* 21 FRERES JACQUES */ 226 0x66,0x33,0x5b,0x39,0x51,0x40,0x66,0x33, 227 0x66,0x33,0x5b,0x39,0x51,0x40,0x66,0x33, 228 0x51,0x40,0x4c,0x44,0x44,0xa2,0x51,0x40, 229 0x4c,0x44,0x44,0xa2, 230 231 0x1e,/* 22 MON BEAU SAPIN */ 232 0x66,0x38,0x4c,0x38,0x4c,0x12,0x4c,0x4a, 233 0x44,0x53,0x3c,0x46,0x3c,0x17,0x3c,0x8b, 234 0x4c,0x25,0x44,0x29,0x3c,0x2f,0x38,0x63, 235 0x51,0x46,0x44,0x53,0x4c,0x4a, 236 237 0x18,/* 23 JOYEUX ANNIVERSAIRE */ 238 0x66,0x14,0x66,0x14,0x5b,0x2d,0x66,0x28, 239 0x4c,0x36,0x51,0x66,0x66,0x14,0x66,0x14, 240 0x5b,0x2d,0x66,0x28,0x44,0x3c,0x4c,0x6c, 241 242 0x1a,/* 24 PETIT PAPA NOEL */ 243 0x66,0x2f,0x4c,0x3e,0x4c,0x3e,0x4c,0x3e, 244 0x44,0x46,0x4c,0xbc,0x4c,0x1f,0x44,0x23, 245 0x3c,0x4f,0x3c,0x4f,0x3c,0x4f,0x38,0x53, 246 0x3c,0xed, 247 248 0x20,/* 25 LA MER */ 249 0x66,0x23,0x4c,0xca,0x51,0x1f,0x4c,0x21, 250 0x44,0x25,0x3c,0x7f,0x4c,0x21,0x44,0x4b, 251 0x51,0x1f,0x5b,0x1c,0x66,0x19,0x3c,0xff, 252 0x44,0x25,0x3c,0x2a,0x38,0x2c,0x32,0x4b, 253 254 0x20,/* 26 LES FEUILLES MORTES */ 255 0x5b,0x11,0x51,0x1d,0x4c,0x0a,0x38,0xff, 256 0x66,0x0f,0x5b,0x19,0x51,0x0a,0x3c,0xf0, 257 0x73,0x0d,0x66,0x17,0x5b,0x08,0x44,0xd6, 258 0x7a,0x0d,0x6d,0x16,0x61,0x08,0x4c,0x54, 259 260 0x1e,/* 27 PETITE FLEUR */ 261 0x73,0x30,0x73,0x18,0x7a,0x9f,0x61,0x1c, 262 0x51,0x22,0x44,0x28,0x38,0x30,0x3c,0x2d, 263 0x4c,0xfc,0x7a,0x16,0x5b,0x24,0x51,0x22, 264 0x4c,0x24,0x5b,0x1e,0x51,0xcc, 265 266 0x1e,/* 28 Y A D'LA JOIE */ 267 0x51,0x16,0x44,0x1a,0x51,0x70,0x89,0x0d, 268 0x7a,0x0f,0x6d,0x10,0x66,0x11,0x5b,0x14, 269 0x51,0x16,0x4c,0x17,0x44,0x1a,0x44,0x1a, 270 0x51,0x16,0x44,0x1a,0x51,0x70, 271 272 0x1e,/* 29 TOUT VA TRES BIEN */ 273 0x44,0x1a,0x51,0x16,0x5b,0x14,0x66,0x35, 274 0x51,0x16,0x5b,0x1e,0x66,0x09,0x6d,0x10, 275 0x7a,0x0f,0x89,0x1a,0x89,0x28,0x44,0x1a, 276 0x51,0x16,0x5b,0x14,0x66,0x23, 277 278 0x1c,/* 30 PARLEZ MOI D'AMOUR */ 279 0x51,0x52,0x51,0x29,0x5b,0x49,0x5b,0x24, 280 0x66,0xa3,0x66,0x20,0x5b,0x24,0x66,0x20, 281 0x5b,0x24,0x51,0x29,0x5b,0x24,0x66,0x20, 282 0x7a,0x52,0x7a,0x52, 283 284 0x1e,/* 31 DE PROFONDIS MORPIONIBUS */ 285 0x7a,0x3c,0x66,0x23,0x5b,0x28,0x51,0xb3, 286 0x3c,0x77,0x44,0x35,0x3c,0x3c,0x51,0xb3, 287 0x5b,0x3c,0x51,0x16,0x4c,0x2f,0x5b,0x28, 288 0x66,0x35,0x5b,0x14,0x51,0x59, 289 290 0x20,/* 32 MARCHE DES SOLDATS DE FAUST */ 291 0x66,0x51,0x89,0x1e,0x66,0x28,0x5b,0x0f, 292 0x51,0x11,0x66,0x0d,0x5b,0x1e,0x5b,0x0f, 293 0x44,0x79,0x51,0x66,0x66,0x28,0x7a,0x22, 294 0x6d,0x0c,0x66,0x0d,0x7a,0x0b,0x6d,0x19, 295 296 0x1c,/* 33 MARCHE D'AIDA */ 297 0x89,0x20,0x66,0x82,0x5b,0x10,0x89,0x0a, 298 0x5b,0x10,0x51,0x36,0x51,0x36,0x51,0x36, 299 0x51,0x12,0x4c,0x13,0x66,0x0e,0x51,0x5b, 300 0x5b,0x10,0x66,0x2b, 301 302 0x1c,/* 34 AIR DU TOREADOR DE CARMEN */ 303 0x44,0x41,0x3c,0x36,0x44,0x10,0x51,0x36, 304 0x51,0x36,0x51,0x29,0x5b,0x0c,0x51,0x29, 305 0x4c,0x0e,0x51,0x6d,0x4c,0x3a,0x5b,0x24, 306 0x44,0x10,0x51,0x6d, 307 308 0x1c,/* 35 MARCHE NUPTIALE DU -SONGE D'UNE NUIT D'ETE -*/ 309 0x38,0x57,0x3c,0x3d,0x51,0x0f,0x44,0x24, 310 0x4c,0x20,0x56,0x1d,0x66,0x18,0x73,0x15, 311 0x7a,0x0f,0x73,0x05,0x66,0x18,0x9a,0x0c, 312 0x66,0x06,0x5b,0x37, 313 314 0x20,/* 36 HYMNE A LA NUIT D'HIPPOLYTE ET ARICIE */ 315 0x7a,0x42,0x89,0x75,0x66,0x4e,0x7a,0x42, 316 0x9a,0x34,0x73,0x8b,0x7a,0x21,0x89,0x1d, 317 0x7a,0x42,0x9a,0x68,0x4c,0x68,0x4c,0x34, 318 0x51,0x31,0x5b,0x2c,0x66,0x27,0x6d,0x94, 319 320 0x1a,/* 37 MARCHE DES ROIS DE L'ARLESIENNE */ 321 0x66,0x26,0x89,0x1c,0x66,0x3a,0x5b,0x16, 322 0x56,0x22,0x5b,0x0a,0x56,0x22,0x66,0x0a, 323 0x44,0x58,0x56,0x16,0x4c,0x34,0x44,0x3a, 324 0x40,0x3e, 325 326 0x1e,/* 38 CHOEUR DES FIANCAILLES DE LOHENGRIN */ 327 0x89,0x2e,0x66,0x2e,0x66,0x0f,0x66,0x7b, 328 0x89,0x2e,0x5b,0x34,0x6d,0x0e,0x66,0x7b, 329 0x89,0x2e,0x66,0x1e,0x4c,0x29,0x4c,0x52, 330 0x51,0x27,0x5b,0x22,0x66,0x3d, 331 332 0x1e,/* 39 HEURE EXQUISE DE LA VEUVE JOYEUSE*/ 333 0x89,0x33,0x66,0x22,0x5b,0x4c,0x51,0x2a, 334 0x89,0x33,0x66,0x22,0x5b,0x4c,0x51,0x2a, 335 0x4c,0x88,0x51,0x80,0x5b,0xe5,0x89,0x33, 336 0x5b,0x26,0x51,0x55,0x4c,0x2d, 337 338 0x1c,/* 40 MARCHE TURQUE - MOZART -*/ 339 0x89,0x08,0x9a,0x07,0xa4,0x06,0x9a,0x07, 340 0x82,0x22,0x73,0x09,0x82,0x09,0x89,0x08, 341 0x82,0x09,0x66,0x2b,0x61,0x0b,0x73,0x09, 342 0x6d,0x0a,0x66,0x0b, 343 344 0x1e,/* 41 HYMNE A LA JOIE - BEETHOVEN -*/ 345 0x51,0x1b,0x51,0x1b,0x4c,0x1d,0x44,0x20, 346 0x44,0x20,0x4c,0x1d,0x51,0x1b,0x5b,0x18, 347 0x66,0x15,0x66,0x15,0x5b,0x18,0x51,0x1b, 348 0x51,0x29,0x5b,0x0c,0x5b,0x30, 349 350 0x1a,/* 42 ETUDE - DITE TRISTESSE - CHOPIN - */ 351 0x89,0x28,0x66,0x6a,0x6d,0x32,0x66,0x35, 352 0x5b,0xb4,0x51,0x43,0x51,0x43,0x5b,0x3c, 353 0x51,0xca,0x4c,0x47,0x4c,0x47,0x51,0x43, 354 0x3c,0xb3, 355 356 0x1e,/* 43 REVERIE - SHUMANN - */ 357 0x9a,0x2d,0x73,0x5b,0x7a,0x1c,0x73,0x1e, 358 0x5b,0x26,0x4c,0x2d,0x38,0x3c,0x38,0x79, 359 0x3c,0x39,0x44,0x33,0x4c,0x2d,0x38,0x3c, 360 0x66,0x22,0x5b,0x26,0x56,0x51, 361 362 0x1e,/* 44 LA TRUITE - SCHUBERT -*/ 363 0x66,0x16,0x4c,0x1e,0x4c,0x1e,0x3c,0x26, 364 0x3c,0x26,0x4c,0x3c,0x66,0x16,0x66,0x16, 365 0x66,0x43,0x66,0x16,0x44,0x21,0x4c,0x1e, 366 0x51,0x1c,0x5b,0x19,0x66,0x43, 367 368 0x20,/* 45 REVE D'AMOUR - LISZT -*/ 369 0x89,0x15,0x51,0x69,0x51,0x69,0x51,0xb0, 370 0x51,0x23,0x51,0x46,0x51,0x23,0x4c,0x4a, 371 0x51,0x23,0x51,0x69,0x7a,0x2f,0x7a,0x17, 372 0x7a,0x17,0x6d,0x1a,0x66,0x1c,0x51,0x46, 373 374 0x1e,/* 46 TAMBOURIN - RAMEAU -*/ 375 0x89,0x09,0x7a,0x0a,0x73,0x0a,0x7a,0x0a, 376 0x89,0x11,0x5b,0x1a,0x5b,0x1a,0x66,0x17, 377 0x73,0x14,0x7a,0x13,0x89,0x09,0x7a,0x0a, 378 0x73,0x0a,0x66,0x0b,0x5b,0x1a, 379 380 0x1a,/* 47 BERCEUSE - BRAHMS -*/ 381 0x7a,0x1e,0x7a,0x0a,0x66,0x62,0x7a,0x1e, 382 0x7a,0x0a,0x66,0x62,0x7a,0x14,0x66,0x18, 383 0x4c,0x41,0x51,0x3d,0x5b,0x37,0x5b,0x37, 384 0x66,0x31, 385 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff 386 }; 387 388int frequence[][2]= 389{ 390 {0x32,784}, 391 {0x35,740}, 392 {0x38,698}, 393 {0x3C,659}, 394 {0x40,622}, 395 {0x44,587}, 396 {0x48,554}, 397 {0x4C,523}, 398 {0x51,494}, 399 {0x56,466}, 400 {0x5B,440}, 401 {0x61,415}, 402 {0x66,392}, 403 {0x6D,370}, 404 {0x73,349}, 405 {0x7A,330}, 406 {0x82,311}, 407 {0x89,294}, 408 {0x92,277}, 409 {0x9A,262}, 410 {0xA4,247}, 411 {0xAE,233}, 412 {0xB8,220}, 413 {0xC3,208}, 414 {0xC7,196}, 415 {0x00, 0}, 416 {-1 , -1} 417}; 418/* 419****-------------------------------------------------------------------- 420 421****-------------------------------------------------------------------- 422*/ 423int Get_Frequency(int val) 424{ 425 int i=0; 426 427 for(i=0;frequence[i][0]!= -1;i++) 428 { 429 if( frequence[i][0] == val ) 430 return(frequence[i][1]); 431 } 432 433 sprintf(buffer,"ERROR Get_Frequency=%x ",val); 434 PrintSerial(buffer); 435 436 return(0); 437} 438 439/* 440****-------------------------------------------------------------------- 441 442****-------------------------------------------------------------------- 443*/ 444unsigned char music( int off ) 445{ 446 return( pgm_read_byte_near( ArrayMusic + off ) ); 447} 448 449 450#ifdef WITHTITLE 451/* 452****-------------------------------------------------------------------- 453 454****-------------------------------------------------------------------- 455*/ 456void Get_Tittle(short off) 457{ 458 char buff[80]; 459 strcpy_P(buff, (char*)pgm_read_word(&(title_table[off]))); 460 461 sprintf(buffer,"****[ %s ]****",(buff)); 462 463} 464#endif 465 466/* 467****-------------------------------------------------------------------- 468 469****-------------------------------------------------------------------- 470*/ 471int Walk_Music(char song) 472{ 473 int offset=0; 474 int fnd=song; 475 476 for(fnd=0;fnd < song;fnd++) 477 offset = offset + music(offset) + 1; 478 479 return(++offset); 480} 481/* 482****-------------------------------------------------------------------- 483 484****-------------------------------------------------------------------- 485*/ 486int Get_Offset_Of_Song_Start(char song) 487{ 488 int offset=0; 489 490 offset = Walk_Music(song); 491 492 sprintf(buffer,"Get_Offset_Of_Song_Start=%d ",offset); 493 PrintSerial(buffer); 494 495 return(offset); 496} 497 498/* 499****-------------------------------------------------------------------- 500 501****-------------------------------------------------------------------- 502*/ 503int Get_Number_Of_Music_Note(char song) 504{ 505 int len=0; 506 507 int offset = Walk_Music(song); 508 len = music( --offset ); 509 510 sprintf(buffer,"Get_Number_Of_Music_Note=%x ",len); 511 PrintSerial(buffer); 512 513 return(len); 514} 515 516 517/* 518****-------------------------------------------------------------------- 519 520****-------------------------------------------------------------------- 521*/ 522void Play_Song() 523{ 524 525 if( CurrentSong < MIN_SONG || CurrentSong > MAX_SONG ) 526 CurrentSong = MIN_SONG; 527 528 sprintf(buffer,"Play_Song=(%d) ",CurrentSong); 529 PrintSerial(buffer); 530 531#ifdef WITHTITLE 532 Get_Tittle(CurrentSong); 533 PrintSerial(buffer); 534#endif 535 536 537 Read_Song(CurrentSong); 538 539 540} 541 542/* 543****-------------------------------------------------------------------- 544 545****-------------------------------------------------------------------- 546*/ 547void Set_Next_Song() 548{ 549 CurrentSong++; 550} 551 552/* 553****-------------------------------------------------------------------- 554 555****-------------------------------------------------------------------- 556*/ 557void Read_Song( char song ) 558{ 559 int offset=0; 560 int maxnote=0; 561 int frq; //frequency 562 int lgt; //length frequency 563 564 565 if( song < MIN_SONG || song > MAX_SONG ) 566 song = MIN_SONG; 567 568 offset = Get_Offset_Of_Song_Start( song ); 569 maxnote = Get_Number_Of_Music_Note( song ); 570 571 //sprintf(buffer,"offset=%x maxnote=%x",offset,maxnote); 572 //PrintSerial(buffer); 573 574 if( maxnote > 0 ) 575 { 576 do{ 577 578 sprintf(buffer,"song(%d) => %x,%x ",song,music(offset),music(offset+1)); 579 PrintSerial(buffer); 580 581 frq = Get_Frequency( music(offset) ); 582 lgt = music(offset+1); 583 584 offset+=2; 585 586 tone(SPEAKER_PIN_OUT,frq); 587 delay( lgt * 8); 588 589 maxnote = maxnote -2; 590 591 }while( maxnote > 0 ); 592 } 593 594 noTone(SPEAKER_PIN_OUT); 595} 596 597/* 598****-------------------------------------------------------------------- 599 600****-------------------------------------------------------------------- 601*/ 602void Extern_Interrupt() 603{ 604 noInterrupts(); 605 606 if( Flg_Play_Song == NO ) 607 Flg_Play_Song = YES; 608 609 interrupts(); 610} 611 612/* 613****-------------------------------------------------------------------- 614 615****-------------------------------------------------------------------- 616*/ 617void Save_Current_Song() 618{ 619 620 if( CurrentSong < MIN_SONG || CurrentSong > MAX_SONG ) 621 CurrentSong = MIN_SONG; 622 623 EEPROM.write(EEPROM_ADRESS,CurrentSong); 624} 625 626/* 627****-------------------------------------------------------------------- 628 629****-------------------------------------------------------------------- 630*/ 631void Load_Current_Song() 632{ 633 CurrentSong = EEPROM.read(EEPROM_ADRESS); 634 635 if( CurrentSong < MIN_SONG || CurrentSong > MAX_SONG ) 636 { 637 CurrentSong = MIN_SONG; 638 Save_Current_Song(); 639 } 640} 641/* 642****-------------------------------------------------------------------- 643 644****-------------------------------------------------------------------- 645*/ 646void setup() 647{ 648 // put your setup code here, to run once: 649 Serial.begin(SERIAL_SPEED); 650 651 Load_Current_Song(); 652 653 PrintSerial("DoorBell V1.0: Schoumacher Patrice 2017/01"); 654 PrintSerial(" : Inspired by R.HUTIN MicroSysteme 9/1981"); 655 656 sprintf(buffer,"Taille EEPROM=%d",EEPROM.length()); 657 PrintSerial(buffer); 658 659 sprintf(buffer," ->Current_Song=%d ",CurrentSong); 660 PrintSerial(buffer); 661 662 sprintf(buffer," SPEAKER_PIN_OUT=%d ",SPEAKER_PIN_OUT); 663 PrintSerial(buffer); 664 sprintf(buffer," EXTERN_INTERRPT_PIN=%d ",EXTERN_INTERRPT_PIN); 665 PrintSerial(buffer); 666 667 pinMode(LED_BUILTIN, OUTPUT); 668 Intern_Led(LOW); 669 670 pinMode(SPEAKER_PIN_OUT, OUTPUT); // no song HP 671 pinMode(EXTERN_INTERRPT_PIN, INPUT_PULLUP); // External interrupt Pin 2 672 673 attachInterrupt(digitalPinToInterrupt(EXTERN_INTERRPT_PIN), Extern_Interrupt, FALLING); 674 675 set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep Mode => save battery 676 677} 678 679void Intern_Led(int val) 680{ 681 digitalWrite(LED_BUILTIN, val); 682} 683/* 684****-------------------------------------------------------------------- 685 686****-------------------------------------------------------------------- 687*/ 688void PrintSerial(const char *text) 689{ 690#ifdef SERIALDEBUG 691 Serial.println(text); 692 Serial.flush(); // while (!(UCSR0A & _BV(TXC0))); // wait for empty serial print bufferer 693 #endif 694} 695 696/* 697****-------------------------------------------------------------------- 698For decrease memory impact with string 699****-------------------------------------------------------------------- 700*/ 701void PrintSerialF(const char *text) 702{ 703#ifdef SERIALDEBUG 704 Serial.print((const __FlashStringHelper *) text); 705 Serial.flush(); 706 #endif 707} 708/* 709****-------------------------------------------------------------------- 710 711****-------------------------------------------------------------------- 712*/ 713void loop() { 714 715 Load_Current_Song(); 716 717 if( Flg_Play_Song == YES ) 718 { 719 Intern_Led(HIGH); 720 Flg_Play_Song = NO; 721 722 Play_Song(); 723 724 Set_Next_Song(); 725 726 Save_Current_Song(); 727 Intern_Led(LOW); 728 } 729 730 PrintSerialF(SLEEP_MODE); 731 732 sleep_mode(); // Sleep mode activ until external interrupt 733 sleep_disable(); 734 735 PrintSerialF(EXTERN_INTERRUPT); 736 737 PrintSerialF(WAKE_UP); 738 739} 740
Downloadable files
Door bell
Door bell
Comments
Only logged in users can leave comments
Anonymous user
7 years ago
just made it for my baby, used an NPN transistor (base to D4 via 1k resistor, emitter to ground and collector to vcc via speaker) as amp with a small 8ohm speaker for switching instead of tactile switch, used a TSOP1738 IR sensor (+ to vcc, Ground Gnd, signal pin to D2), use any IR remote click any button u can Play the music. Happy Parenting.
Harrix
7 years ago
Audio 2x3W Modul: https://fr.aliexpress.com/item/2pcs-Audio-Amplifier-Module-USB-Class-D-Amplifier-Board-2-5-5V-2X3W-for-Arduino/32701394093.html?spm=a2g0s.9042311.0.0.874lYH
Harrix
0 Followers
•1 Projects
1
3
Harrix
2 years ago
Audio 2x3W Modul: https://fr.aliexpress.com/item/2pcs-Audio-Amplifier-Module-USB-Class-D-Amplifier-Board-2-5-5V-2X3W-for-Arduino/32701394093.html?spm=a2g0s.9042311.0.0.874lYH