不多说,先上图
:lol
程序其实很简单,就是读数组里面的频率,然后就tone()播出去了。
- #define LENGTH 16
-
- int music_1[LENGTH] = {1318, 1318, 1397, 1568, 1568, 1397, 1318, 1175, 1046, 1046, 1175, 1318, 1318, 1318, 1175, 1175};
- int music_2[LENGTH] = {1318, 1318, 1397, 1568, 1568, 1397, 1318, 1175, 1046, 1046, 1175, 1318, 1175, 1175, 1046, 1046};
- int music_3[LENGTH + 2] = {1175, 1175, 1318, 1046, 1175, 1318, 1397, 1318, 1046, 1175, 1318, 1397, 1318, 1175, 1046, 1175, 784, 784};
-
- void setup() {
- pinMode(13, OUTPUT);
- Serial.begin(9600);
- }
-
- void loop() {
- delay(5000);
- Serial.println("");
- while(true) {
- Serial.println("Music Start.");
- for(int i = 0; i < LENGTH; i++) {
- digitalWrite(13, !digitalRead(13));
- if((i == 14) || (i == 12)) {
- tone(8, music_1[i], 500);
- delay(600);
- Serial.println(music_1[i]);
- i++;
- continue;
- }
- tone(8, music_1[i], 200);
- delay(300);
- Serial.println(music_1[i]);
- }
- for(int i = 0; i < LENGTH; i++) {
- digitalWrite(13, !digitalRead(13));
- if((i == 14) || (i == 12)) {
- tone(8, music_2[i], 500);
- delay(600);
- Serial.println(music_2[i]);
- i++;
- continue;
- }
- tone(8, music_2[i], 200);
- delay(300);
- Serial.println(music_2[i]);
- }
- for(int i = 0; i < LENGTH + 2; i++) {
- switch(i) {
- case 16:
- digitalWrite(13, !digitalRead(13));
- tone(8, music_3[i], 500);
- delay(600);
- Serial.println(music_3[i]);
- i++;
- continue;
- break;
- case 5:
- case 6:
- case 10:
- case 11:
- digitalWrite(13, !digitalRead(13));
- tone(8, music_3[i], 100);
- delay(150);
- Serial.println(music_3[i]);
- break;
- default:
- digitalWrite(13, !digitalRead(13));
- tone(8, music_3[i], 200);
- delay(300);
- Serial.println(music_3[i]);
- break;
- }
- }
- for(int i = 0; i < LENGTH; i++) {
- digitalWrite(13, !digitalRead(13));
- if((i == 14) || (i == 12)) {
- tone(8, music_2[i], 500);
- delay(600);
- Serial.println(music_2[i]);
- i++;
- continue;
- }
- tone(8, music_2[i], 200);
- delay(300);
- Serial.println(music_2[i]);
- }
- delay(1000);
- Serial.println("Music End");
- Serial.println("");
- Serial.println("");
- delay( 1000 );
- }
- }
复制代码
最后当然是连线图啦
|