#include "pitches.h"
const byte xaxis = A3;
const byte speakerPin = 3;
const byte leds[]={2,10,11};
// Melody Notes
const byte melody[] = {
NOTE_E7, NOTE_E7, 0, NOTE_E7,
0, NOTE_C7, NOTE_E7, 0,
NOTE_G7, 0, 0, 0,
NOTE_G6, 0, 0, 0,
NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,
NOTE_G6, NOTE_E7, NOTE_G7,
NOTE_A7, 0, NOTE_F7, NOTE_G7,
0, NOTE_E7, 0,NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0,
NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,
NOTE_G6, NOTE_E7, NOTE_G7,
NOTE_A7, 0, NOTE_F7, NOTE_G7,
0, NOTE_E7, 0,NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0,
NOTE_E7, NOTE_E7, 0, NOTE_E7,
0, NOTE_C7, NOTE_E7, 0,
NOTE_G7, 0, 0, 0,
NOTE_G6, 0, 0, 0,
};
// Each Note Duration
const byte noteDurations[] = {
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12
};
// Play Melody
void play_tone(int note) {
int noteDuration = 1000 / noteDurations[note];
tone(7, melody[note], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(7);
}
// Shut Down Every Leds
void reset_led() {
digitalWrite(leds[0], LOW);
digitalWrite(leds[1], LOW);
digitalWrite(leds[2], LOW);
}
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
Serial.begin(9600);
for (int i = 0; i <= 4; i++) {
pinMode(leds[i], OUTPUT);
}
pinMode(speakerPin, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
int accel = analogRead(xaxis);
Serial.print("Accel X ");
Serial.println(accel);
if(accel > 50)
{
int y = 0;
// For Every Notes...
for (int i = 0; i < 94; i++)
{
// Different of 0
if (melody[i] != 0)
{
// Light up Led
digitalWrite(leds[y], HIGH);
y++;
// Reset Count After Five Pins
if (y > 4)
y = 0;
}
play_tone(i);
reset_led();
}
}
else
{
digitalWrite(speakerPin, LOW);
}
delay(1000);
}
So heres is my code with a file that is referencing the notes I am trying to implement. I tried several different ways although the buzzer will not work. The LED will although. Any ideas? I put the "+" on the buzzer to pin 3 and the "-" to gnd.
pitches.h (1.95 KB)