아두이노는 스피커에 주파수를 입력하여 소리를 낼 수 있습니다.


http://arduino.cc/en/Reference/Tone 에 들어가면 Tone에 대한 설명이있습니다.



위의 그림처럼 연결해주고 소스에서 톤을 넣어주면 소리가 나게 됩니다.


아래는 소스입니다.


소스 코드 1 


  #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 durations: 4 = quarter note, 8 = eighth note, etc.:

int noteDurations[] = {

  4, 8, 8, 4,4,4,4,4 };


void setup() {

  for (int thisNote = 0; thisNote < 8; thisNote++) {


    int noteDuration = 1000/noteDurations[thisNote];

    tone(8, melody[thisNote],noteDuration);


    int pauseBetweenNotes = noteDuration * 1.30;

    delay(pauseBetweenNotes);

    noTone(8);

  }

}


void loop() {

  // no need to repeat the melody.

}


tone( 'pinNum' , 'toneNote' , 'toneDuration' ); 를 채워주면되는데

Note는 음계 ( 도레미파솔라시도 )

Duration 는 지속시간(ms) 입니다.


아두이노 셈플 소스를 재생해보면 띠리리띠리띠띠! 라는 소리를 들을 수 있습니다.

따로 동영상을 촬영하지않아서 넘어가겠습니다.





이제 피아노! 를 만들어봅시다.


위의 회로를 사용하여 아래그림처럼 꾸몄습니다.


버튼의 용도는 2345 6789 핀을 이용해서

도래미파 솔라시도 이런식으로 넣어주었고 

소리의 경우 출력과 그라운드를 별도의 스피커에 넣어주였습니다.


음표는 같이 동봉된  pitches.h 를 보고 만드시면 됩니다.







+ Recent posts