Arduino Grove の 「ブザー・モジュール」のサンプルです。
「ブザー・モジュール」を、「D4」コネクタに取り付けます。
プログラム的には、配列とループのサンプルです。
Arduino IDE 上のプログラム
sketch_buzzer.ino
int port_buzzer = 4;
void setup() {
pinMode(port_buzzer,OUTPUT);
}
void loop() {
int tt = 300;
int freq[] = {262,294,330,349,392,440,494,523};
for(int it=0; it < 8; it++)
{
tone(port_buzzer,freq[it],tt);
delay(tt);
}
delay(500);
for(int it=7; 0<= it; it--)
{
tone(port_buzzer,freq[it],tt);
delay(tt);
}
delay(2000);
}