arduino mega2560 を利用して 自分の作業に役立てたいと思っている初心者です。
「Android ADK組込みプログラミング完全ガイド」を購入し、現在、スケッチを勉強しています。
しかし、本に掲載されているサンプルブログラムを何度入力しても、エラーが発生し、検証コンパイルができません。
エラーは下記のようなものです。
'convertDurationToClocks' was not declared in this scope
是非、解決方法を教えていただければ、幸いです。
スケッチは、上記本の「第8章 Android対応の電子オルゴールを作る」のサンプルスケッチです。
全体のスケッチは下記の通りてす。
何卒、よろしくお願いいたします。
#define PIN_PUSHSW_INPUT 8 // 押しボタンスイッチをデジタルI/O 8番に接続
#define PIN_TONE_OUTPUT 11 // 圧電スピーカーをデジタルI/O 11番に接続
#define PIN_LED_INDICATOR 13 // デジタルI/O 13番に接続されているARDUINOボードのLED用
void parseMml(char* );
boolean isDigit(char c);
char* getNumber(char* mmlstr,int columns,int* number);
char* getDuration(char* mmlstr,int correntlength,int* duration,boolean* dotted);
char* getTone(char* mmlstr,unsigned char* tone,int* octaveoffset);
unsigned long convertFrequency(int tone,int octave);
// 楽譜データ
char mmlString[] = "T132 05 L4GL8RDL4GL8RD GDGB>L4DR CL8R<AL4>CL8R<A >C<AF+AL4DR";
void setup()
{
pinMode(PIN_TONE_OUTPUT,OUTPUT);
digitalWrite(PIN_TONE_OUTPUT,LOW);
pinMode(PIN_LED_INDICATOR,OUTPUT);
digitalWrite(PIN_LED_INDICATOR,LOW);
pinMode(PIN_PUSHSW_INPUT,INPUT_PULLUP);
}
// 押しボタンスイッチが押されたどうかの確認
// 引数 : なし
// 戻り値 : true = 押されている(100ms待ちも入れる)
// false = 押されていない
boolean checkButtonPushed(void)
{
if(digitalRead(PIN_PUSHSW_INPUT) == LOW){
delay(200);
return(true);
}
return(false);
}
boolean checkStopPlay(void)
{
return checkButtonPushed();
}
void loop()
{
// ポンタが押されるまで待つ
while(checkButtonPushed() == false);
// MMLデータの字句解析と再生
digitalWrite(PIN_LED_INDICATOR,HIGH);
parseMml(mmlString);
digitalWrite(PIN_LED_INDICATOR,LOW);
}
// MMLデータを解析しながら再生する
// 引数 : MMLデータ(終端は'\0')
// 戻り値 : なし
void parseMml(char* mmlstr)
{
// ** 再生開始状態における初期値
// オクターブ = 4(O4)
int current_octave = 4;
// 音符、休符の長さ = 4分(L4)
int current_length = 4;
// テンポ = 60(T60)
int current_tempo = 60;
// ボリューム = 127(V127) *未使用
int current_volume = 127;
// 楽器番号 = 0(@0) *未使用
int current_program = 0;
int delay_time;
int duration;
int oct_offset;
unsigned char ctone;
unsigned char ctone_prev = 255;
unsigned short oneTick;
boolean tie = false;
boolean dotted;
oneTick = 60000 / current_tempo / 96;
while(*mmlstr != '\0'){
if(checkStopPlay() == true){ noTone(PIN_TONE_OUTPUT); return; } switch(*mmlstr){ case 'C': case 'D': case 'E': case 'F': case 'G': case 'A': case 'B': case 'c': case 'd': case 'e': case 'f': case 'g': case 'a': case 'b': // 音符の取得 mmlstr = getTone(mmlstr,&ctone,&oct_offset); // 長さの取得 mmlstr = getDuration(mmlstr,current_length,&duration,&dotted); delay_time = convertDurationToClocks(duration) * oneTick; if(dotted){ // 符点がある場合には、音長を1.5培にする delay_time += delay_time >> 1; } // タイの処理 if(tie && (ctone == ctone_prev)){ // タイの場合(前回処理した音符と今回処理した音符が同一である場合) delay(delay_time); } else} // タイでない場合はスラーとする(処理上は単に音程を変える) } tone(PIN_TONE_OUTPUT,convertFrequency(ctone,cuurent(octave+ oct_offset)); delay(delay_time); ] ] ctone_prev = ctone; tie = false; break; case 'L'; case 'l'; // 休符の処理 tie = false; mmlstr = getDuration(mmlstr+1,current_lenth,&duration,&dotted); delay_time = convertDurationToClocks(duration) * oneTick; if(dotted){ // 音符、休符の長さの設定 mmlstr = getNumber(mmlstr+a,2,¤t_length); break; case 'R'; case 'r'; // 符点がある場合には、音長1.5倍にする delay_time += delay_time >> 1; ] // 音を止める noTone(PIN_TONE_OUTPUT); delay(delay_time); break; case 'O'; case 'o'; // オクターブの変更 tie = false; [ int oct; mmlstr = getNumber(mmlstr+1,2,&oct); // オクターブの設定範囲:0~8の間かチェック if(oct >= 0 && oct <= 8)[ current_octave = oct; } } break; case 'T'; case 't'; // テンポの変更 tie = false; mmlstr = getNumber(mmlstr+1,3,¤t_tempo); // テンポ設定値を元に4分音符を96で割った値を基準値として記憶する oneTick = 60000 / current_temp / 96; break; case 'V'; case 'v'; // 音量の変更 tie = false; mmlstr = getNumber(mmlstr+1,3,¤t_volume); printf("Volume => %d\n",current_Volume); break; case '@'; // 楽器の変更 tie = false; mmlstr = getNumber(mmlstr+1,3,¤t_program); break; case '>'; // オクターブを1つ上げる tie = false; if(current_octave < 8){ current_octave++; } mmlstr++; break; case '<'; // オクターブを1つ下げる tie = false; if(current_octave > 8){ current_octave--; } mmlstr++; break; case '&'; // タイ tie = true; mmlstr++; break; defailt: // 不明のキャラクタ tie = false; mmlstr++; } } noTone(11); }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。