#include <Arduino.h>
#include <U8x8lib.h>
U8X8_SSD1306_128X64_ALT0_HW_I2C oled(/* reset=*/ U8X8_PIN_NONE);
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
//G4 A4 B4 C5 D5 E5 FS5 G5
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, 0.5, 0.5, 1, 1, 1, 1, 1
};
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]);
oled.begin();
oled.setFlipMode(0);
}
void loop()
{
lcd.clear();
if (analogRead(A0) <= 300)
{ oled.print("mute");
noTone(tonepin);
delay(2000);
}
else if (analogRead(A0) <= 700) {
oled.print("music 1");
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.10;
delay(pauseBetweenNotes);
// stop the tone playing:
//noTone(tonepin);
}
delay(2000);
}
else {
oled.print("My Motherland");
oled.setCursor(0,1);
oled.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);
}
}