아두이노로 학교종이 땡땡땡 연주하기
기본적인 음계의 주파수 대역을 알면 피에조를 이용하여 간단하게 노래를 만들수 있다. ^^;
음계

회로 구성

Source code
#define DO3 7645
#define RE3 6811
#define MI3 6068
#define PA3 5727
#define SOL3 5102
#define RA3 4545
#define SI3 4050
#define DO4 3822
#define RE4 3405
#define MI4 3034
#define PA4 2863
#define SOL4 2551
#define RA4 2273
#define SI4 2025
#define DO5 1910
#define RE5 1703
#define MI5 1517
#define PA5 1432
#define SOL5 1276
#define RA5 1136
#define SI5 1012
void play_music(int SCALE, int duration)
{
for(long i = 0; i<1000000; i=i+SCALE)
{
digitalWrite(7,1);
delayMicroseconds(SCALE/2);
digitalWrite(7,0);
delayMicroseconds(SCALE/2);
}
delay(duration);
}
void school_bell(int tempo)
{
play_music(SOL4, 50*tempo);
play_music(SOL4, 50*tempo);
play_music(RA4, 50*tempo);
play_music(RA4, 50*tempo);
play_music(SOL4, 50*tempo);
play_music(SOL4, 50*tempo);
play_music(MI4, 50*tempo);
play_music(SOL4, 50*tempo);
play_music(SOL4, 50*tempo);
play_music(MI4, 50*tempo);
play_music(MI4, 50*tempo);
play_music(RE4, 100*tempo);
play_music(SOL4, 50*tempo);
play_music(SOL4, 50*tempo);
play_music(RA4, 50*tempo);
play_music(RA4, 50*tempo);
play_music(SOL4, 50*tempo);
play_music(SOL4, 50*tempo);
play_music(MI4, 50*tempo);
play_music(SOL4, 50*tempo);
play_music(MI4, 50*tempo);
play_music(RE4, 50*tempo);
play_music(MI4, 50*tempo);
play_music(DO4, 200*tempo);
delay(10000);
}
void setup()
{
pinMode(7, OUTPUT);
}
void loop(){
school_bell(1);
}
동작
\