//Music Dynamic Rhythm Lamp
#include <LiquidCrystal.h>
#include "pitches.h"
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
// notes in the melody:
int melody[] = {
NOTE_C5, NOTE_C5, NOTE_G5, NOTE_G5, NOTE_A5, NOTE_A5, NOTE_G5,
NOTE_F5, NOTE_F5, NOTE_E5, NOTE_E5, NOTE_D5, NOTE_D5, NOTE_C5,
NOTE_G5, NOTE_G5, NOTE_F5, NOTE_F5, NOTE_E5, NOTE_E5, NOTE_D5,
NOTE_G5, NOTE_G5, NOTE_F5, NOTE_F5, NOTE_E5, NOTE_E5, NOTE_D5,
NOTE_C5, NOTE_C5, NOTE_G5, NOTE_G5, NOTE_A5, NOTE_A5, NOTE_G5,
NOTE_F5, NOTE_F5, NOTE_E5, NOTE_E5, NOTE_D5, NOTE_D5, NOTE_C5
};
int melody_motherland[] = {
NOTE_D5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_A4,
NOTE_G4, NOTE_D4,
NOTE_G4, NOTE_B4, NOTE_G5, NOTE_FS5, NOTE_E5, NOTE_B4,
NOTE_D5
};
// note durations: 1 = quarter note, 2 = eighth note, etc.:
float duration[] = {
1, 1, 1, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 2
};
float duration_motherland[] = {
1, 1, 1, 1, 1, 1,
3, 3,
1, 1, 1, 1, 1.5, 0.5,
6
};
int length, length_motherland;
int tonepin = 5;
void setup()
{
pinMode(tonepin, OUTPUT);
length = sizeof(melody) / sizeof(melody[0]);
length_motherland = sizeof(melody_motherland) / sizeof(melody_motherland[0]);
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
}
void loop()
{
lcd.clear();
if (analogRead(A0) <= 300)
{ lcd.print("mute");
noTone(tonepin);
delay(2000);
}
else if (analogRead(A0) <= 700) {
lcd.print("Twinkle Twinkle");
lcd.setCursor(0,1);
lcd.print("Little Star");
for (int thisNote = 0; thisNote < length; thisNote++) {
int noteDuration = 250 * duration[thisNote];
tone(tonepin, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.2;
delay(pauseBetweenNotes);
// stop the tone playing:
//noTone(tonepin);
}
delay(2000);
}
else {
lcd.print("My Motherland");
lcd.setCursor(0,1);
lcd.print("and Me");
for (int thisNote = 0; thisNote < length_motherland; thisNote++) {
int noteDuration = 250 * duration_motherland[thisNote];
tone(tonepin, melody_motherland[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.20;
delay(pauseBetweenNotes);
// stop the tone playing:
//noTone(tonepin);
}
delay(2000);
}
}