Lab_interaccio/2016/hybridPlay/hybridPlay1.0.0/Speaker.ino

51 lines
1.4 KiB
Arduino
Raw Normal View History

2025-02-25 21:29:42 +01:00
void sensorON_play(){
// iterate over the notes of the melody:
for (int i = 0; i < 3; i++) {
// 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 / sensorON_durations[i];
tone(speaker, sensorON_melody[i], 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(speaker);
}
}
void sensorRESET_play(){
// iterate over the notes of the melody:
for (int i = 0; i < 2; i++) {
// 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 / 32;
tone(speaker, NOTE_C4, 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(speaker);
}
}
void sensorLowBattery_play(){
for (int i = 0; i < 10; i++) {
int noteDuration = 1000 / 32;
tone(speaker,NOTE_C4, noteDuration);
delay(noteDuration * 1.30);
noTone(speaker);
}
}