私はプロジェクトが1日で完了していますが、これは非常に単純なものですが、この質問に答えられるとは思っていません。 http://dominikzeman.blogspot.co.nz/2016/12/we-are-number-one-but-its-arduino.html ピエゾスピーカーで "私たちはナンバーワンです"という曲を演奏するシンプルなコードですが、ループなしで必要な曲をループします。私はループを止めるために様々な戦略を試しました(これは私にとって初めてのことです)が、毎回エラーが出ます。Arduino Uno Piezoスピーカーループを1回再生する代わりに(プログラミング初心者)
const int fn = 400;
const int hn = 200;
const int qn = 100;
const int f5 = 698;
const int c6 = 1047;
const int b5 = 988;
const int gh5 = 831;
const int ch6 = 1109;
const int dh6 = 1245;
int song[] = {
f5,fn + hn,
c6,hn,
b5,qn,
c6,qn,
b5,qn,
c6,qn,
b5,hn,
c6,hn,
gh5,fn,
f5,fn + hn,
f5,hn,
gh5,hn,
c6,hn,
ch6,fn,
gh5,fn,
ch6,fn,
dh6,fn,
c6,hn,
ch6,hn,
c6,hn,
ch6,hn,
c6,fn
};
void setup() {
Serial.begin(9600);
}
void loop() {
for (int i = 0; i < (sizeof(song)/sizeof(int)); i = i + 2){
tone(8, song[i]);
delay(song[i + 1]);
}
noTone(8);
delay(1000);
}
私は、問題は、私はそれはしかし、私は一定のイライラエラーなしでそれを修正することはできません停止したい場合は、ボイドループにコードがあってはならないということであることを知っていますか:ここで
はコードです。いずれの簡単なヘルプも救命救助者になるでしょう。 、起動時に一度だけの曲を再生するには
void PlaySong()
{
for (int i = 0; i < (sizeof(song)/sizeof(int)); i = i + 2){
tone(8, song[i]);
delay(song[i + 1]);
}
}
setup()
からそれを呼び出す: