Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pitches.h"
- int melody[] = {
- NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
- };
- int noteDurations[] = {
- 4, 8, 8, 4, 4, 4, 4, 4
- };
- void setup() {
- pinMode(D2, OUTPUT);
- for (int thisNote = 0; thisNote < 8; thisNote++) {
- int noteDuration = 1000 / noteDurations[thisNote];
- tone(D2, melody[thisNote], noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- noTone(D2);
- }
- }
- void loop() {
- // no need to repeat the melody.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement