Last active
May 6, 2019 16:55
-
-
Save maximeadjigble/f5c08826352195119fc5d6a084061b77 to your computer and use it in GitHub Desktop.
Play tunes using the Arduino board and a piezzo-electric buzzer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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