본문 바로가기
아두이노

아두이노 (5) 사운드

by artra 2017. 4. 27.
반응형

 

파일 > 예제 > 02.Digital > toneMelody 에서

 

밑 안에 이걸 복하해서 넣으시면됩니다.

 

#include "pitches.h"
 
// notes in the melody:
 
int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4,
  NOTE_C4, NOTE_G4, NOTE_D3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
// 피아노 건반노트 / 0은 안침
};
 
int noteDurations[] = {
  4884444448844444 // 음표길이
};
 
void setup() {
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 16; thisNote++) {
    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);
    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
  }
}
 
void loop() {
  // no need to repeat the melody.
}
cs

 

 

 주의 

 

 

toneMelody 옆 pitches.h. 탭이 있는데 이안에 내용들은

 

건반 멜로디를 정렬해놓은것이오니 건들지 마시고

 

C = 도 , D = 레, E = 미, F = 파, G = 솔,  A = 라, B = 시

CS = 도#(레b), DS = 레#(미b) FS = 파#(솔b), GS = 솔#(라b), AS = 라#(시b)

입니다.

 

그옆 숫자들은 주파수 값입니다.

 

1,2,3~ 는 건반 위치 입니다.

 

C5 가 실제 피아노 중앙 도 위치인것으로 알고 계시면 됩니다.

 

 

반응형

'아두이노' 카테고리의 다른 글

RGB LED 켜보기  (0) 2017.05.15
아두이노 8x8 도트 매트릭스  (2) 2017.04.30
왜? 아두이노 해야해?  (0) 2017.04.19
아두이노 그림, 그리는 사이트  (0) 2017.04.19
아두이노 led 저항 + - 극 상관없이 연결?  (0) 2017.04.19

댓글