LoginSignup
0
1

More than 5 years have passed since last update.

Arduino で、ようこそジャパリパークへを演奏してみた!

Last updated at Posted at 2017-07-22

 ♪~ウェルカム とぅざ ジャパリパーク!~♪

◆Arduino で、ようこそジャパリパークへを演奏してみた!

タイトル、そのまんまである。
http://www.nicovideo.jp/watch/sm30846698

◆環境

Arduino Uno /duemilanoveで動く。

◆How should I do?

①ライブラリ準備
Playtuneライブラリを入れてほしい。
https://github.com/jarv/PlayTune

(違うPlaytuneの、リンク貼ってた。
(修正(2017-07-23 11時59分

②曲を準備する。
Playtuneライブラリの、songsフォルダにWTJP328p.hを入れる。
(面倒だが、下からコピペして、ファイルに保存してほしい。)

③コンパイル&書込み
Arduinoの設定
Arduino Uno /duemilanove → 328p 16Mhz
(これも面倒だが、下からコピペして、ファイルに保存してほしい。)

Ctrl+Rで書込み

④ ピエゾブザーを
6,9,11ピンにつなぐ。

完了

ソース

WTJP328p.h
#ifndef WTJP328P
#define WTJP328P
#include <stdint.h>
#include <avr/pgmspace.h>

#define WTJP328P0 256,WTJP328p0_notes,WTJP328p0_delays,sizeof(WTJP328p0_notes)/sizeof(*(WTJP328p0_notes)),sizeof(WTJP328p0_delays)/sizeof(*(WTJP328p0_delays))
#define WTJP328P1 64,WTJP328p1_notes,WTJP328p1_delays,sizeof(WTJP328p1_notes)/sizeof(*(WTJP328p1_notes)),sizeof(WTJP328p1_delays)/sizeof(*(WTJP328p1_delays))
#define WTJP328P2 256,WTJP328p2_notes,WTJP328p2_delays,sizeof(WTJP328p2_notes)/sizeof(*(WTJP328p2_notes)),sizeof(WTJP328p2_delays)/sizeof(*(WTJP328p2_delays))

/*

    Part: 0
    Freq: 16000000
    Number of voices: 1
    Note length: 306
    Delay length: 306

    Part: 1
    Freq: 16000000
    Number of voices: 1
    Note length: 160
    Delay length: 160

    Part: 2
    Freq: 16000000
    Number of voices: 1
    Note length: 444
    Delay length: 444

*/

const uint8_t WTJP328p0_notes[] PROGMEM = {88,94,88,79,88,79,70,66,62,59,70,79,88,88,0,52,0,59,0,88,0,105,66,70,79,88,0,0,0,0,0,0,0,88,74,88,74,88,74,66,66,74,66,62,66,74,88,99,88,0,0,0,0,88,74,88,74,88,74,66,66,66,74,74,66,62,66,74,88,99,88,0,0,88,0,99,0,118,0,0,70,70,70,70,70,52,70,70,70,70,79,79,88,88,79,79,79,79,59,79,66,0,70,0,79,0,70,0,66,105,105,0,70,118,118,0,118,112,99,88,59,70,66,70,70,79,0,0,88,94,88,79,88,79,70,66,62,59,0,70,79,88,88,0,52,0,59,0,88,0,66,70,79,88,79,0,88,94,88,79,88,79,70,66,62,59,0,70,79,88,88,0,52,59,88,105,66,70,79,88,0,88,79,74,79,88,112,118,70,70,70,0,74,70,66,59,66,70,0,70,66,70,88,105,88,0,0,70,66,70,88,112,112,118,79,88,0,0,0,70,88,105,79,0,79,94,118,88,141,133,88,94,105,105,118,141,118,0,70,88,105,79,0,79,70,66,70,79,88,133,88,94,88,88,79,88,88,0,70,88,105,79,0,79,94,118,88,141,133,88,94,105,105,118,141,118,0,70,88,105,79,0,79,70,66,70,79,88,133,88,94,88,88,79,88,88,0,133,88,94,88,79,88,79,88,0};
const uint8_t WTJP328p0_delays[] PROGMEM = {2,2,2,4,2,2,4,2,2,4,2,2,2,2,2,2,2,2,2,2,2,4,4,4,4,2,2,4,8,16,16,16,2,2,2,2,3,3,4,2,2,2,3,3,2,2,2,2,4,2,4,16,2,2,2,2,3,3,4,1,1,2,1,1,3,3,2,2,2,2,4,2,4,2,2,2,2,2,2,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,4,2,2,4,2,2,2,2,2,2,2,2,2,8,2,4,4,6,2,4,2,2,4,2,4,4,4,2,2,2,4,4,16,2,2,2,4,2,2,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,4,2,2,2,4,2,2,4,2,2,2,2,2,2,2,2,2,4,4,4,4,4,4,4,8,2,4,2,4,4,4,4,3,3,2,1,2,3,2,6,1,1,4,2,2,4,2,4,4,6,2,8,2,4,2,4,4,2,8,8,4,4,8,16,2,2,2,8,2,2,2,2,6,4,4,4,4,4,2,2,2,6,4,2,2,2,8,2,2,2,2,4,2,4,4,4,4,2,2,6,2,6,2,2,2,2,8,2,2,2,2,6,4,4,4,4,4,2,2,2,6,4,2,2,2,8,2,2,2,2,4,2,4,4,4,4,2,2,6,2,6,2,4,4,4,2,4,2,4,4,4};

const uint8_t WTJP328p1_notes[] PROGMEM = {0,0,158,0,0,141,0,133,126,118,0,0,178,0,141,0,158,0,141,0,0,0,0,0,0,0,0,0,0,0,0,0,0,88,141,0,158,0,158,0,0,158,0,168,0,158,0,141,0,133,0,141,149,118,0,0,0,0,0,0,141,133,126,118,0,178,141,158,141,178,158,141,133,126,118,0,0,178,141,212,133,141,158,0,0,0,149,149,149,0,178,178,178,0,141,0,0,133,133,133,0,141,141,141,0,133,0,133,141,178,212,178,0,0,0,0,0,0,141,158,158,178,158,141,178,141,141,158,238,178,158,141,158,178,141,158,158,178,158,141,178,141,141,158,238,178,158,141,158,178,200,141,158,0,158,0,0,178,0,0};
const uint8_t WTJP328p1_delays[] PROGMEM = {2,4,2,2,4,2,2,2,2,4,2,4,4,4,4,4,4,4,4,4,16,16,16,16,16,16,16,16,16,16,16,4,8,4,8,8,8,8,8,2,4,2,2,2,2,2,2,2,2,16,2,16,14,6,4,8,16,2,4,8,4,2,2,6,4,8,8,8,8,6,8,4,2,2,4,2,4,8,8,4,4,4,4,2,4,8,1,1,4,2,1,1,4,4,8,2,4,1,1,4,2,1,1,4,4,8,8,4,2,4,4,4,2,4,8,16,16,16,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,6,4,2,1,1,2,2,2,4};

const uint8_t WTJP328p2_notes[] PROGMEM = {88,0,88,0,0,88,212,189,178,178,118,178,0,133,0,133,0,141,0,141,0,178,0,178,0,189,0,189,189,200,0,200,200,212,212,212,212,224,0,224,0,238,0,238,238,252,0,252,252,238,224,212,200,178,0,178,0,189,0,189,189,200,0,200,200,212,212,212,212,224,0,224,0,238,0,238,238,252,0,252,252,238,224,212,200,0,0,88,0,88,0,94,0,94,94,99,0,99,99,105,105,105,105,112,0,112,0,118,0,118,118,126,0,126,126,118,112,105,99,0,0,88,0,88,0,94,0,94,94,99,0,99,99,105,105,105,105,133,0,0,126,0,0,118,0,0,0,141,141,141,141,105,105,88,105,158,158,158,158,112,112,88,112,158,158,158,158,118,118,94,99,0,99,0,99,0,0,0,0,0,0,0,118,0,105,0,112,112,105,99,94,88,0,0,118,0,118,0,141,141,141,0,88,79,88,79,79,112,105,99,94,88,0,0,0,88,0,88,0,105,66,70,79,88,112,133,88,112,133,88,133,88,112,133,88,112,133,88,0,70,88,118,70,88,118,70,118,99,99,99,99,99,99,99,99,88,88,0,88,0,88,0,88,0,88,88,112,112,0,112,0,112,112,178,0,178,0,189,0,189,189,200,0,200,200,212,212,212,212,224,0,224,0,238,0,238,238,252,0,252,252,238,224,212,200,88,88,0,88,0,79,79,79,94,94,0,94,0,88,88,88,88,0,88,88,79,0,79,79,88,88,0,88,0,88,88,88,88,88,0,88,0,79,79,79,94,94,0,94,0,88,88,88,88,0,88,88,79,0,79,79,88,88,0,88,0,88,88,88,88,88,0,88,0,79,79,79,94,94,0,94,0,88,88,88,88,0,88,88,79,0,79,79,88,88,0,88,0,88,88,88,88,88,0,88,0,79,79,79,94,94,0,94,0,88,88,88,88,0,88,88,79,0,79,79,88,88,0,88,0,88,88,88,79,0,0,94,0,88,88,88,0,0,88};
const uint8_t WTJP328p2_delays[] PROGMEM = {2,4,2,2,4,4,2,2,4,2,2,2,2,2,2,2,2,2,2,2,16,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,16,16,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,16,16,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,2,1,1,2,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,8,16,16,16,16,16,2,2,2,2,2,2,2,4,2,2,6,4,2,2,2,2,2,2,2,2,16,2,2,2,4,2,2,4,2,2,4,2,4,2,2,2,2,8,4,4,4,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,2,4,2,2,2,4,2,2,2,6,4,2,4,2,2,2,16,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,2,4,4,2,1,1,2,8};

#endif

Playtune_WTJP328p.ino
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include <playtune.h>
#include <songs/WTJP328p.h>

void setup(void)
{
      // set everything low that we aren't using
    DDRB |= (1<<PB2) | (1<<PB4) | (1<<PB3) | (1<<PB5);
    PORTB &= ~(1<<PB2) | ~(1<<PB4) | ~(1<<PB3) | ~(1<<PB5);


    PlayTune p0(0,WTJP328P0);
    PlayTune p1(1,WTJP328P1);
    PlayTune p2(2,WTJP328P2);
    while ( p0.isPlaying() || p1.isPlaying() || p2.isPlaying()) {

        p0.playNote();
        p1.playNote();
        p2.playNote();
        _delay_ms(87);
    }


    /*
    PlayTune pk0(0,ASUHENO0);
    PlayTune pk1(1,ASUHENO1);
    PlayTune pk2(1,ASUHENO2);
    while ( pk0.isPlaying() || pk1.isPlaying() || pk2.isPlaying()) {

        pk0.playNote();
        pk1.playNote();
        pk2.playNote();
        _delay_ms(30);
    }
    */


    digitalWrite(6, LOW);
    digitalWrite(9, LOW); 
    digitalWrite(11, LOW); 
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_mode();
  }

void loop(void)
{
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1