Permalink
Browse files

Auto play

  • Loading branch information...
aminosan committed Apr 30, 2017
1 parent 2f7a9a5 commit b30cce23c2b5d18666dc69bc54322f9e0e2f8185
Showing with 49 additions and 19 deletions.
  1. +17 −7 MenZ-TONE.ino
  2. +1 −0 pitches.h
  3. +31 −12 songs.h
View
@@ -66,6 +66,7 @@ int currentPosition = 0;
int readyTone = 1;
int nowNote;
int nowNoteDuration;
int tempo;
void ledBlink() {
static boolean output = LOW; // プログラム起動前に1回だけHIGH(1)で初期化される
@@ -158,23 +159,32 @@ void loop() {
if(autoPlay == 1){
Serial.println("DEBUG DEBUG DEBUG autoPlay: ");
nowNote = pgm_read_word(&melody[currentSong][currentPosition]);
nowNoteDuration = 1000 / pgm_read_word(&noteDurations[currentSong][currentPosition]);
tempo = pgm_read_word(&tempoList[currentSong]);
nowNoteDuration = pgm_read_word(&noteDurations[currentSong][currentPosition]);
Serial.print("tempo: ");
Serial.println(tempo);
Serial.print("nowNoteDuration: ");
Serial.println(nowNoteDuration);
nowNoteDuration = (int)((240000 / tempo) / nowNoteDuration);
// 最後の音まで来たらリセット
if(nowNote == 0){
if(nowNote == 0) {
Serial.print("if currentPosition: ");
Serial.println(currentPosition);
currentPosition = 0;
nowNote = pgm_read_word(&melody[currentSong][currentPosition]);
autoPlay = 0;
Serial.println("DEBUG DEBUG DEBUG reset: ");
} else {
tone(14, nowNote, nowNoteDuration);
Serial.print("nowNoteDuration: ");
Serial.println(nowNoteDuration);
int pauseBetweenNotes = nowNoteDuration * 1.30;
delay(pauseBetweenNotes);
if (nowNote > 1) {
tone(14, nowNote);
}
delay(nowNoteDuration);
noTone(14);
currentPosition++;
noTone(14);
currentPosition++;
}
}
View
@@ -2,6 +2,7 @@
* Public Constants
*************************************************/
#define REST 1
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
View
43 songs.h
@@ -12,11 +12,11 @@ const PROGMEM uint16_t melody[songNum][256] =
},
// なん本桜
{
NOTE_D4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_A4,
NOTE_D4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, REST, NOTE_A4,
NOTE_C5, NOTE_D5, NOTE_G4, NOTE_F4, NOTE_A4,
NOTE_D4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_A4,
NOTE_D4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, REST, NOTE_A4,
NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_F4,
NOTE_D4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_A4,
NOTE_D4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, REST, NOTE_A4,
NOTE_C5, NOTE_D5, NOTE_G4, NOTE_F4, NOTE_A4,
NOTE_D4, NOTE_F4, NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_G4,
NOTE_A4, NOTE_E4, NOTE_C4, NOTE_D4,
@@ -46,19 +46,19 @@ const PROGMEM uint16_t melody[songNum][256] =
{
NOTE_B4, NOTE_CS5, NOTE_D5, NOTE_A5,
NOTE_FS5, NOTE_FS5, NOTE_E5, NOTE_FS5,
1, NOTE_E5, NOTE_FS5, NOTE_A5, NOTE_E5, NOTE_CS5, NOTE_D5,
NOTE_E5, NOTE_FS5, NOTE_A5, NOTE_E5, NOTE_CS5, NOTE_D5,
NOTE_CS5, NOTE_CS5, NOTE_B4, NOTE_FS4,
NOTE_B4, NOTE_CS5, NOTE_D5, NOTE_A5,
NOTE_FS5, NOTE_FS5, NOTE_E5, NOTE_FS5, 1,
NOTE_FS5, NOTE_FS5, NOTE_E5, NOTE_FS5,
NOTE_E5, NOTE_FS5, NOTE_A5, NOTE_FS5, NOTE_A5, NOTE_D6,
NOTE_CS6, NOTE_B5, NOTE_FS5, NOTE_E5,
NOTE_FS5, NOTE_A5, NOTE_B5, NOTE_CS6,
NOTE_FS5, NOTE_FS5, NOTE_E5, NOTE_FS5,
1, NOTE_E5, NOTE_FS5, NOTE_A5, NOTE_E5, NOTE_CS5, NOTE_D5,
NOTE_E5, NOTE_FS5, NOTE_A5, NOTE_E5, NOTE_CS5, NOTE_D5,
NOTE_CS5, NOTE_CS5, NOTE_B4, NOTE_FS4,
1, NOTE_B4, NOTE_CS5, NOTE_D5, NOTE_A5,
NOTE_B4, NOTE_CS5, NOTE_D5, NOTE_A5,
NOTE_FS5, NOTE_FS5, NOTE_E5, NOTE_FS5,
1, NOTE_E5, NOTE_FS5, NOTE_A5, NOTE_FS5, NOTE_A5, NOTE_D6,
NOTE_E5, NOTE_FS5, NOTE_A5, NOTE_FS5, NOTE_A5, NOTE_D6,
NOTE_CS6, NOTE_B5,
NOTE_B5, NOTE_B5,
NOTE_CS6, NOTE_B5,
@@ -236,15 +236,34 @@ const PROGMEM uint16_t defaultSongs[songNum][256] =
}
};
const PROGMEM uint16_t tempoList[songNum] = {
170, 154
};
// 休符は二つ連続で入れちゃダメよー
const PROGMEM uint16_t noteDurations[songNum][256] =
{
// パーパパパーパーパーパー
// ようこそなんとかパークへ
{
4, 8, 8, 4, 4, 4, 4, 4,
0
8, 8, 8, 4, 8, 8, 4,
8, 8, 4, 8, 8, 8,
4, 4, 4, 4, 8, 8,
8, 8, 2,
0
},
// 何本桜
{
8, 8, 6, 6, 8, 4, 8, 8,
8, 8, 8, 8, 4,
8, 8, 6, 6, 8, 4, 8, 8,
8, 8, 8, 8, 4,
8, 8, 6, 6, 8, 4, 8, 8,
8, 8, 8, 8, 4,
8, 8, 4, 4, 4, 4, 8,
8, 8, 8, 4,
0
},
// 鳥の詩
// 鳥のなんとか
{
4, 8, 8, 8,
4, 8, 8, 2,

0 comments on commit b30cce2

Please sign in to comment.