Skip to content

Instantly share code, notes, and snippets.

@maximeadjigble
Last active May 6, 2019 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximeadjigble/f5c08826352195119fc5d6a084061b77 to your computer and use it in GitHub Desktop.
Save maximeadjigble/f5c08826352195119fc5d6a084061b77 to your computer and use it in GitHub Desktop.
Play tunes using the Arduino board and a piezzo-electric buzzer
#define NUM_NOTES 8
int buzzerPin = 3;
int melody[NUM_NOTES] = {
262, 196, 196, 220, 196, 0, 247, 262
};
int noteDurations[NUM_NOTES] = {
4, 8, 8, 4, 4, 4, 4, 4
};
void setup() {
}
void loop() {
for(int noteId = 0; noteId < NUM_NOTES; noteId++){
int noteDuration = 1000/ noteDurations[noteId];
tone(buzzerPin, melody[noteId], noteDuration);
int pauseBetweenNotes = noteDuration* 1.3;
delay(pauseBetweenNotes);
noTone(buzzerPin);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment