나는 6 명의 스피커가 연결된 Arduino로 연주 한 작은 노래를 프로그램하려고합니다. 이 과정은 주파수에서 다른 스피커를 켜고 음표의 지속 시간을 카운트 다운해야합니다. 지속 시간이 끝나면 나는 다음 소리를 듣거나 스피커를 켜십시오. 나는 6 명의 연설자를 위해 다른 배열을 정의했다. 또한 노트 주파수와 지속 시간에 대한 정의가 많습니다.Arduino로 음악 연주하기
문제는, 나는 단지 깊은 윙윙 거리는 소리를 듣지 만 조정은하지 않는다는 것입니다.
누구나 코드에 대해 잘못된 점이있을 수 있습니다.
#define pause 0
#define c1 32.7
#define cis1 34.6
#define d1 36.7
#define dis1 38.9
...
#define l1 32
#define l2 16
...
#define note 0
#define laenge 1
int myChannels[] = { 8, 9, 10, 11, 12, 13 };
int myDuration[] = { 0, 0, 0, 0, 0, 0 };
int myPointer[] = { 0, 0, 0, 0, 0, 0 };
const PROGMEM float myPlayList[6][600][2] = {
// 1st Voice
{
{ c2, l8}, { g2, l8}, { c2, l8}, { g2, l8}, { c2, l8}, { g2, l8}, { c2, l8}, { g2, l8},
{ c2, l8}, { g2, l8}, { c2, l8}, { g2, l8}, { c2, l8}, { g2, l8}, { c2, l8}, { g2, 18},
...
}
};
void play(int out, float freq, float len) {
if (freq > 0) {
tone (myChannels[out], freq);
} else {
noTone (freq);
}
myDuration[ out] = len;
}
void setup() {
for (int channel = 0; channel < 6; channel++) {
pinMode (myChannels[channel], OUTPUT);
}
}
void loop() {
boolean playing = false;
for (int channel = 0; channel < 6; channel++) {
if (myDuration[channel] == 0) {
if (myPointer[channel] < sizeof(myPlayList[channel])) {
play(channel, myPlayList[channel][myPointer[channel]][0], myPlayList[channel][myPointer[channel]][1]);
myPointer[channel]++;
playing = true;
} else {
noTone (channel);
}
} else {
myDuration[channel]--;
playing = true;
}
}
if (!playing) {
delay (10000);
for (int channel = 0; channel < 6; channel++) {
myDuration[channel] = 0;
myPointer[channel] = 0;
}
}
delay (25);
}