I’m new to this forum, and I’m not sure if this was the correct spot to put this topic, but I’m making an Arduino program for a project in a Media and Technology class, and my program isn’t working, and I’m not sure what’s wrong. I’m trying to set up a program that plays a melody when I press a button, but I’ve uploaded the program and nothing’s happening. There are also some things that I’ve made into comments, as I’m just trying to figure out how to get the first melody to play, and I’m not setting up a second one at the moment.
I’m going to paste my current program down below, and I’d be grateful if someone could let me know where I went wrong.
#include “pitches.h”
int const buzzer1 = 2;
//int const buzzer2 = 3;
int const button = 4;
//int const touchsensor = 5;
int buttonValue;
//int touchValue;
int melody = {
NOTE_F5, NOTE_C6, NOTE_B6, NOTE_C6, NOTE_B6, NOTE_C6, NOTE_GS6, NOTE_F5
};
int noteDurations = {
2, 4, 8, 8, 8, 8, 4, 4
};
void setup() {
// put your setup code here, to run once:
pinMode(buzzer1, OUTPUT);
//pinMode(buzzer2, OUTPUT);
pinMode(button, INPUT);
//pinMode(touchsensor, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
buttonValue = digitalRead(button);
//touchValue = digitalRead(touchsensor);
if (buttonValue == 1) {
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
noTone(8 );
}
}
else {
digitalWrite(buzzer1, LOW);
}
}
Note: In the noTone part, I had to put a space between the 8 and the ) because it turned into an emoji.
Edit: I have no idea how to use this website, can a moderator delete this topic?