さくら と言う音楽がワンフレーズほど流れるようにしようとしています。
さくら さくらまでは出来でいると思うのですが、やよいの空はの「空」の部分がうまく出来ません。
教えください、お願いします。
//delayMicroseconds(1000000L)
// the setup function runs once when you press reset or power the board
const char SPK = 11;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(SPK, OUTPUT);
}
//float T=1/440; ラの音 1秒440Hz 0.002272/2 = 0.00113636 *1000000 =1136microsec
float len[10] = {262 ,294 ,330 ,349 ,392 ,440 ,494 ,523, 220, 247};
float sec[10] = {261.6,293.7,329.6,349.2,392.0,440.0,493.9,523.3,220, 247};
// the loop function runs over and over again forever
int sound(int t, int c, int d){
for(int j=0; j<=len[t]; j++){
digitalWrite(SPK, HIGH);
delayMicroseconds(1/sec[c]/21000000L);
digitalWrite(SPK, LOW);
delayMicroseconds(1/sec[c]/21000000L);
}
delayMicroseconds(d);
}
void loop(){
for(int k=0; k<8; k++){
sound(k, k, 100);
}
sound(6, 6, 50);
sound(6, 6, 50);
sound(7, 7, 25);
sound(6, 6, 50);
sound(6, 6, 50);
sound(7, 7, 25);
sound(6, 6, 50);
sound(7, 7, 50);
sound(8, 8, 50);
sound(7, 7, 50);
sound(6, 6, 50);
sound(9, 9, 25);
sound(8, 8, 25);
sound(4, 4, 50);
}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。