but then I had to hold down the button for it to play, and it started in the middle of the song. How can I push the button once and make it start playing the song?
Thank you for the link, but that is not your code, that seems to be the code that is working. There is no switch in the code you provided.
Please post your code.
Dermaptera:
Thank you for the link, but that is not your code, that seems to be the code that is working. There is no switch in the code you provided.
Please post your code.
I tried your code, because I could not see anything obviously wrong with it, and it seems to work fine for me. How is your button wired? Are you using a hardware pullup resistor? Is it between the buzzer and the pin? That would explain, why you have to hold it down to play.
And with your code it plays all the songs (several times) once the button is pressed. Is that, what you want?
Dermaptera:
I tried your code, because I could not see anything obviously wrong with it, and it seems to work fine for me. How is your button wired? Are you using a hardware pullup resistor? Is it between the buzzer and the pin? That would explain, why you have to hold it down to play.
And with your code it plays all the songs (several times) once the button is pressed. Is that, what you want?
My button is connected to a resistor that connecting it to the buzzer, and it's connected to pin 2 and pin 3. There is a resistor between the button and the buzzer. The resistor and pin 2 are on the same side of the button. After the buzzer there is a resistor and then the ground if that matters.
Why would you connect it like this?
Connect your button to pin 2 and ground and use INPUT_PULLUP instead of INPUT for pinmode.
And I think it is really hard to understand a circuit if you just describe it. It is much easier if you draw it.
Yes, you are right, it plays the song once. I didn't notice that were parts of one song.
That worked, I see now that I was thinking the wrong way. It makes much more sense to do it like this. I will draw it next time. Thank you so much for the help