This file contains hidden or 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
void loop() { | |
if (digitalRead(button)==LOW){ //if button is pressed | |
for (int thisNote = 0; thisNote < looptune; thisNote++) { | |
int noteDuration = 750/4; | |
tone(buzzer, melody[thisNote%72], noteDuration); | |
int pauseBetweenNotes = noteDuration * 1.30; | |
delay(pauseBetweenNotes); | |
noTone(buzzer); | |
} | |
} |
This file contains hidden or 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
void setup() { | |
pinMode(button, INPUT_PULLUP); | |
looptune = looptune * 72; //do not change this | |
} |
This file contains hidden or 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
int melody[] = { | |
NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5, | |
NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_F4, | |
NOTE_G4, 0, NOTE_G4, NOTE_D5, | |
NOTE_C5, 0, NOTE_AS4, 0, | |
NOTE_A4, 0, NOTE_A4, NOTE_A4, | |
NOTE_C5, 0, NOTE_AS4, NOTE_A4, | |
NOTE_G4,0, NOTE_G4, NOTE_AS5, | |
NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5, | |
NOTE_G4,0, NOTE_G4, NOTE_AS5, |
This file contains hidden or 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
#include "pitches.h" | |
int button = 5; //pin to connect to button | |
int buzzer = 8; //pin to connect to buzzer +ve terminal | |
int looptune = 2; // how many times do you want the tune to loop |
This file contains hidden or 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
//To use TX as GPIO: | |
pinMode(1, FUNCTION_3); | |
//To use RX as GPIO: | |
pinMode(3, FUNCTION_3); |