#define NOTE_C4 262
#define NOTE_DS4 311
#define NOTE_FS4 370
#define NOTE_D4 294
#define NOTE_CS4 277
#define NOTE_AS3 233
#define BUZZER_PIN 9 //makes buzzer
int yled = 12; //makes yellow led
int bled = 13; //makes blue led
int melody[] = {
//notes of song in order
NOTE_C4, NOTE_C4, NOTE_DS4, NOTE_FS4, 0, //i count money
NOTE_C4, NOTE_C4, NOTE_DS4, NOTE_FS4, 0,//i count money
NOTE_C4, NOTE_C4, NOTE_DS4, NOTE_FS4, 0, //i count money
NOTE_D4, NOTE_D4, NOTE_CS4, NOTE_AS3, NOTE_DS4, NOTE_FS4, //I swerve in a humvee
};
int durations[] = {
//time of each note respectively in milliseconds
16, 16, 9, 5, 16,
16, 16, 9, 5, 16,
16, 16, 9, 5, 16,
16, 16, 16, 16, 8, 4
};
void setup() {
// put your setup code here, to run once:
pinMode(BUZZER_PIN, OUTPUT); //sets the buzzer as an output
pinMode(yled, OUTPUT); //yellow led output
pinMode (bled, OUTPUT); //blue led output
}
void loop() {
// put your main code here, to run repeatedly:
//code for led lights
digitalWrite(yled, HIGH); // turn the yellow on on
digitalWrite(bled, LOW); // turn the blue off
delay(250); // wait for a half second
digitalWrite(yled, LOW); // turn the yelllow off
digitalWrite(bled, HIGH); // turn the blue on
delay(250); // wait for a half second
// code for buzzer
int size = sizeof(durations) / sizeof(int);
for (int note = 0; note < size; note++) {
/*note duration is one second divided by note type
example: quarter note is 1000/4 */
int duration = 1000 / durations[note];
tone(BUZZER_PIN, melody[note], duration);
int pauseBetweenNotes = duration * 1.30;
//to distinguish notes, set minimun time btwn them
//note duration + 30%
delay(pauseBetweenNotes);
noTone(BUZZER_PIN);
//stop the tone playing
}
}