2017-03-08 19 views
0

나는 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); 
} 

답변

0

당신은 동시에 여섯 개 개별 채널에 대한 tone() 함수를 호출하려고합니다. 이것은 arduino 코어 라이브러리의 tone() 함수가 일 때 톤을 생성하도록 지정 되었기 때문에 작동하지 않습니다. 그 이유는 구형파를 생성하기 위해 단일 하드웨어 타이머를 사용하기 때문입니다.

  1. 당신의 디자인 모노 폰을 확인하십시오

    다음은 달성하기 위해 노력하고 무엇을 달성하는 방법에 대한 아이디어가 아닌 완전한 목록입니다. 하나의 핀, 하나의 스피커, 하나의 음성.

  2. micros()을 사용하여 손으로 사각형을 생성하십시오.
  3. Brett Hagman의 톤 라이브러리를 사용하십시오 : https://code.google.com/archive/p/rogue-code/wikis/ToneLibraryDocumentation.wiki#Ugly_Details. 이 라이브러리는 보드의 Atmel 칩에 따라 더 많은 하드웨어 타이머, 실제 번호를 사용합니다. 6 개의 핀을 동시에 구동하려면 ATmega1280 + 칩이있는 Arduino가 필요합니다. 메모 측면

tone()는 인수로 두 int을 기대하고있다.