Configuratia hardware:
-printr-o rezistenta de de 100 ohmi se conecteaza firul rosu(+) al difuzorului la pinul 8 (digital) al placutei arduino;
-firul negru se leaga la masa.
Pentru a genera note muzicale, kitul Arduino necesita utlizarea functiei " tone() " .
Sintaxa functiei tone() este urmatoarea:
tone(pin, frecveta)
tone(pin, frecventa, durata)
tone(pin, frecventa, durata)
Semnificatia parametrilor functiei:
-pin: pinul de iesire care va genera notele muzicale;
-frequency: frecventa notelor in hertzi-este o variabila de tip unsigned int
-duration: durata notei in milisecunde-este o variabila de tip unsigned long
COUDUL SURSA:
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
int melody[] = {
NOTE_F3, NOTE_G3,NOTE_A3, NOTE_A3, NOTE_G3, NOTE_F3, NOTE_G3,NOTE_A3,NOTE_F3,NOTE_C3,
NOTE_F3,NOTE_G3,NOTE_A3,NOTE_A3,NOTE_G3,NOTE_F3,NOTE_G3,NOTE_A3,NOTE_F3};
int noteDurations[] = {
3,8,4,4,8,8,8,8,4,4,3,8,4,4,8,8,8,8,2 };
void setup() {
}
void loop() {
for (int thisNote = 0; thisNote < 19; thisNote++) {
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(8);
}
delay(2000);
}